mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
caldav: Refactor DELETE
This commit is contained in:
22
crates/caldav/src/calendar/methods/delete.rs
Normal file
22
crates/caldav/src/calendar/methods/delete.rs
Normal 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(""))
|
||||
}
|
||||
@@ -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(""))
|
||||
}
|
||||
|
||||
@@ -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}")
|
||||
|
||||
Reference in New Issue
Block a user