caldav: Refactor DELETE

This commit is contained in:
Lennart
2024-05-28 12:50:56 +02:00
parent 7f979ddd93
commit 5d8b67472a
3 changed files with 27 additions and 14 deletions

View File

@@ -0,0 +1,22 @@
use crate::CalDavContext;
use crate::Error;
use actix_web::{
web::{Data, Path},
HttpResponse,
};
use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
use rustical_store::calendar::CalendarStore;
pub async fn route_delete_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>,
path: Path<(String, String)>,
auth: AuthInfoExtractor<A>,
) -> 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?;
Ok(HttpResponse::Ok().body(""))
}