Add trash bin feature

This commit is contained in:
Lennart
2024-06-21 19:26:45 +02:00
parent c1cc12e2ac
commit aed6bcff63
9 changed files with 45 additions and 9 deletions

View File

@@ -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(""))
}

View File

@@ -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 {