Replace this internal_props stuff with CommonPropertiesExtension

This commit is contained in:
Lennart
2025-01-18 22:59:02 +01:00
parent 1dda9dea8d
commit eb1a8578d7
19 changed files with 263 additions and 233 deletions

View File

@@ -1,5 +1,5 @@
use crate::{
calendar_object::resource::{CalendarObjectProp, CalendarObjectResource},
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
Error,
};
use actix_web::{
@@ -8,7 +8,7 @@ use actix_web::{
HttpRequest,
};
use rustical_dav::{
resource::{CommonPropertiesProp, EitherProp, Resource},
resource::Resource,
xml::{multistatus::ResponseElement, MultistatusElement, PropElement, PropfindType},
};
use rustical_store::{auth::User, CalendarObject, CalendarStore};
@@ -60,8 +60,7 @@ pub async fn handle_calendar_multiget<C: CalendarStore>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<EitherProp<CalendarObjectProp, CommonPropertiesProp>, String>, Error>
{
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
let (objects, not_found) =
get_objects_calendar_multiget(&cal_multiget, req.path(), principal, cal_id, cal_store)
.await?;

View File

@@ -2,14 +2,14 @@ use std::ops::Deref;
use actix_web::HttpRequest;
use rustical_dav::{
resource::{CommonPropertiesProp, EitherProp, Resource},
resource::Resource,
xml::{MultistatusElement, PropElement, PropfindType},
};
use rustical_store::{auth::User, calendar::UtcDateTime, CalendarObject, CalendarStore};
use rustical_xml::XmlDeserialize;
use crate::{
calendar_object::resource::{CalendarObjectProp, CalendarObjectResource},
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
Error,
};
@@ -185,8 +185,7 @@ pub async fn handle_calendar_query<C: CalendarStore>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<EitherProp<CalendarObjectProp, CommonPropertiesProp>, String>, Error>
{
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
let objects = get_objects_calendar_query(&cal_query, principal, cal_id, cal_store).await?;
let props = match cal_query.prop {

View File

@@ -1,6 +1,6 @@
use actix_web::{http::StatusCode, HttpRequest};
use rustical_dav::{
resource::{CommonPropertiesProp, EitherProp, Resource},
resource::Resource,
xml::{
multistatus::ResponseElement, sync_collection::SyncCollectionRequest, MultistatusElement,
PropElement, PropfindType,
@@ -13,7 +13,7 @@ use rustical_store::{
};
use crate::{
calendar_object::resource::{CalendarObjectProp, CalendarObjectResource},
calendar_object::resource::{CalendarObjectPropWrapper, CalendarObjectResource},
Error,
};
@@ -24,8 +24,7 @@ pub async fn handle_sync_collection<C: CalendarStore>(
principal: &str,
cal_id: &str,
cal_store: &C,
) -> Result<MultistatusElement<EitherProp<CalendarObjectProp, CommonPropertiesProp>, String>, Error>
{
) -> Result<MultistatusElement<CalendarObjectPropWrapper, String>, Error> {
let props = match sync_collection.prop {
PropfindType::Allprop => {
vec!["allprop".to_owned()]

View File

@@ -11,7 +11,8 @@ use actix_web::web;
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::extensions::{
DavPushExtension, DavPushExtensionProp, SyncTokenExtension, SyncTokenExtensionProp,
CommonPropertiesExtension, CommonPropertiesProp, DavPushExtension, DavPushExtensionProp,
SyncTokenExtension, SyncTokenExtensionProp,
};
use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{Resource, ResourceService};
@@ -66,6 +67,7 @@ pub enum CalendarPropWrapper {
Calendar(CalendarProp),
SyncToken(SyncTokenExtensionProp),
DavPush(DavPushExtensionProp),
Common(CommonPropertiesProp),
}
#[derive(Clone, Debug, From, Into)]
@@ -117,8 +119,8 @@ impl Resource for CalendarResource {
fn get_prop(
&self,
_rmap: &ResourceMap,
_user: &User,
rmap: &ResourceMap,
user: &User,
prop: &Self::PropName,
) -> Result<Self::Prop, Self::Error> {
Ok(match prop {
@@ -160,18 +162,19 @@ impl Resource for CalendarResource {
CalendarPropName::SupportedReportSet => {
CalendarProp::SupportedReportSet(SupportedReportSet::default())
}
// CalendarPropName::SyncToken => CalendarProp::SyncToken(self.get_synctoken()),
// CalendarPropName::Getctag => CalendarProp::Getctag(self.get_synctoken()),
CalendarPropName::Source => CalendarProp::Source(
self.cal.subscription_url.to_owned().map(HrefElement::from),
),
}),
CalendarPropWrapperName::SyncToken(prop) => {
CalendarPropWrapper::SyncToken(<Self as SyncTokenExtension>::get_prop(self, prop)?)
CalendarPropWrapper::SyncToken(SyncTokenExtension::get_prop(self, prop)?)
}
CalendarPropWrapperName::DavPush(prop) => {
CalendarPropWrapper::DavPush(<Self as DavPushExtension>::get_prop(self, prop)?)
CalendarPropWrapper::DavPush(DavPushExtension::get_prop(self, prop)?)
}
CalendarPropWrapperName::Common(prop) => CalendarPropWrapper::Common(
CommonPropertiesExtension::get_prop(self, rmap, user, prop)?,
),
})
}
@@ -227,10 +230,9 @@ impl Resource for CalendarResource {
// Converting between a calendar subscription calendar and a normal one would be weird
CalendarProp::Source(_) => Err(rustical_dav::Error::PropReadOnly),
},
CalendarPropWrapper::SyncToken(prop) => {
<Self as SyncTokenExtension>::set_prop(self, prop)
}
CalendarPropWrapper::DavPush(prop) => <Self as DavPushExtension>::set_prop(self, prop),
CalendarPropWrapper::SyncToken(prop) => SyncTokenExtension::set_prop(self, prop),
CalendarPropWrapper::DavPush(prop) => DavPushExtension::set_prop(self, prop),
CalendarPropWrapper::Common(prop) => CommonPropertiesExtension::set_prop(self, prop),
}
}
@@ -275,11 +277,10 @@ impl Resource for CalendarResource {
// Converting a calendar subscription calendar into a normal one would be weird
CalendarPropName::Source => Err(rustical_dav::Error::PropReadOnly),
},
CalendarPropWrapperName::SyncToken(prop) => {
<Self as SyncTokenExtension>::remove_prop(self, prop)
}
CalendarPropWrapperName::DavPush(prop) => {
<Self as DavPushExtension>::remove_prop(self, prop)
CalendarPropWrapperName::SyncToken(prop) => SyncTokenExtension::remove_prop(self, prop),
CalendarPropWrapperName::DavPush(prop) => DavPushExtension::remove_prop(self, prop),
CalendarPropWrapperName::Common(prop) => {
CommonPropertiesExtension::remove_prop(self, prop)
}
}
}

View File

@@ -4,6 +4,7 @@ use actix_web::dev::ResourceMap;
use async_trait::async_trait;
use derive_more::derive::{From, Into};
use rustical_dav::{
extensions::{CommonPropertiesExtension, CommonPropertiesProp},
privileges::UserPrivilegeSet,
resource::{Resource, ResourceService},
xml::Resourcetype,
@@ -37,6 +38,13 @@ pub enum CalendarObjectProp {
CalendarData(String),
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
#[xml(unit_variants_ident = "CalendarObjectPropWrapperName", untagged)]
pub enum CalendarObjectPropWrapper {
CalendarObject(CalendarObjectProp),
Common(CommonPropertiesProp),
}
#[derive(Clone, From, Into)]
pub struct CalendarObjectResource {
pub object: CalendarObject,
@@ -44,8 +52,8 @@ pub struct CalendarObjectResource {
}
impl Resource for CalendarObjectResource {
type PropName = CalendarObjectPropName;
type Prop = CalendarObjectProp;
type PropName = CalendarObjectPropWrapperName;
type Prop = CalendarObjectPropWrapper;
type Error = Error;
type PrincipalResource = PrincipalResource;
@@ -55,18 +63,27 @@ impl Resource for CalendarObjectResource {
fn get_prop(
&self,
_rmap: &ResourceMap,
_user: &User,
rmap: &ResourceMap,
user: &User,
prop: &Self::PropName,
) -> Result<Self::Prop, Self::Error> {
Ok(match prop {
CalendarObjectPropName::Getetag => CalendarObjectProp::Getetag(self.object.get_etag()),
CalendarObjectPropName::CalendarData => {
CalendarObjectProp::CalendarData(self.object.get_ics().to_owned())
}
CalendarObjectPropName::Getcontenttype => {
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
CalendarObjectPropWrapperName::CalendarObject(prop) => {
CalendarObjectPropWrapper::CalendarObject(match prop {
CalendarObjectPropName::Getetag => {
CalendarObjectProp::Getetag(self.object.get_etag())
}
CalendarObjectPropName::CalendarData => {
CalendarObjectProp::CalendarData(self.object.get_ics().to_owned())
}
CalendarObjectPropName::Getcontenttype => {
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8")
}
})
}
CalendarObjectPropWrapperName::Common(prop) => CalendarObjectPropWrapper::Common(
CommonPropertiesExtension::get_prop(self, rmap, user, prop)?,
),
})
}

View File

@@ -3,6 +3,7 @@ use crate::principal::PrincipalResource;
use crate::Error;
use actix_web::dev::ResourceMap;
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::xml::{HrefElement, Resourcetype, ResourcetypeInner};
@@ -24,9 +25,16 @@ pub enum PrincipalProp {
PrincipalUrl(HrefElement),
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
pub enum PrincipalPropWrapper {
Principal(PrincipalProp),
Common(CommonPropertiesProp),
}
impl Resource for CalendarSetResource {
type PropName = PrincipalPropName;
type Prop = PrincipalProp;
type PropName = PrincipalPropWrapperName;
type Prop = PrincipalPropWrapper;
type Error = Error;
type PrincipalResource = PrincipalResource;
@@ -40,7 +48,7 @@ impl Resource for CalendarSetResource {
fn get_prop(
&self,
rmap: &ResourceMap,
_user: &User,
user: &User,
prop: &Self::PropName,
) -> Result<Self::Prop, Self::Error> {
let principal_href = HrefElement::new(
@@ -48,7 +56,15 @@ impl Resource for CalendarSetResource {
);
Ok(match prop {
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
PrincipalPropWrapperName::Principal(prop) => {
PrincipalPropWrapper::Principal(match prop {
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
})
}
PrincipalPropWrapperName::Common(prop) => PrincipalPropWrapper::Common(
<Self as CommonPropertiesExtension>::get_prop(self, rmap, user, prop)?,
),
})
}

View File

@@ -2,6 +2,7 @@ use crate::calendar_set::CalendarSetResource;
use crate::Error;
use actix_web::dev::ResourceMap;
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::xml::{HrefElement, Resourcetype, ResourcetypeInner};
@@ -38,6 +39,13 @@ pub enum PrincipalProp {
CalendarHomeSet(CalendarHomeSet),
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
#[xml(unit_variants_ident = "PrincipalPropWrapperName", untagged)]
pub enum PrincipalPropWrapper {
Principal(PrincipalProp),
Common(CommonPropertiesProp),
}
impl PrincipalResource {
pub fn get_principal_url(rmap: &ResourceMap, principal: &str) -> String {
Self::get_url(rmap, vec![principal]).unwrap()
@@ -51,8 +59,8 @@ impl NamedRoute for PrincipalResource {
}
impl Resource for PrincipalResource {
type PropName = PrincipalPropName;
type Prop = PrincipalProp;
type PropName = PrincipalPropWrapperName;
type Prop = PrincipalPropWrapper;
type Error = Error;
type PrincipalResource = PrincipalResource;
@@ -66,7 +74,7 @@ impl Resource for PrincipalResource {
fn get_prop(
&self,
rmap: &ResourceMap,
_user: &User,
user: &User,
prop: &Self::PropName,
) -> Result<Self::Prop, Self::Error> {
let principal_url = Self::get_url(rmap, vec![&self.principal]).unwrap();
@@ -78,13 +86,26 @@ impl Resource for PrincipalResource {
);
Ok(match prop {
PrincipalPropName::CalendarUserType => PrincipalProp::CalendarUserType("INDIVIDUAL"),
PrincipalPropName::Displayname => PrincipalProp::Displayname(self.principal.to_owned()),
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_url.into()),
PrincipalPropName::CalendarHomeSet => PrincipalProp::CalendarHomeSet(home_set),
PrincipalPropName::CalendarUserAddressSet => {
PrincipalProp::CalendarUserAddressSet(principal_url.into())
PrincipalPropWrapperName::Principal(prop) => {
PrincipalPropWrapper::Principal(match prop {
PrincipalPropName::CalendarUserType => {
PrincipalProp::CalendarUserType("INDIVIDUAL")
}
PrincipalPropName::Displayname => {
PrincipalProp::Displayname(self.principal.to_owned())
}
PrincipalPropName::PrincipalUrl => {
PrincipalProp::PrincipalUrl(principal_url.into())
}
PrincipalPropName::CalendarHomeSet => PrincipalProp::CalendarHomeSet(home_set),
PrincipalPropName::CalendarUserAddressSet => {
PrincipalProp::CalendarUserAddressSet(principal_url.into())
}
})
}
PrincipalPropWrapperName::Common(prop) => PrincipalPropWrapper::Common(
<Self as CommonPropertiesExtension>::get_prop(self, rmap, user, prop)?,
),
})
}