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 {

View File

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