proppatch: Respect namespaces in more cases

This commit is contained in:
Lennart
2025-01-18 23:45:29 +01:00
parent 8359e4ee1c
commit 670c28c72f

View File

@@ -8,7 +8,6 @@ use crate::Error;
use actix_web::http::StatusCode; use actix_web::http::StatusCode;
use actix_web::web::Data; use actix_web::web::Data;
use actix_web::{web::Path, HttpRequest}; use actix_web::{web::Path, HttpRequest};
use itertools::Itertools;
use quick_xml::name::Namespace; use quick_xml::name::Namespace;
use rustical_store::auth::User; use rustical_store::auth::User;
use rustical_xml::EnumUnitVariants; use rustical_xml::EnumUnitVariants;
@@ -110,16 +109,21 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
} }
SetPropertyPropWrapper::Invalid(invalid) => { SetPropertyPropWrapper::Invalid(invalid) => {
let propname = invalid.tag_name(); let propname = invalid.tag_name();
if <R::Resource as Resource>::list_props()
if let Some(full_propname) = <R::Resource as Resource>::list_props()
.into_iter() .into_iter()
.map(|(_ns, tag)| tag) .find_map(|(ns, tag)| {
.collect_vec() if tag == propname.as_str() {
.contains(&propname.as_str()) Some((ns, tag.to_owned()))
} else {
None
}
})
{ {
// This happens in following cases: // This happens in following cases:
// - read-only properties with #[serde(skip_deserializing)] // - read-only properties with #[serde(skip_deserializing)]
// - internal properties // - internal properties
props_conflict.push((None, propname)) props_conflict.push(full_propname)
} else { } else {
props_not_found.push((None, propname)); props_not_found.push((None, propname));
} }
@@ -133,7 +137,10 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
) { ) {
Ok(prop) => match resource.remove_prop(&prop) { Ok(prop) => match resource.remove_prop(&prop) {
Ok(()) => props_ok.push((None, propname)), Ok(()) => props_ok.push((None, propname)),
Err(Error::PropReadOnly) => props_conflict.push((None, propname)), Err(Error::PropReadOnly) => props_conflict.push({
let (ns, tag) = prop.into();
(ns, tag.to_owned())
}),
Err(err) => return Err(err.into()), Err(err) => return Err(err.into()),
}, },
// I guess removing a nonexisting property should be successful :) // I guess removing a nonexisting property should be successful :)