mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 14:42:30 +00:00
Remove Resource::PropName
This commit is contained in:
@@ -93,7 +93,6 @@ impl DavPushExtension for CalendarResource {
|
||||
}
|
||||
|
||||
impl Resource for CalendarResource {
|
||||
type PropName = CalendarPropWrapperName;
|
||||
type Prop = CalendarPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -119,7 +118,7 @@ impl Resource for CalendarResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &CalendarPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
CalendarPropWrapperName::Calendar(prop) => CalendarPropWrapper::Calendar(match prop {
|
||||
@@ -230,7 +229,7 @@ impl Resource for CalendarResource {
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||
fn remove_prop(&mut self, prop: &CalendarPropWrapperName) -> Result<(), rustical_dav::Error> {
|
||||
if self.read_only {
|
||||
return Err(rustical_dav::Error::PropReadOnly);
|
||||
}
|
||||
|
||||
@@ -52,7 +52,6 @@ pub struct CalendarObjectResource {
|
||||
}
|
||||
|
||||
impl Resource for CalendarObjectResource {
|
||||
type PropName = CalendarObjectPropWrapperName;
|
||||
type Prop = CalendarObjectPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -65,7 +64,7 @@ impl Resource for CalendarObjectResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &CalendarObjectPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
CalendarObjectPropWrapperName::CalendarObject(prop) => {
|
||||
|
||||
@@ -24,7 +24,6 @@ pub enum PrincipalPropWrapper {
|
||||
}
|
||||
|
||||
impl Resource for CalendarSetResource {
|
||||
type PropName = PrincipalPropWrapperName;
|
||||
type Prop = PrincipalPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -40,7 +39,7 @@ impl Resource for CalendarSetResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &PrincipalPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
PrincipalPropWrapperName::Common(prop) => PrincipalPropWrapper::Common(
|
||||
|
||||
@@ -59,7 +59,6 @@ impl NamedRoute for PrincipalResource {
|
||||
}
|
||||
|
||||
impl Resource for PrincipalResource {
|
||||
type PropName = PrincipalPropWrapperName;
|
||||
type Prop = PrincipalPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -75,7 +74,7 @@ impl Resource for PrincipalResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &PrincipalPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
let principal_url = Self::get_url(rmap, vec![&self.principal]).unwrap();
|
||||
let home_set = CalendarHomeSet(
|
||||
|
||||
@@ -48,7 +48,6 @@ pub struct AddressObjectResource {
|
||||
}
|
||||
|
||||
impl Resource for AddressObjectResource {
|
||||
type PropName = AddressObjectPropWrapperName;
|
||||
type Prop = AddressObjectPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -61,7 +60,7 @@ impl Resource for AddressObjectResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &AddressObjectPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
AddressObjectPropWrapperName::AddressObject(prop) => {
|
||||
|
||||
@@ -81,7 +81,6 @@ impl DavPushExtension for AddressbookResource {
|
||||
}
|
||||
|
||||
impl Resource for AddressbookResource {
|
||||
type PropName = AddressbookPropWrapperName;
|
||||
type Prop = AddressbookPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -97,7 +96,7 @@ impl Resource for AddressbookResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &AddressbookPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
AddressbookPropWrapperName::Addressbook(prop) => {
|
||||
@@ -153,7 +152,10 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||
fn remove_prop(
|
||||
&mut self,
|
||||
prop: &AddressbookPropWrapperName,
|
||||
) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookPropWrapperName::Addressbook(prop) => match prop {
|
||||
AddressbookPropName::Displayname => {
|
||||
|
||||
@@ -64,7 +64,6 @@ impl NamedRoute for PrincipalResource {
|
||||
}
|
||||
|
||||
impl Resource for PrincipalResource {
|
||||
type PropName = PrincipalPropWrapperName;
|
||||
type Prop = PrincipalPropWrapper;
|
||||
type Error = Error;
|
||||
type PrincipalResource = PrincipalResource;
|
||||
@@ -80,7 +79,7 @@ impl Resource for PrincipalResource {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &PrincipalPropWrapperName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
let principal_href = HrefElement::new(Self::get_principal_url(rmap, &self.principal));
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ use actix_web::{web::Path, HttpRequest};
|
||||
use itertools::Itertools;
|
||||
use quick_xml::name::Namespace;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_xml::EnumUnitVariants;
|
||||
use rustical_xml::Unparsed;
|
||||
use rustical_xml::XmlDeserialize;
|
||||
use rustical_xml::XmlDocument;
|
||||
@@ -97,7 +98,7 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
}) => {
|
||||
match property {
|
||||
SetPropertyPropWrapper::Valid(prop) => {
|
||||
let propname: <R::Resource as Resource>::PropName = prop.clone().into();
|
||||
let propname: <<R::Resource as Resource>::Prop as EnumUnitVariants>::UnitVariants = prop.clone().into();
|
||||
let (ns, propname): (Option<Namespace>, &str) = propname.into();
|
||||
match resource.set_prop(prop) {
|
||||
Ok(()) => props_ok.push((ns, propname.to_owned())),
|
||||
@@ -127,7 +128,9 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
}
|
||||
Operation::Remove(remove_el) => {
|
||||
let propname = remove_el.prop.0 .0;
|
||||
match <<R::Resource as Resource>::PropName as FromStr>::from_str(&propname) {
|
||||
match <<R::Resource as Resource>::Prop as EnumUnitVariants>::UnitVariants::from_str(
|
||||
&propname,
|
||||
) {
|
||||
Ok(prop) => match resource.remove_prop(&prop) {
|
||||
Ok(()) => props_ok.push((None, propname)),
|
||||
Err(Error::PropReadOnly) => props_conflict.push((None, propname)),
|
||||
|
||||
@@ -9,7 +9,7 @@ use itertools::Itertools;
|
||||
use quick_xml::name::Namespace;
|
||||
pub use resource_service::ResourceService;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_xml::{EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize};
|
||||
use std::str::FromStr;
|
||||
|
||||
mod methods;
|
||||
@@ -24,10 +24,7 @@ pub trait ResourcePropName: FromStr {}
|
||||
impl<T: FromStr> ResourcePropName for T {}
|
||||
|
||||
pub trait Resource: Clone + 'static {
|
||||
type PropName: ResourcePropName
|
||||
+ From<Self::Prop>
|
||||
+ Into<(Option<Namespace<'static>>, &'static str)>;
|
||||
type Prop: ResourceProp + PartialEq + Clone + EnumVariants;
|
||||
type Prop: ResourceProp + PartialEq + Clone + EnumVariants + EnumUnitVariants;
|
||||
type Error: ResponseError + From<crate::Error>;
|
||||
type PrincipalResource: Resource + NamedRoute;
|
||||
|
||||
@@ -41,14 +38,17 @@ pub trait Resource: Clone + 'static {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &<Self::Prop as EnumUnitVariants>::UnitVariants,
|
||||
) -> Result<Self::Prop, Self::Error>;
|
||||
|
||||
fn set_prop(&mut self, _prop: Self::Prop) -> Result<(), crate::Error> {
|
||||
Err(crate::Error::PropReadOnly)
|
||||
}
|
||||
|
||||
fn remove_prop(&mut self, _prop: &Self::PropName) -> Result<(), crate::Error> {
|
||||
fn remove_prop(
|
||||
&mut self,
|
||||
_prop: &<Self::Prop as EnumUnitVariants>::UnitVariants,
|
||||
) -> Result<(), crate::Error> {
|
||||
Err(crate::Error::PropReadOnly)
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ pub trait Resource: Clone + 'static {
|
||||
let mut valid_props = vec![];
|
||||
let mut invalid_props = vec![];
|
||||
for prop in props {
|
||||
if let Ok(valid_prop) = Self::PropName::from_str(prop) {
|
||||
if let Ok(valid_prop) = <Self::Prop as EnumUnitVariants>::UnitVariants::from_str(prop) {
|
||||
valid_props.push(valid_prop);
|
||||
} else {
|
||||
invalid_props.push(prop.to_string())
|
||||
|
||||
@@ -19,7 +19,6 @@ impl<PR: Resource> Default for RootResource<PR> {
|
||||
}
|
||||
|
||||
impl<PR: Resource + NamedRoute> Resource for RootResource<PR> {
|
||||
type PropName = CommonPropertiesPropName;
|
||||
type Prop = CommonPropertiesProp;
|
||||
type Error = PR::Error;
|
||||
type PrincipalResource = PR;
|
||||
@@ -35,7 +34,7 @@ impl<PR: Resource + NamedRoute> Resource for RootResource<PR> {
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
prop: &CommonPropertiesPropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
CommonPropertiesExtension::get_prop(self, rmap, user, prop)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use quick_xml::name::Namespace;
|
||||
use std::collections::HashMap;
|
||||
use std::str::FromStr;
|
||||
|
||||
pub mod de;
|
||||
mod error;
|
||||
@@ -34,6 +35,6 @@ pub trait EnumVariants {
|
||||
fn variant_names() -> Vec<(Option<Namespace<'static>>, &'static str)>;
|
||||
}
|
||||
|
||||
pub trait EnumUnitVariants {
|
||||
type UnitVariants;
|
||||
pub trait EnumUnitVariants: Sized {
|
||||
type UnitVariants: Into<(Option<Namespace<'static>>, &'static str)> + From<Self> + FromStr;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user