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

@@ -3,12 +3,11 @@ use crate::{
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
};
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::{AddressObject, AddressbookStore, auth::User};
@@ -60,25 +59,26 @@ pub async fn get_objects_addressbook_multiget<AS: AddressbookStore>(
pub async fn handle_addressbook_multiget<AS: AddressbookStore>(
addr_multiget: &AddressbookMultigetRequest,
props: &[&str],
req: HttpRequest,
path: &str,
puri: &impl PrincipalUri,
user: &User,
principal: &str,
cal_id: &str,
addr_store: &AS,
) -> Result<MultistatusElement<AddressObjectPropWrapper, String>, Error> {
let (objects, not_found) =
get_objects_addressbook_multiget(addr_multiget, req.path(), principal, cal_id, addr_store)
get_objects_addressbook_multiget(addr_multiget, path, principal, cal_id, addr_store)
.await?;
let mut responses = Vec::new();
for object in objects {
let path = format!("{}/{}.vcf", req.path(), object.get_id());
let path = format!("{}/{}.vcf", path, object.get_id());
responses.push(
AddressObjectResource {
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::{CardDavPrincipalUri, Error};
use actix_web::{
HttpRequest, Responder,
web::{Data, Path},
@@ -49,6 +49,7 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
body: String,
user: User,
req: HttpRequest,
puri: Data<CardDavPrincipalUri>,
addr_store: Data<AS>,
) -> Result<impl Responder, Error> {
let (principal, addressbook_id) = path.into_inner();
@@ -64,7 +65,8 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
handle_addressbook_multiget(
addr_multiget,
&props,
req,
req.path(),
puri.as_ref(),
&user,
&principal,
&addressbook_id,
@@ -76,7 +78,8 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
handle_sync_collection(
sync_collection,
&props,
req,
req.path(),
puri.as_ref(),
&user,
&principal,
&addressbook_id,

View File

@@ -2,9 +2,9 @@ use crate::{
Error,
address_object::resource::{AddressObjectPropWrapper, AddressObjectResource},
};
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,
},
@@ -18,7 +18,8 @@ use rustical_store::{
pub async fn handle_sync_collection<AS: AddressbookStore>(
sync_collection: &SyncCollectionRequest,
props: &[&str],
req: HttpRequest,
path: &str,
puri: &impl PrincipalUri,
user: &User,
principal: &str,
addressbook_id: &str,
@@ -31,22 +32,18 @@ pub async fn handle_sync_collection<AS: AddressbookStore>(
let mut responses = Vec::new();
for object in new_objects {
let path = format!(
"{}/{}.vcf",
req.path().trim_end_matches('/'),
object.get_id()
);
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object.get_id());
responses.push(
AddressObjectResource {
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!("{}/{}.vcf", req.path().trim_end_matches('/'), object_id);
let path = format!("{}/{}.vcf", path.trim_end_matches('/'), object_id);
responses.push(ResponseElement {
href: path,
status: Some(StatusCode::NOT_FOUND),