fix some dumb design decisions

This commit is contained in:
Lennart
2024-11-04 17:57:09 +01:00
parent 0fed7b05fa
commit c41e3e3abb
9 changed files with 17 additions and 72 deletions

View File

@@ -14,9 +14,7 @@ use actix_web::{web::Data, HttpRequest};
use async_trait::async_trait; use async_trait::async_trait;
use derive_more::derive::{From, Into, TryInto}; use derive_more::derive::{From, Into, TryInto};
use rustical_dav::extension::BoxedExtension; use rustical_dav::extension::BoxedExtension;
use rustical_dav::extensions::{ use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
};
use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
use rustical_store::auth::User; use rustical_store::auth::User;
@@ -33,7 +31,7 @@ pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
pub calendar_id: String, pub calendar_id: String,
} }
#[derive(EnumString, VariantNames, Clone, From, TryInto)] #[derive(EnumString, VariantNames, Clone)]
#[strum(serialize_all = "kebab-case")] #[strum(serialize_all = "kebab-case")]
pub enum CalendarPropName { pub enum CalendarPropName {
Displayname, Displayname,
@@ -48,10 +46,6 @@ pub enum CalendarPropName {
SupportedReportSet, SupportedReportSet,
SyncToken, SyncToken,
Getctag, Getctag,
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
#[derive(Deserialize, Serialize, From, TryInto)] #[derive(Deserialize, Serialize, From, TryInto)]
@@ -157,15 +151,11 @@ impl Resource for CalendarResource {
CalendarProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) CalendarProp::Getcontenttype("text/calendar;charset=utf-8".to_owned())
} }
CalendarPropName::MaxResourceSize => CalendarProp::MaxResourceSize(10000000), CalendarPropName::MaxResourceSize => CalendarProp::MaxResourceSize(10000000),
// CalendarPropName::CurrentUserPrivilegeSet => {
// CalendarProp::CurrentUserPrivilegeSet(user_privileges.to_owned())
// }
CalendarPropName::SupportedReportSet => { CalendarPropName::SupportedReportSet => {
CalendarProp::SupportedReportSet(SupportedReportSet::default()) CalendarProp::SupportedReportSet(SupportedReportSet::default())
} }
CalendarPropName::SyncToken => CalendarProp::SyncToken(self.0.format_synctoken()), CalendarPropName::SyncToken => CalendarProp::SyncToken(self.0.format_synctoken()),
CalendarPropName::Getctag => CalendarProp::Getctag(self.0.format_synctoken()), CalendarPropName::Getctag => CalendarProp::Getctag(self.0.format_synctoken()),
_ => panic!("we shouldn't end up here"),
}) })
} }
@@ -197,7 +187,6 @@ impl Resource for CalendarResource {
CalendarProp::SupportedCalendarData(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::SupportedCalendarData(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::Getcontenttype(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::Getcontenttype(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::MaxResourceSize(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::MaxResourceSize(_) => Err(rustical_dav::Error::PropReadOnly),
// CalendarProp::CurrentUserPrivilegeSet(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::SupportedReportSet(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::SupportedReportSet(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::SyncToken(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::SyncToken(_) => Err(rustical_dav::Error::PropReadOnly),
CalendarProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly), CalendarProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly),
@@ -234,11 +223,9 @@ impl Resource for CalendarResource {
CalendarPropName::SupportedCalendarData => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::SupportedCalendarData => Err(rustical_dav::Error::PropReadOnly),
CalendarPropName::Getcontenttype => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::Getcontenttype => Err(rustical_dav::Error::PropReadOnly),
CalendarPropName::MaxResourceSize => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::MaxResourceSize => Err(rustical_dav::Error::PropReadOnly),
// CalendarPropName::CurrentUserPrivilegeSet => Err(rustical_dav::Error::PropReadOnly),
CalendarPropName::SupportedReportSet => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::SupportedReportSet => Err(rustical_dav::Error::PropReadOnly),
CalendarPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly),
CalendarPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::Getctag => Err(rustical_dav::Error::PropReadOnly),
_ => panic!("we shouldn't end up here"),
} }
} }

View File

@@ -5,7 +5,7 @@ use async_trait::async_trait;
use derive_more::derive::{From, Into, TryInto}; use derive_more::derive::{From, Into, TryInto};
use rustical_dav::{ use rustical_dav::{
extension::BoxedExtension, extension::BoxedExtension,
extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName}, extensions::{CommonPropertiesExtension, CommonPropertiesProp},
privileges::UserPrivilegeSet, privileges::UserPrivilegeSet,
resource::{InvalidProperty, Resource, ResourceService}, resource::{InvalidProperty, Resource, ResourceService},
}; };
@@ -22,16 +22,12 @@ pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
pub object_id: String, pub object_id: String,
} }
#[derive(EnumString, VariantNames, Clone, From, TryInto)] #[derive(EnumString, VariantNames, Clone)]
#[strum(serialize_all = "kebab-case")] #[strum(serialize_all = "kebab-case")]
pub enum CalendarObjectPropName { pub enum CalendarObjectPropName {
Getetag, Getetag,
CalendarData, CalendarData,
Getcontenttype, Getcontenttype,
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
#[derive(Deserialize, Serialize, From, TryInto)] #[derive(Deserialize, Serialize, From, TryInto)]
@@ -99,7 +95,6 @@ impl Resource for CalendarObjectResource {
CalendarObjectPropName::Getcontenttype => { CalendarObjectPropName::Getcontenttype => {
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned())
} }
_ => panic!("we shouldn't end up here"),
}) })
} }

