mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 07:02:24 +00:00
xml use tuple structs
This commit is contained in:
@@ -13,7 +13,7 @@ use actix_web::web::Data;
|
||||
use actix_web::web::Path;
|
||||
use actix_web::HttpRequest;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_xml::de::XmlDocument;
|
||||
use rustical_xml::XmlDocument;
|
||||
use tracing::instrument;
|
||||
use tracing_actix_web::RootSpan;
|
||||
|
||||
@@ -53,9 +53,9 @@ pub(crate) async fn route_propfind<R: ResourceService>(
|
||||
let props = match &propfind.prop {
|
||||
PropfindType::Allprop => vec!["allprop"],
|
||||
PropfindType::Propname => vec!["propname"],
|
||||
PropfindType::Prop(PropElement { prop: prop_tags }) => prop_tags
|
||||
PropfindType::Prop(PropElement(prop_tags)) => prop_tags
|
||||
.iter()
|
||||
.map(|propname| propname.name.as_str())
|
||||
.map(|propname| propname.0.as_str())
|
||||
.collect(),
|
||||
};
|
||||
|
||||
|
||||
@@ -26,10 +26,9 @@ enum SetPropertyPropWrapper<T: XmlDeserialize> {
|
||||
|
||||
// We are <prop>
|
||||
#[derive(XmlDeserialize, Clone, Debug)]
|
||||
struct SetPropertyPropWrapperWrapper<T: XmlDeserialize> {
|
||||
#[xml(ty = "untagged")]
|
||||
property: SetPropertyPropWrapper<T>,
|
||||
}
|
||||
struct SetPropertyPropWrapperWrapper<T: XmlDeserialize>(
|
||||
#[xml(ty = "untagged")] SetPropertyPropWrapper<T>,
|
||||
);
|
||||
|
||||
// We are <set>
|
||||
#[derive(XmlDeserialize, Clone, Debug)]
|
||||
@@ -39,16 +38,10 @@ struct SetPropertyElement<T: XmlDeserialize> {
|
||||
}
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug)]
|
||||
struct TagName {
|
||||
#[xml(ty = "tag_name")]
|
||||
name: String,
|
||||
}
|
||||
struct TagName(#[xml(ty = "tag_name")] String);
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug)]
|
||||
struct PropertyElement {
|
||||
#[xml(ty = "untagged")]
|
||||
property: TagName,
|
||||
}
|
||||
struct PropertyElement(#[xml(ty = "untagged")] TagName);
|
||||
|
||||
#[derive(XmlDeserialize, Clone, Debug)]
|
||||
struct RemovePropertyElement {
|
||||
@@ -67,10 +60,7 @@ enum Operation<T: XmlDeserialize> {
|
||||
#[derive(XmlDeserialize, XmlRootTag, Clone, Debug)]
|
||||
#[xml(root = b"propertyupdate")]
|
||||
#[xml(ns = "crate::namespace::NS_DAV")]
|
||||
struct PropertyupdateElement<T: XmlDeserialize> {
|
||||
#[xml(ty = "untagged", flatten)]
|
||||
operations: Vec<Operation<T>>,
|
||||
}
|
||||
struct PropertyupdateElement<T: XmlDeserialize>(#[xml(ty = "untagged", flatten)] Vec<Operation<T>>);
|
||||
|
||||
#[instrument(parent = root_span.id(), skip(path, req, root_span, resource_service))]
|
||||
pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
@@ -84,9 +74,9 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
let href = req.path().to_owned();
|
||||
|
||||
// Extract operations
|
||||
let PropertyupdateElement::<SetPropertyPropWrapperWrapper<<R::Resource as Resource>::Prop>> {
|
||||
let PropertyupdateElement::<SetPropertyPropWrapperWrapper<<R::Resource as Resource>::Prop>>(
|
||||
operations,
|
||||
} = XmlDocument::parse_str(&body).map_err(Error::XmlDeserializationError)?;
|
||||
) = XmlDocument::parse_str(&body).map_err(Error::XmlDeserializationError)?;
|
||||
|
||||
let mut resource = resource_service.get_resource(&path).await?;
|
||||
let privileges = resource.get_user_privileges(&user)?;
|
||||
@@ -100,8 +90,10 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
|
||||
for operation in operations.into_iter() {
|
||||
match operation {
|
||||
Operation::Set(SetPropertyElement { prop }) => {
|
||||
match prop.property {
|
||||
Operation::Set(SetPropertyElement {
|
||||
prop: SetPropertyPropWrapperWrapper(property),
|
||||
}) => {
|
||||
match property {
|
||||
SetPropertyPropWrapper::Valid(prop) => {
|
||||
let propname: <R::Resource as Resource>::PropName = prop.clone().into();
|
||||
let propname: &str = propname.into();
|
||||
@@ -125,7 +117,7 @@ pub(crate) async fn route_proppatch<R: ResourceService>(
|
||||
}
|
||||
}
|
||||
Operation::Remove(remove_el) => {
|
||||
let propname = remove_el.prop.property.name;
|
||||
let propname = remove_el.prop.0 .0;
|
||||
match <<R::Resource as Resource>::PropName as FromStr>::from_str(&propname) {
|
||||
Ok(prop) => match resource.remove_prop(&prop) {
|
||||
Ok(()) => props_ok.push(propname),
|
||||
|
||||
@@ -207,9 +207,7 @@ pub trait Resource: Clone + 'static {
|
||||
|
||||
let mut propstats = vec![PropstatWrapper::Normal(PropstatElement {
|
||||
status: StatusCode::OK,
|
||||
prop: PropTagWrapper {
|
||||
prop: prop_responses,
|
||||
},
|
||||
prop: PropTagWrapper(prop_responses),
|
||||
})];
|
||||
if !invalid_props.is_empty() {
|
||||
propstats.push(PropstatWrapper::TagList(PropstatElement {
|
||||
|
||||
Reference in New Issue
Block a user