caldav: some minor refactoring

This commit is contained in:
Lennart
2024-09-29 14:40:28 +02:00
parent ac10ed096a
commit e9e16a71f0
4 changed files with 9 additions and 5 deletions

1
Cargo.lock generated
View File

@@ -2010,6 +2010,7 @@ dependencies = [
"actix-web", "actix-web",
"anyhow", "anyhow",
"async-trait", "async-trait",
"derive_more 1.0.0",
"futures-util", "futures-util",
"itertools", "itertools",
"log", "log",

View File

@@ -40,6 +40,7 @@ pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?S
cal_store: Data<RwLock<C>>, cal_store: Data<RwLock<C>>,
prefix: Data<ServicePrefix>, prefix: Data<ServicePrefix>,
) -> Result<impl Responder, Error> { ) -> Result<impl Responder, Error> {
let prefix = prefix.into_inner();
let (principal, cid) = path.into_inner(); let (principal, cid) = path.into_inner();
if principal != auth.inner.user_id { if principal != auth.inner.user_id {
return Err(Error::Unauthorized); return Err(Error::Unauthorized);
@@ -51,10 +52,10 @@ pub async fn route_report_calendar<A: CheckAuthentication, C: CalendarStore + ?S
Ok(match request.clone() { Ok(match request.clone() {
ReportRequest::CalendarQuery(cal_query) => { ReportRequest::CalendarQuery(cal_query) => {
handle_calendar_query(cal_query, req, &prefix.0, &principal, &cid, &cal_store).await? handle_calendar_query(cal_query, req, &prefix, &principal, &cid, &cal_store).await?
} }
ReportRequest::CalendarMultiget(cal_multiget) => { ReportRequest::CalendarMultiget(cal_multiget) => {
handle_calendar_multiget(cal_multiget, req, &prefix.0, &principal, &cid, &cal_store) handle_calendar_multiget(cal_multiget, req, &prefix, &principal, &cid, &cal_store)
.await? .await?
} }
ReportRequest::SyncCollection(sync_collection) => { ReportRequest::SyncCollection(sync_collection) => {

View File

@@ -20,3 +20,4 @@ itertools = "0.13"
thiserror = "1.0" thiserror = "1.0"
roxmltree = "0.20" roxmltree = "0.20"
log = "0.4" log = "0.4"
derive_more = { version = "1.0.0", features = ["deref"] }

View File

@@ -8,11 +8,13 @@ use crate::xml::TagList;
use crate::Error; use crate::Error;
use actix_web::web::{Data, Path}; use actix_web::web::{Data, Path};
use actix_web::HttpRequest; use actix_web::HttpRequest;
use derive_more::derive::Deref;
use log::debug; use log::debug;
use rustical_auth::{AuthInfoExtractor, CheckAuthentication}; use rustical_auth::{AuthInfoExtractor, CheckAuthentication};
use serde::Deserialize; use serde::Deserialize;
// This is not the final place for this struct // This is not the final place for this struct
#[derive(Deref)]
pub struct ServicePrefix(pub String); pub struct ServicePrefix(pub String);
#[derive(Deserialize, Clone, Debug)] #[derive(Deserialize, Clone, Debug)]
@@ -53,11 +55,10 @@ pub async fn route_propfind<A: CheckAuthentication, R: ResourceService>(
> { > {
debug!("{body}"); debug!("{body}");
let auth_info = auth.inner; let auth_info = auth.inner;
let prefix = prefix.0.to_owned(); let prefix = prefix.into_inner();
let path_components = path_components.into_inner();
let path = req.path().to_owned(); let path = req.path().to_owned();
let resource_service = R::new(&req, &auth_info, path_components.clone()).await?; let resource_service = R::new(&req, &auth_info, path_components.into_inner()).await?;
// A request body is optional. If empty we MUST return all props // A request body is optional. If empty we MUST return all props
let propfind: PropfindElement = if !body.is_empty() { let propfind: PropfindElement = if !body.is_empty() {