dav: Refactor proppatch, remove InvalidProperty trait

This commit is contained in:
Lennart
2024-12-25 17:34:38 +01:00
parent d74e0fa702
commit 8fdaba2b57
13 changed files with 90 additions and 143 deletions

View File

@@ -10,7 +10,7 @@ use rustical_store::{auth::User, AddressObject, AddressbookStore};
use rustical_xml::XmlDeserialize;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use strum::{EnumDiscriminants, EnumString, VariantNames};
use strum::{EnumDiscriminants, EnumString, IntoStaticStr, VariantNames};
use super::methods::{get_object, put_object};
@@ -21,10 +21,10 @@ pub struct AddressObjectResourceService<AS: AddressbookStore + ?Sized> {
object_id: String,
}
#[derive(Default, XmlDeserialize, Serialize, PartialEq, EnumDiscriminants)]
#[derive(XmlDeserialize, Serialize, PartialEq, EnumDiscriminants, Clone)]
#[strum_discriminants(
name(AddressObjectPropName),
derive(EnumString, VariantNames),
derive(EnumString, VariantNames, IntoStaticStr),
strum(serialize_all = "kebab-case")
)]
#[serde(rename_all = "kebab-case")]
@@ -36,12 +36,6 @@ pub enum AddressObjectProp {
// CalDAV (RFC 4791)
#[serde(rename = "CARD:address-data")]
AddressData(String),
#[serde(other)]
#[xml(other)]
#[strum_discriminants(strum(disabled))]
#[default]
Invalid,
}
#[derive(Clone, From, Into)]
@@ -74,9 +68,6 @@ impl Resource for AddressObjectResource {
AddressObjectPropName::Getcontenttype => {
AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned())
}
AddressObjectPropName::Invalid => {
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
}
})
}

View File

@@ -18,7 +18,7 @@ use rustical_xml::XmlDeserialize;
use serde::Serialize;
use std::str::FromStr;
use std::sync::Arc;
use strum::{EnumDiscriminants, EnumString, VariantNames};
use strum::{EnumDiscriminants, EnumString, IntoStaticStr, VariantNames};
pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
addr_store: Arc<AS>,
@@ -26,11 +26,11 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
addressbook_id: String,
}
#[derive(Default, XmlDeserialize, Serialize, PartialEq, EnumDiscriminants)]
#[derive(XmlDeserialize, Serialize, PartialEq, EnumDiscriminants, Clone)]
#[serde(rename_all = "kebab-case")]
#[strum_discriminants(
name(AddressbookPropName),
derive(EnumString, VariantNames),
derive(EnumString, VariantNames, IntoStaticStr),
strum(serialize_all = "kebab-case")
)]
pub enum AddressbookProp {
@@ -61,12 +61,6 @@ pub enum AddressbookProp {
// Didn't find the spec
Getctag(String),
#[serde(other)]
#[xml(other)]
#[strum_discriminants(strum(disabled))]
#[default]
Invalid,
}
#[derive(Clone, Debug, From, Into)]
@@ -107,9 +101,6 @@ impl Resource for AddressbookResource {
}
AddressbookPropName::SyncToken => AddressbookProp::SyncToken(self.0.format_synctoken()),
AddressbookPropName::Getctag => AddressbookProp::Getctag(self.0.format_synctoken()),
AddressbookPropName::Invalid => {
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
}
})
}
@@ -129,7 +120,6 @@ impl Resource for AddressbookResource {
AddressbookProp::SupportedAddressData(_) => Err(rustical_dav::Error::PropReadOnly),
AddressbookProp::SyncToken(_) => Err(rustical_dav::Error::PropReadOnly),
AddressbookProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly),
AddressbookProp::Invalid => Err(rustical_dav::Error::PropReadOnly),
}
}
@@ -149,7 +139,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),
AddressbookPropName::Invalid => Err(rustical_dav::Error::PropReadOnly),
}
}

View File

@@ -12,7 +12,7 @@ use rustical_store::AddressbookStore;
use rustical_xml::XmlDeserialize;
use serde::Serialize;
use std::sync::Arc;
use strum::{EnumDiscriminants, EnumString, VariantNames};
use strum::{EnumDiscriminants, EnumString, IntoStaticStr, VariantNames};
pub struct PrincipalResourceService<A: AddressbookStore + ?Sized> {
principal: String,
@@ -24,10 +24,10 @@ pub struct PrincipalResource {
principal: String,
}
#[derive(Default, XmlDeserialize, Serialize, PartialEq, EnumDiscriminants)]
#[derive(XmlDeserialize, Serialize, PartialEq, EnumDiscriminants, Clone)]
#[strum_discriminants(
name(PrincipalPropName),
derive(EnumString, VariantNames),
derive(EnumString, VariantNames, IntoStaticStr),
strum(serialize_all = "kebab-case")
)]
#[serde(rename_all = "kebab-case")]
@@ -42,12 +42,6 @@ pub enum PrincipalProp {
AddressbookHomeSet(HrefElement),
#[serde(rename = "CARD:principal-address")]
PrincipalAddress(Option<HrefElement>),
#[serde(other)]
#[xml(other)]
#[strum_discriminants(strum(disabled))]
#[default]
Invalid,
}
impl PrincipalResource {
@@ -80,9 +74,6 @@ impl Resource for PrincipalResource {
PrincipalProp::AddressbookHomeSet(principal_href)
}
PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None),
PrincipalPropName::Invalid => {
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
}
})
}