Refactoring around routing and getting the principal uri (less dependence on actix)

This commit is contained in:
Lennart K
2025-06-02 16:17:13 +02:00
parent 0f294cf2e1
commit ef33868151
23 changed files with 169 additions and 216 deletions

View File

@@ -4,12 +4,11 @@ use crate::{
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
};
use actix_web::{
HttpRequest,
dev::{Path, ResourceDef},
http::StatusCode,
};
use rustical_dav::{
resource::Resource,
resource::{PrincipalUri, Resource},
xml::{MultistatusElement, PropfindType, multistatus::ResponseElement},
};
use rustical_store::{CalendarObject, CalendarStore, auth::User};
@@ -58,25 +57,25 @@ pub async fn get_objects_calendar_multiget<C: CalendarStore>(
pub async fn handle_calendar_multiget<C: CalendarStore>(
cal_multiget: &CalendarMultigetRequest,
props: &[&str],
req: HttpRequest,
path: &str,
puri: &impl PrincipalUri,
user: &User,
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
let (objects, not_found) =
get_objects_calendar_multiget(cal_multiget, req.path(), principal, cal_id, cal_store)
.await?;
get_objects_calendar_multiget(cal_multiget, path, principal, cal_id, cal_store).await?;
let mut responses = Vec::new();
for object in objects {
let path = format!("{}/{}.ics", req.path(), object.get_id());
let path = format!("{}/{}.ics", path, object.get_id());
responses.push(
CalendarObjectResource {
object,
principal: principal.to_owned(),
}
.propfind(&path, props, user, req.resource_map())?,
.propfind(&path, props, puri, user)?,
);
}

View File

@@ -1,6 +1,5 @@
use actix_web::HttpRequest;
use rustical_dav::{
resource::Resource,
resource::{PrincipalUri, Resource},
xml::{MultistatusElement, PropfindType},
};
use rustical_ical::UtcDateTime;
@@ -217,7 +216,8 @@ pub async fn get_objects_calendar_query<C: CalendarStore>(
pub async fn handle_calendar_query<C: CalendarStore>(
cal_query: &CalendarQueryRequest,
props: &[&str],
req: HttpRequest,
path: &str,
puri: &impl PrincipalUri,
user: &User,
principal: &str,
cal_id: &str,
@@ -227,17 +227,13 @@ pub async fn handle_calendar_query<C: CalendarStore>(
let mut responses = Vec::new();
for object in objects {
let path = format!(
"{}/{}.ics",
req.path().trim_end_matches('/'),
object.get_id()
);
let path = format!("{}/{}.ics", path, object.get_id());
responses.push(
CalendarObjectResource {
object,
principal: principal.to_owned(),
}
.propfind(&path, props, user, req.resource_map())?,
.propfind(&path, props, puri, user)?,
);
}

View File

@@ -1,4 +1,4 @@
use crate::Error;
use crate::{CalDavPrincipalUri, Error};
use actix_web::{
HttpRequest, Responder,
web::{Data, Path},
@@ -87,6 +87,7 @@ pub async fn route_report_calendar<C: CalendarStore>(
body: String,
user: User,
req: HttpRequest,
puri: Data<CalDavPrincipalUri>,
cal_store: Data<C>,
) -> Result<impl Responder, Error> {
let (principal, cal_id) = path.into_inner();
@@ -102,7 +103,8 @@ pub async fn route_report_calendar<C: CalendarStore>(
handle_calendar_query(
cal_query,
&props,
req,
req.path(),
puri.as_ref(),
&user,
&principal,
&cal_id,
@@ -114,7 +116,8 @@ pub async fn route_report_calendar<C: CalendarStore>(
handle_calendar_multiget(
cal_multiget,
&props,
req,
req.path(),
puri.as_ref(),
&user,
&principal,
&cal_id,
@@ -126,7 +129,8 @@ pub async fn route_report_calendar<C: CalendarStore>(
handle_sync_collection(
sync_collection,
&props,
req,
req.path(),
puri.as_ref(),
&user,
&principal,
&cal_id,

View File

@@ -3,9 +3,9 @@ use crate::{
Error,
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
};
use actix_web::{HttpRequest, http::StatusCode};
use actix_web::http::StatusCode;
use rustical_dav::{
resource::Resource,
resource::{PrincipalUri, Resource},
xml::{
MultistatusElement, multistatus::ResponseElement, sync_collection::SyncCollectionRequest,
},
@@ -19,7 +19,8 @@ use rustical_store::{
pub async fn handle_sync_collection<C: CalendarStore>(
sync_collection: &SyncCollectionRequest<ReportPropName>,
props: &[&str],
req: HttpRequest,
path: &str,
puri: &impl PrincipalUri,
user: &User,
principal: &str,
cal_id: &str,
@@ -32,22 +33,18 @@ pub async fn handle_sync_collection<C: CalendarStore>(
let mut responses = Vec::new();
for object in new_objects {
let path = format!(
"{}/{}.ics",
req.path().trim_end_matches('/'),
object.get_id()
);
let path = format!("{}/{}.ics", path, object.get_id());
responses.push(
CalendarObjectResource {
object,
principal: principal.to_owned(),
}
.propfind(&path, props, user, req.resource_map())?,
.propfind(&path, props, puri, user)?,
);
}
for object_id in deleted_objects {
let path = format!("{}/{}.ics", req.path().trim_end_matches('/'), object_id);
let path = format!("{path}/{object_id}.ics");
responses.push(ResponseElement {
href: path,
status: Some(StatusCode::NOT_FOUND),