View File

@@ -6,9 +6,7 @@ use actix_web::HttpRequest;
use async_trait::async_trait; use async_trait::async_trait;
use derive_more::derive::{From, TryInto}; use derive_more::derive::{From, TryInto};
use rustical_dav::extension::BoxedExtension; use rustical_dav::extension::BoxedExtension;
use rustical_dav::extensions::{ use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
};
use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
use rustical_dav::xml::HrefElement; use rustical_dav::xml::HrefElement;
@@ -63,17 +61,13 @@ impl InvalidProperty for PrincipalProp {
} }
} }
#[derive(EnumString, VariantNames, Clone, From, TryInto)] #[derive(EnumString, VariantNames, Clone)]
#[strum(serialize_all = "kebab-case")] #[strum(serialize_all = "kebab-case")]
pub enum PrincipalPropName { pub enum PrincipalPropName {
#[strum(serialize = "principal-URL")] #[strum(serialize = "principal-URL")]
PrincipalUrl, PrincipalUrl,
CalendarHomeSet, CalendarHomeSet,
CalendarUserAddressSet, CalendarUserAddressSet,
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
impl PrincipalResource { impl PrincipalResource {
@@ -108,7 +102,6 @@ impl Resource for PrincipalResource {
PrincipalPropName::CalendarUserAddressSet => { PrincipalPropName::CalendarUserAddressSet => {
PrincipalProp::CalendarUserAddressSet(principal_href) PrincipalProp::CalendarUserAddressSet(principal_href)
} }
_ => panic!("we shouldn't end up here"),
}) })
} }

View File

@@ -4,7 +4,7 @@ use async_trait::async_trait;
use derive_more::derive::{From, Into, TryInto}; use derive_more::derive::{From, Into, TryInto};
use rustical_dav::{ use rustical_dav::{
extension::BoxedExtension, extension::BoxedExtension,
extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName}, extensions::{CommonPropertiesExtension, CommonPropertiesProp},
privileges::UserPrivilegeSet, privileges::UserPrivilegeSet,
resource::{InvalidProperty, Resource, ResourceService}, resource::{InvalidProperty, Resource, ResourceService},
}; };
@@ -23,16 +23,12 @@ pub struct AddressObjectResourceService<AS: AddressbookStore + ?Sized> {
pub object_id: String, pub object_id: String,
} }
#[derive(EnumString, VariantNames, Clone, From, TryInto)] #[derive(EnumString, VariantNames, Clone)]
#[strum(serialize_all = "kebab-case")] #[strum(serialize_all = "kebab-case")]
pub enum AddressObjectPropName { pub enum AddressObjectPropName {
Getetag, Getetag,
AddressData, AddressData,
Getcontenttype, Getcontenttype,
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
#[derive(Deserialize, Serialize, From, TryInto)] #[derive(Deserialize, Serialize, From, TryInto)]
@@ -100,7 +96,6 @@ impl Resource for AddressObjectResource {
AddressObjectPropName::Getcontenttype => { AddressObjectPropName::Getcontenttype => {
AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned()) AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned())
} }
_ => panic!("we shouldn't end up here"),
}) })
} }

View File

@@ -11,9 +11,7 @@ use actix_web::{web::Data, HttpRequest};
use async_trait::async_trait; use async_trait::async_trait;
use derive_more::derive::{From, Into, TryInto}; use derive_more::derive::{From, Into, TryInto};
use rustical_dav::extension::BoxedExtension; use rustical_dav::extension::BoxedExtension;
use rustical_dav::extensions::{ use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
};
use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
use rustical_store::auth::User; use rustical_store::auth::User;
@@ -30,7 +28,7 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
pub addressbook_id: String, pub addressbook_id: String,
} }
#[derive(EnumString, VariantNames, Clone, From, TryInto)] #[derive(EnumString, VariantNames, Clone)]
#[strum(serialize_all = "kebab-case")] #[strum(serialize_all = "kebab-case")]
pub enum AddressbookPropName { pub enum AddressbookPropName {
Displayname, Displayname,
@@ -41,9 +39,6 @@ pub enum AddressbookPropName {
MaxResourceSize, MaxResourceSize,
SyncToken, SyncToken,
Getctag, Getctag,
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
#[derive(Deserialize, Serialize, From, TryInto)] #[derive(Deserialize, Serialize, From, TryInto)]
@@ -128,7 +123,6 @@ impl Resource for AddressbookResource {
} }
AddressbookPropName::SyncToken => AddressbookProp::SyncToken(self.0.format_synctoken()), AddressbookPropName::SyncToken => AddressbookProp::SyncToken(self.0.format_synctoken()),
AddressbookPropName::Getctag => AddressbookProp::Getctag(self.0.format_synctoken()), AddressbookPropName::Getctag => AddressbookProp::Getctag(self.0.format_synctoken()),
_ => panic!("we shouldn't end up here"),
}) })
} }
@@ -169,7 +163,6 @@ impl Resource for AddressbookResource {
AddressbookPropName::SupportedAddressData => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::SupportedAddressData => Err(rustical_dav::Error::PropReadOnly),
AddressbookPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly),
AddressbookPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::Getctag => Err(rustical_dav::Error::PropReadOnly),
_ => panic!("we shouldn't end up here"),
} }
} }

