mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
fix some dumb design decisions
This commit is contained in:
@@ -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<C: CalendarStore + ?Sized> {
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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<C: CalendarStore + ?Sized> {
|
||||
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"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AS: AddressbookStore + ?Sized> {
|
||||
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"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AS: AddressbookStore + ?Sized> {
|
||||
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"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -35,7 +35,7 @@ pub trait BoxableExtension<R: Resource> {
|
||||
resource: &R,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: R::PropName,
|
||||
prop: &str,
|
||||
) -> Result<Option<R::Prop>, R::Error>;
|
||||
|
||||
fn propfind<'a>(
|
||||
@@ -51,12 +51,7 @@ pub trait BoxableExtension<R: Resource> {
|
||||
|
||||
impl<
|
||||
R: Resource,
|
||||
RE: ResourceExtension<
|
||||
R,
|
||||
PropName: Into<R::PropName> + TryFrom<R::PropName>,
|
||||
Prop: Into<R::Prop> + TryFrom<R::Prop>,
|
||||
Error: Into<R::Error>,
|
||||
>,
|
||||
RE: ResourceExtension<R, Prop: Into<R::Prop> + TryFrom<R::Prop>, Error: Into<R::Error>>,
|
||||
> BoxableExtension<R> for RE
|
||||
{
|
||||
fn get_prop(
|
||||
@@ -64,9 +59,10 @@ impl<
|
||||
resource: &R,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: <R as Resource>::PropName,
|
||||
prop: &str,
|
||||
// prop: <R as Resource>::PropName,
|
||||
) -> 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
|
||||
} else {
|
||||
return Ok(None);
|
||||
@@ -118,13 +114,7 @@ impl<
|
||||
pub struct BoxedExtension<R>(Box<dyn BoxableExtension<R>>);
|
||||
|
||||
impl<R: Resource> BoxedExtension<R> {
|
||||
pub fn from_ext<
|
||||
RE: ResourceExtension<
|
||||
R,
|
||||
PropName: Into<R::PropName> + TryFrom<R::PropName>,
|
||||
Prop: Into<R::Prop> + TryFrom<R::Prop>,
|
||||
> + 'static,
|
||||
>(
|
||||
pub fn from_ext<RE: ResourceExtension<R, Prop: Into<R::Prop> + TryFrom<R::Prop>> + 'static>(
|
||||
ext: RE,
|
||||
) -> Self {
|
||||
let boxed_ext: Box<dyn BoxableExtension<R>> = Box::new(ext);
|
||||
|
||||
@@ -53,7 +53,6 @@ pub enum CommonPropertiesPropName {
|
||||
|
||||
impl<R: Resource, PR: Resource> ResourceExtension<R> for CommonPropertiesExtension<PR>
|
||||
where
|
||||
R::PropName: TryInto<CommonPropertiesPropName>,
|
||||
R::Prop: From<CommonPropertiesProp<R>>,
|
||||
{
|
||||
type Prop = CommonPropertiesProp<R>;
|
||||
|
||||
Reference in New Issue
Block a user