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

View File

@@ -14,6 +14,7 @@ use rustical_dav::xml_snippets::generate_multistatus;
use rustical_store::calendar::CalendarStore;
use rustical_store::event::Event;
pub mod delete;
pub mod mkcalendar;
async fn handle_report_calendar_query(
@@ -88,16 +89,3 @@ pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?S
};
handle_report_calendar_query(query_node, events, prefix).await
}
pub async fn delete_calendar<A: CheckAuthentication, C: CalendarStore + ?Sized>(
context: Data<CalDavContext<C>>,
path: Path<(String, String)>,
auth: AuthInfoExtractor<A>,
) -> Result<HttpResponse, Error> {
let _user = auth.inner.user_id;
// TODO: verify whether user is authorized
let (_principal, cid) = path.into_inner();
context.store.write().await.delete_calendar(&cid).await?;
Ok(HttpResponse::Ok().body(""))
}

View File

@@ -60,7 +60,10 @@ pub fn configure_dav<A: CheckAuthentication, C: CalendarStore + ?Sized>(
.route(
mkcalendar_method().to(calendar::methods::mkcalendar::route_mkcol_calendar::<A, C>),
)
.route(web::method(Method::DELETE).to(calendar::methods::delete_calendar::<A, C>)),
.route(
web::method(Method::DELETE)
.to(calendar::methods::delete::route_delete_calendar::<A, C>),
),
)
.service(
web::resource("/{principal}/{calendar}/{event}")