View File

@@ -6,9 +6,7 @@ use actix_web::HttpRequest;
use async_trait::async_trait; use async_trait::async_trait;
use derive_more::derive::{From, TryInto}; use derive_more::derive::{From, TryInto};
use rustical_dav::extension::BoxedExtension; use rustical_dav::extension::BoxedExtension;
use rustical_dav::extensions::{ use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp};
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
};
use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::privileges::UserPrivilegeSet;
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
use rustical_dav::xml::HrefElement; use rustical_dav::xml::HrefElement;
@@ -70,10 +68,6 @@ pub enum PrincipalPropName {
PrincipalUrl, PrincipalUrl,
AddressbookHomeSet, AddressbookHomeSet,
PrincipalAddress, PrincipalAddress,
#[from]
#[try_into]
#[strum(disabled)]
ExtCommonProperties(CommonPropertiesPropName),
} }
impl PrincipalResource { impl PrincipalResource {
@@ -108,7 +102,6 @@ impl Resource for PrincipalResource {
PrincipalProp::AddressbookHomeSet(principal_href) PrincipalProp::AddressbookHomeSet(principal_href)
} }
PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None), PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None),
_ => panic!("we shouldn't end up here"),
}) })
} }

View File

@@ -35,7 +35,7 @@ pub trait BoxableExtension<R: Resource> {
resource: &R, resource: &R,
rmap: &ResourceMap, rmap: &ResourceMap,
user: &User, user: &User,
prop: R::PropName, prop: &str,
) -> Result<Option<R::Prop>, R::Error>; ) -> Result<Option<R::Prop>, R::Error>;
fn propfind<'a>( fn propfind<'a>(
@@ -51,12 +51,7 @@ pub trait BoxableExtension<R: Resource> {
impl< impl<
R: Resource, R: Resource,
RE: ResourceExtension< RE: ResourceExtension<R, Prop: Into<R::Prop> + TryFrom<R::Prop>, Error: Into<R::Error>>,
R,
PropName: Into<R::PropName> + TryFrom<R::PropName>,
Prop: Into<R::Prop> + TryFrom<R::Prop>,
Error: Into<R::Error>,
>,
> BoxableExtension<R> for RE > BoxableExtension<R> for RE
{ {
fn get_prop( fn get_prop(
@@ -64,9 +59,10 @@ impl<
resource: &R, resource: &R,
rmap: &ResourceMap, rmap: &ResourceMap,
user: &User, user: &User,
prop: <R as Resource>::PropName, prop: &str,
// prop: <R as Resource>::PropName,
) -> Result<Option<R::Prop>, R::Error> { ) -> Result<Option<R::Prop>, R::Error> {
let prop: RE::PropName = if let Ok(prop) = prop.try_into() { let prop: RE::PropName = if let Ok(prop) = prop.parse() {
prop prop
} else { } else {
return Ok(None); return Ok(None);
@@ -118,13 +114,7 @@ impl<
pub struct BoxedExtension<R>(Box<dyn BoxableExtension<R>>); pub struct BoxedExtension<R>(Box<dyn BoxableExtension<R>>);
impl<R: Resource> BoxedExtension<R> { impl<R: Resource> BoxedExtension<R> {
pub fn from_ext< pub fn from_ext<RE: ResourceExtension<R, Prop: Into<R::Prop> + TryFrom<R::Prop>> + 'static>(
RE: ResourceExtension<
R,
PropName: Into<R::PropName> + TryFrom<R::PropName>,
Prop: Into<R::Prop> + TryFrom<R::Prop>,
> + 'static,
>(
ext: RE, ext: RE,
) -> Self { ) -> Self {
let boxed_ext: Box<dyn BoxableExtension<R>> = Box::new(ext); let boxed_ext: Box<dyn BoxableExtension<R>> = Box::new(ext);

View File

@@ -53,7 +53,6 @@ pub enum CommonPropertiesPropName {
impl<R: Resource, PR: Resource> ResourceExtension<R> for CommonPropertiesExtension<PR> impl<R: Resource, PR: Resource> ResourceExtension<R> for CommonPropertiesExtension<PR>
where where
R::PropName: TryInto<CommonPropertiesPropName>,
R::Prop: From<CommonPropertiesProp<R>>, R::Prop: From<CommonPropertiesProp<R>>,
{ {
type Prop = CommonPropertiesProp<R>; type Prop = CommonPropertiesProp<R>;