mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 08:12:24 +00:00
dav: Refactor proppatch, remove InvalidProperty trait
This commit is contained in:
@@ -24,7 +24,7 @@ use serde::Serialize;
|
||||
use sha2::{Digest, Sha256};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumDiscriminants, EnumString, VariantNames};
|
||||
use strum::{EnumDiscriminants, EnumString, IntoStaticStr, VariantNames};
|
||||
|
||||
pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
|
||||
cal_store: Arc<C>,
|
||||
@@ -32,10 +32,10 @@ pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
|
||||
calendar_id: String,
|
||||
}
|
||||
|
||||
#[derive(Default, XmlDeserialize, Serialize, PartialEq, EnumDiscriminants)]
|
||||
#[derive(XmlDeserialize, Serialize, PartialEq, EnumDiscriminants, Clone)]
|
||||
#[strum_discriminants(
|
||||
name(CalendarPropName),
|
||||
derive(EnumString, VariantNames),
|
||||
derive(EnumString, VariantNames, IntoStaticStr),
|
||||
strum(serialize_all = "kebab-case")
|
||||
)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@@ -90,11 +90,6 @@ pub enum CalendarProp {
|
||||
Getctag(String),
|
||||
#[serde(rename = "CS:source", alias = "source")]
|
||||
Source(Option<HrefElement>),
|
||||
|
||||
#[serde(other)]
|
||||
#[strum_discriminants(strum(disabled))]
|
||||
#[default]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, From, Into)]
|
||||
@@ -168,9 +163,6 @@ impl Resource for CalendarResource {
|
||||
CalendarPropName::Source => {
|
||||
CalendarProp::Source(self.0.subscription_url.to_owned().map(HrefElement::from))
|
||||
}
|
||||
CalendarPropName::Invalid => {
|
||||
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -209,7 +201,6 @@ impl Resource for CalendarResource {
|
||||
CalendarProp::Getctag(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
// Converting between a calendar subscription calendar and a normal one would be weird
|
||||
CalendarProp::Source(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
CalendarProp::Invalid => Err(rustical_dav::Error::PropReadOnly),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -248,7 +239,6 @@ impl Resource for CalendarResource {
|
||||
CalendarPropName::Getctag => Err(rustical_dav::Error::PropReadOnly),
|
||||
// Converting a calendar subscription calendar into a normal one would be weird
|
||||
CalendarPropName::Source => Err(rustical_dav::Error::PropReadOnly),
|
||||
CalendarPropName::Invalid => Err(rustical_dav::Error::PropReadOnly),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ use rustical_store::{auth::User, CalendarObject, CalendarStore};
|
||||
use rustical_xml::XmlDeserialize;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
use strum::{EnumDiscriminants, EnumString, VariantNames};
|
||||
use strum::{EnumDiscriminants, EnumString, IntoStaticStr, VariantNames};
|
||||
|
||||
pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
||||
cal_store: Arc<C>,
|
||||
@@ -20,10 +20,10 @@ pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
||||
object_id: String,
|
||||
}
|
||||
|
||||
#[derive(Default, XmlDeserialize, Serialize, PartialEq, EnumDiscriminants)]
|
||||
#[derive(XmlDeserialize, Serialize, PartialEq, EnumDiscriminants, Clone)]
|
||||
#[strum_discriminants(
|
||||
name(CalendarObjectPropName),
|
||||
derive(EnumString, VariantNames),
|
||||
derive(EnumString, VariantNames, IntoStaticStr),
|
||||
strum(serialize_all = "kebab-case")
|
||||
)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
@@ -35,12 +35,6 @@ pub enum CalendarObjectProp {
|
||||
// CalDAV (RFC 4791)
|
||||
#[serde(rename = "C:calendar-data")]
|
||||
CalendarData(String),
|
||||
|
||||
#[serde(other)]
|
||||
#[xml(other)]
|
||||
#[strum_discriminants(strum(disabled))]
|
||||
#[default]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
#[derive(Clone, From, Into)]
|
||||
@@ -73,14 +67,12 @@ impl Resource for CalendarObjectResource {
|
||||
CalendarObjectPropName::Getcontenttype => {
|
||||
CalendarObjectProp::Getcontenttype("text/calendar;charset=utf-8".to_owned())
|
||||
}
|
||||
CalendarObjectPropName::Invalid => {
|
||||
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn resource_name() -> &'static str {
|
||||
let a: CalendarObjectPropName = CalendarObjectProp::Getetag("".to_owned()).into();
|
||||
"caldav_calendar_object"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ use rustical_store::CalendarStore;
|
||||
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<C: CalendarStore + ?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 {
|
||||
CalendarHomeSet(HrefElement),
|
||||
#[serde(rename = "C:calendar-user-address-set")]
|
||||
CalendarUserAddressSet(HrefElement),
|
||||
|
||||
#[serde(other)]
|
||||
#[xml(other)]
|
||||
#[strum_discriminants(strum(disabled))]
|
||||
#[default]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
impl PrincipalResource {
|
||||
@@ -80,9 +74,6 @@ impl Resource for PrincipalResource {
|
||||
PrincipalPropName::CalendarUserAddressSet => {
|
||||
PrincipalProp::CalendarUserAddressSet(principal_href)
|
||||
}
|
||||
PrincipalPropName::Invalid => {
|
||||
return Err(rustical_dav::Error::BadRequest("invalid prop name".to_owned()).into())
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user