mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
Add trash bin feature
This commit is contained in:
1
Cargo.lock
generated
1
Cargo.lock
generated
@@ -509,6 +509,7 @@ dependencies = [
|
||||
"iana-time-zone",
|
||||
"js-sys",
|
||||
"num-traits",
|
||||
"serde",
|
||||
"wasm-bindgen",
|
||||
"windows-targets 0.52.5",
|
||||
]
|
||||
|
||||
@@ -15,10 +15,11 @@ a calendar server
|
||||
- [ ] CardDAV
|
||||
- [ ] Locking
|
||||
- [ ] Web UI
|
||||
- [ ] Hiding calendars instead of deleting them
|
||||
- [ ] Testing such that I'm confident enough to use it myself :)
|
||||
- [ ] WebDAV sync extension [RFC 6578](https://www.rfc-editor.org/rfc/rfc6578)
|
||||
- [ ] implement getctag [see](https://github.com/apple/ccs-calendarserver/blob/master/doc/Extensions/caldav-ctag.txt)
|
||||
- [ ] Ensure proper routing
|
||||
- [ ] Trash bin
|
||||
- [x] Trash bin
|
||||
- [x] Hiding calendars instead of deleting them
|
||||
- [ ] Restore endpoint
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::CalDavContext;
|
||||
use crate::Error;
|
||||
use actix_web::HttpRequest;
|
||||
use actix_web::{
|
||||
web::{Data, Path},
|
||||
HttpResponse,
|
||||
@@ -11,12 +12,25 @@ pub async fn route_delete_calendar<A: CheckAuthentication, C: CalendarStore + ?S
|
||||
context: Data<CalDavContext<C>>,
|
||||
path: Path<(String, String)>,
|
||||
auth: AuthInfoExtractor<A>,
|
||||
req: HttpRequest,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, cid) = path.into_inner();
|
||||
if principal != auth.inner.user_id {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
context.store.write().await.delete_calendar(&cid).await?;
|
||||
|
||||
let no_trash = req
|
||||
.headers()
|
||||
.get("X-No-Trashbin")
|
||||
.map(|val| matches!(val.to_str(), Ok("1")))
|
||||
.unwrap_or(false);
|
||||
|
||||
context
|
||||
.store
|
||||
.write()
|
||||
.await
|
||||
.delete_calendar(&cid, !no_trash)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().body(""))
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ pub async fn route_mkcol_calendar<A: CheckAuthentication, C: CalendarStore + ?Si
|
||||
timezone: request.calendar_timezone,
|
||||
color: request.calendar_color,
|
||||
description: request.calendar_description,
|
||||
deleted: false,
|
||||
deleted_at: None,
|
||||
};
|
||||
|
||||
match context.store.read().await.get_calendar(&cid).await {
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
use crate::CalDavContext;
|
||||
use crate::Error;
|
||||
use actix_web::web::{Data, Path};
|
||||
use actix_web::HttpRequest;
|
||||
use actix_web::HttpResponse;
|
||||
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
|
||||
use rustical_store::CalendarStore;
|
||||
@@ -9,6 +10,7 @@ pub async fn delete_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
||||
context: Data<CalDavContext<C>>,
|
||||
path: Path<(String, String, String)>,
|
||||
auth: AuthInfoExtractor<A>,
|
||||
req: HttpRequest,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let _user = auth.inner.user_id;
|
||||
// TODO: verify whether user is authorized
|
||||
@@ -16,7 +18,18 @@ pub async fn delete_event<A: CheckAuthentication, C: CalendarStore + ?Sized>(
|
||||
if cid.ends_with(".ics") {
|
||||
cid.truncate(cid.len() - 4);
|
||||
}
|
||||
context.store.write().await.delete_event(&cid, &uid).await?;
|
||||
let no_trash = req
|
||||
.headers()
|
||||
.get("X-No-Trashbin")
|
||||
.map(|val| matches!(val.to_str(), Ok("1")))
|
||||
.unwrap_or(false);
|
||||
|
||||
context
|
||||
.store
|
||||
.write()
|
||||
.await
|
||||
.delete_event(&cid, &uid, !no_trash)
|
||||
.await?;
|
||||
|
||||
Ok(HttpResponse::Ok().body(""))
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ sqlx = { version = "0.7", features = [
|
||||
tokio = { version = "1.35", features = ["sync", "full"] }
|
||||
toml = "0.8"
|
||||
ical = { version = "0.11", features = ["generator", "serde"] }
|
||||
chrono = "0.4"
|
||||
chrono = { version = "0.4", features = ["serde"] }
|
||||
regex = "1.10"
|
||||
lazy_static = "1.4"
|
||||
rstest = "0.21"
|
||||
|
||||
@@ -5,13 +5,15 @@ CREATE TABLE calendars (
|
||||
description TEXT,
|
||||
'order' INT DEFAULT 0 NOT NULL,
|
||||
color TEXT,
|
||||
timezone TEXT NOT NULL
|
||||
timezone TEXT NOT NULL,
|
||||
deleted_at DATETIME
|
||||
);
|
||||
|
||||
CREATE TABLE events (
|
||||
uid TEXT NOT NULL,
|
||||
cid TEXT NOT NULL,
|
||||
ics TEXT NOT NULL,
|
||||
deleted_at DATETIME,
|
||||
PRIMARY KEY (cid, uid),
|
||||
FOREIGN KEY (cid) REFERENCES calendars(id)
|
||||
);
|
||||
@@ -1,3 +1,4 @@
|
||||
use chrono::NaiveDateTime;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Debug, Default, Clone, Deserialize, Serialize)]
|
||||
@@ -9,4 +10,5 @@ pub struct Calendar {
|
||||
pub description: Option<String>,
|
||||
pub color: Option<String>,
|
||||
pub timezone: Option<String>,
|
||||
pub deleted_at: Option<NaiveDateTime>,
|
||||
}
|
||||
|
||||
@@ -10,10 +10,13 @@ pub trait CalendarStore: Send + Sync + 'static {
|
||||
async fn get_calendars(&self, owner: &str) -> Result<Vec<Calendar>, Error>;
|
||||
async fn update_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn insert_calendar(&mut self, cid: String, calendar: Calendar) -> Result<(), Error>;
|
||||
async fn delete_calendar(&mut self, cid: &str) -> Result<(), Error>;
|
||||
async fn delete_calendar(&mut self, cid: &str, use_trashbin: bool) -> Result<(), Error>;
|
||||
async fn restore_calendar(&mut self, cid: &str) -> Result<(), Error>;
|
||||
|
||||
async fn get_events(&self, cid: &str) -> Result<Vec<Event>, Error>;
|
||||
async fn get_event(&self, cid: &str, uid: &str) -> Result<Event, Error>;
|
||||
async fn put_event(&mut self, cid: String, uid: String, ics: String) -> Result<(), Error>;
|
||||
async fn delete_event(&mut self, cid: &str, uid: &str) -> Result<(), Error>;
|
||||
async fn delete_event(&mut self, cid: &str, uid: &str, use_trashbin: bool)
|
||||
-> Result<(), Error>;
|
||||
async fn restore_event(&mut self, cid: &str, uid: &str) -> Result<(), Error>;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user