From c41e3e3abbbfa3ff6049dafe274dfc9b153e418f Mon Sep 17 00:00:00 2001 From: Lennart <18233294+lennart-k@users.noreply.github.com> Date: Mon, 4 Nov 2024 17:57:09 +0100 Subject: [PATCH] fix some dumb design decisions --- crates/caldav/src/calendar/resource.rs | 17 ++------------ crates/caldav/src/calendar_object/resource.rs | 9 ++------ crates/caldav/src/principal/mod.rs | 11 ++-------- crates/carddav/src/address_object/resource.rs | 9 ++------ crates/carddav/src/addressbook/resource.rs | 11 ++-------- crates/carddav/src/principal/mod.rs | 9 +------- crates/dav/src/extension.rs | 22 +++++-------------- crates/dav/src/extensions/mod.rs | 1 - .../dav/src/{resource.rs => resource/mod.rs} | 0 9 files changed, 17 insertions(+), 72 deletions(-) rename crates/dav/src/{resource.rs => resource/mod.rs} (100%) diff --git a/crates/caldav/src/calendar/resource.rs b/crates/caldav/src/calendar/resource.rs index c0c1e81..9208ebb 100644 --- a/crates/caldav/src/calendar/resource.rs +++ b/crates/caldav/src/calendar/resource.rs @@ -14,9 +14,7 @@ use actix_web::{web::Data, HttpRequest}; use async_trait::async_trait; use derive_more::derive::{From, Into, TryInto}; use rustical_dav::extension::BoxedExtension; -use rustical_dav::extensions::{ - CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName, -}; +use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp}; use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_store::auth::User; @@ -33,7 +31,7 @@ pub struct CalendarResourceService { pub calendar_id: String, } -#[derive(EnumString, VariantNames, Clone, From, TryInto)] +#[derive(EnumString, VariantNames, Clone)] #[strum(serialize_all = "kebab-case")] pub enum CalendarPropName { Displayname, @@ -48,10 +46,6 @@ pub enum CalendarPropName { SupportedReportSet, SyncToken, Getctag, - #[from] - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } #[derive(Deserialize, Serialize, From, TryInto)] @@ -157,15 +151,11 @@ impl Resource for CalendarResource { CalendarProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) } CalendarPropName::MaxResourceSize => CalendarProp::MaxResourceSize(10000000), - // CalendarPropName::CurrentUserPrivilegeSet => { - // CalendarProp::CurrentUserPrivilegeSet(user_privileges.to_owned()) - // } CalendarPropName::SupportedReportSet => { CalendarProp::SupportedReportSet(SupportedReportSet::default()) } CalendarPropName::SyncToken => CalendarProp::SyncToken(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::Getcontenttype(_) => 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::SyncToken(_) => 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::Getcontenttype => 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::SyncToken => Err(rustical_dav::Error::PropReadOnly), CalendarPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), - _ => panic!("we shouldn't end up here"), } } diff --git a/crates/caldav/src/calendar_object/resource.rs b/crates/caldav/src/calendar_object/resource.rs index dd7f3d2..01b01e5 100644 --- a/crates/caldav/src/calendar_object/resource.rs +++ b/crates/caldav/src/calendar_object/resource.rs @@ -5,7 +5,7 @@ use async_trait::async_trait; use derive_more::derive::{From, Into, TryInto}; use rustical_dav::{ extension::BoxedExtension, - extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName}, + extensions::{CommonPropertiesExtension, CommonPropertiesProp}, privileges::UserPrivilegeSet, resource::{InvalidProperty, Resource, ResourceService}, }; @@ -22,16 +22,12 @@ pub struct CalendarObjectResourceService { pub object_id: String, } -#[derive(EnumString, VariantNames, Clone, From, TryInto)] +#[derive(EnumString, VariantNames, Clone)] #[strum(serialize_all = "kebab-case")] pub enum CalendarObjectPropName { Getetag, CalendarData, Getcontenttype, - #[from] - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } #[derive(Deserialize, Serialize, From, TryInto)] @@ -99,7 +95,6 @@ impl Resource for CalendarObjectResource { CalendarObjectPropName::Getcontenttype => { CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned()) } - _ => panic!("we shouldn't end up here"), }) } diff --git a/crates/caldav/src/principal/mod.rs b/crates/caldav/src/principal/mod.rs index 2b6ab0d..da4ed68 100644 --- a/crates/caldav/src/principal/mod.rs +++ b/crates/caldav/src/principal/mod.rs @@ -6,9 +6,7 @@ use actix_web::HttpRequest; use async_trait::async_trait; use derive_more::derive::{From, TryInto}; use rustical_dav::extension::BoxedExtension; -use rustical_dav::extensions::{ - CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName, -}; +use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp}; use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; 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")] pub enum PrincipalPropName { #[strum(serialize = "principal-URL")] PrincipalUrl, CalendarHomeSet, CalendarUserAddressSet, - #[from] - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } impl PrincipalResource { @@ -108,7 +102,6 @@ impl Resource for PrincipalResource { PrincipalPropName::CalendarUserAddressSet => { PrincipalProp::CalendarUserAddressSet(principal_href) } - _ => panic!("we shouldn't end up here"), }) } diff --git a/crates/carddav/src/address_object/resource.rs b/crates/carddav/src/address_object/resource.rs index 7427200..077d87f 100644 --- a/crates/carddav/src/address_object/resource.rs +++ b/crates/carddav/src/address_object/resource.rs @@ -4,7 +4,7 @@ use async_trait::async_trait; use derive_more::derive::{From, Into, TryInto}; use rustical_dav::{ extension::BoxedExtension, - extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName}, + extensions::{CommonPropertiesExtension, CommonPropertiesProp}, privileges::UserPrivilegeSet, resource::{InvalidProperty, Resource, ResourceService}, }; @@ -23,16 +23,12 @@ pub struct AddressObjectResourceService { pub object_id: String, } -#[derive(EnumString, VariantNames, Clone, From, TryInto)] +#[derive(EnumString, VariantNames, Clone)] #[strum(serialize_all = "kebab-case")] pub enum AddressObjectPropName { Getetag, AddressData, Getcontenttype, - #[from] - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } #[derive(Deserialize, Serialize, From, TryInto)] @@ -100,7 +96,6 @@ impl Resource for AddressObjectResource { AddressObjectPropName::Getcontenttype => { AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned()) } - _ => panic!("we shouldn't end up here"), }) } diff --git a/crates/carddav/src/addressbook/resource.rs b/crates/carddav/src/addressbook/resource.rs index 5d28c26..c93e17d 100644 --- a/crates/carddav/src/addressbook/resource.rs +++ b/crates/carddav/src/addressbook/resource.rs @@ -11,9 +11,7 @@ use actix_web::{web::Data, HttpRequest}; use async_trait::async_trait; use derive_more::derive::{From, Into, TryInto}; use rustical_dav::extension::BoxedExtension; -use rustical_dav::extensions::{ - CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName, -}; +use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp}; use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_store::auth::User; @@ -30,7 +28,7 @@ pub struct AddressbookResourceService { pub addressbook_id: String, } -#[derive(EnumString, VariantNames, Clone, From, TryInto)] +#[derive(EnumString, VariantNames, Clone)] #[strum(serialize_all = "kebab-case")] pub enum AddressbookPropName { Displayname, @@ -41,9 +39,6 @@ pub enum AddressbookPropName { MaxResourceSize, SyncToken, Getctag, - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } #[derive(Deserialize, Serialize, From, TryInto)] @@ -128,7 +123,6 @@ impl Resource for AddressbookResource { } AddressbookPropName::SyncToken => AddressbookProp::SyncToken(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::SyncToken => Err(rustical_dav::Error::PropReadOnly), AddressbookPropName::Getctag => Err(rustical_dav::Error::PropReadOnly), - _ => panic!("we shouldn't end up here"), } } diff --git a/crates/carddav/src/principal/mod.rs b/crates/carddav/src/principal/mod.rs index bc5c128..e76e6b3 100644 --- a/crates/carddav/src/principal/mod.rs +++ b/crates/carddav/src/principal/mod.rs @@ -6,9 +6,7 @@ use actix_web::HttpRequest; use async_trait::async_trait; use derive_more::derive::{From, TryInto}; use rustical_dav::extension::BoxedExtension; -use rustical_dav::extensions::{ - CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName, -}; +use rustical_dav::extensions::{CommonPropertiesExtension, CommonPropertiesProp}; use rustical_dav::privileges::UserPrivilegeSet; use rustical_dav::resource::{InvalidProperty, Resource, ResourceService}; use rustical_dav::xml::HrefElement; @@ -70,10 +68,6 @@ pub enum PrincipalPropName { PrincipalUrl, AddressbookHomeSet, PrincipalAddress, - #[from] - #[try_into] - #[strum(disabled)] - ExtCommonProperties(CommonPropertiesPropName), } impl PrincipalResource { @@ -108,7 +102,6 @@ impl Resource for PrincipalResource { PrincipalProp::AddressbookHomeSet(principal_href) } PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None), - _ => panic!("we shouldn't end up here"), }) } diff --git a/crates/dav/src/extension.rs b/crates/dav/src/extension.rs index 656b30c..980eae6 100644 --- a/crates/dav/src/extension.rs +++ b/crates/dav/src/extension.rs @@ -35,7 +35,7 @@ pub trait BoxableExtension { resource: &R, rmap: &ResourceMap, user: &User, - prop: R::PropName, + prop: &str, ) -> Result, R::Error>; fn propfind<'a>( @@ -51,12 +51,7 @@ pub trait BoxableExtension { impl< R: Resource, - RE: ResourceExtension< - R, - PropName: Into + TryFrom, - Prop: Into + TryFrom, - Error: Into, - >, + RE: ResourceExtension + TryFrom, Error: Into>, > BoxableExtension for RE { fn get_prop( @@ -64,9 +59,10 @@ impl< resource: &R, rmap: &ResourceMap, user: &User, - prop: ::PropName, + prop: &str, + // prop: ::PropName, ) -> Result, R::Error> { - let prop: RE::PropName = if let Ok(prop) = prop.try_into() { + let prop: RE::PropName = if let Ok(prop) = prop.parse() { prop } else { return Ok(None); @@ -118,13 +114,7 @@ impl< pub struct BoxedExtension(Box>); impl BoxedExtension { - pub fn from_ext< - RE: ResourceExtension< - R, - PropName: Into + TryFrom, - Prop: Into + TryFrom, - > + 'static, - >( + pub fn from_ext + TryFrom> + 'static>( ext: RE, ) -> Self { let boxed_ext: Box> = Box::new(ext); diff --git a/crates/dav/src/extensions/mod.rs b/crates/dav/src/extensions/mod.rs index 866d745..1074ee5 100644 --- a/crates/dav/src/extensions/mod.rs +++ b/crates/dav/src/extensions/mod.rs @@ -53,7 +53,6 @@ pub enum CommonPropertiesPropName { impl ResourceExtension for CommonPropertiesExtension where - R::PropName: TryInto, R::Prop: From>, { type Prop = CommonPropertiesProp; diff --git a/crates/dav/src/resource.rs b/crates/dav/src/resource/mod.rs similarity index 100% rename from crates/dav/src/resource.rs rename to crates/dav/src/resource/mod.rs