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

@@ -1,16 +1,14 @@
use std::sync::Arc;
use crate::Error;
use crate::calendar_set::CalendarSetResource;
use actix_web::dev::ResourceMap;
use crate::{CalDavPrincipalUri, Error};
use async_trait::async_trait;
use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{NamedRoute, Resource, ResourceService};
use rustical_dav::resource::{PrincipalUri, Resource, ResourceService};
use rustical_dav::xml::{HrefElement, Resourcetype, ResourcetypeInner};
use rustical_store::auth::user::PrincipalType;
use rustical_store::auth::{AuthenticationProvider, User};
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
use std::sync::Arc;
#[derive(Clone)]
pub struct PrincipalResource {
@@ -49,22 +47,6 @@ pub enum PrincipalPropWrapper {
Common(CommonPropertiesProp),
}
impl PrincipalResource {
pub fn get_principal_url(rmap: &ResourceMap, principal: &str) -> String {
Self::get_url(rmap, vec![principal]).unwrap()
}
}
impl NamedRoute for PrincipalResource {
fn route_name() -> &'static str {
"caldav_principal"
}
}
impl CommonPropertiesExtension for PrincipalResource {
type PrincipalResource = Self;
}
impl Resource for PrincipalResource {
type Prop = PrincipalPropWrapper;
type Error = Error;
@@ -79,16 +61,16 @@ impl Resource for PrincipalResource {
fn get_prop(
&self,
rmap: &ResourceMap,
puri: &impl PrincipalUri,
user: &User,
prop: &PrincipalPropWrapperName,
) -> Result<Self::Prop, Self::Error> {
let principal_url = Self::get_url(rmap, vec![&self.principal.id]).unwrap();
let principal_url = puri.principal_uri(&self.principal.id);
let home_set = CalendarHomeSet(
user.memberships()
.into_iter()
.map(|principal| Self::get_url(rmap, vec![principal]).unwrap())
.map(|principal| puri.principal_uri(principal))
.flat_map(|principal_url| {
self.home_set.iter().map(move |&(home_name, _read_only)| {
HrefElement::new(format!("{}/{}", &principal_url, home_name))
@@ -119,7 +101,7 @@ impl Resource for PrincipalResource {
})
}
PrincipalPropWrapperName::Common(prop) => PrincipalPropWrapper::Common(
<Self as CommonPropertiesExtension>::get_prop(self, rmap, user, prop)?,
<Self as CommonPropertiesExtension>::get_prop(self, puri, user, prop)?,
),
})
}
@@ -147,6 +129,7 @@ impl<AP: AuthenticationProvider> ResourceService for PrincipalResourceService<AP
type Resource = PrincipalResource;
type Error = Error;
type Principal = User;
type PrincipalUri = CalDavPrincipalUri;
async fn get_resource(
&self,