Remove Resource::PropName

This commit is contained in:
Lennart
2025-01-18 23:18:59 +01:00
parent 020e836c42
commit 8359e4ee1c
11 changed files with 29 additions and 30 deletions

View File

@@ -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)),

View File

@@ -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())