mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 04:42:15 +00:00
outsource resourcetype to extension
This commit is contained in:
@@ -24,7 +24,7 @@ pub struct AddressObjectResourceService<AS: AddressbookStore + ?Sized> {
|
||||
pub object_id: String,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum AddressObjectPropName {
|
||||
Getetag,
|
||||
@@ -37,7 +37,7 @@ pub enum AddressObjectPropName {
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum AddressObjectProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -58,7 +58,7 @@ pub enum AddressObjectProp {
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
ExtCommonProperties(CommonPropertiesProp<AddressObjectResource>),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -76,10 +76,18 @@ pub struct AddressObjectResource {
|
||||
pub principal: String,
|
||||
}
|
||||
|
||||
// TODO: set correct resourcetype
|
||||
#[derive(Debug, Clone, Deserialize, Serialize, Default)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub struct Resourcetype {
|
||||
collection: (),
|
||||
}
|
||||
|
||||
impl Resource for AddressObjectResource {
|
||||
type PropName = AddressObjectPropName;
|
||||
type Prop = AddressObjectProp;
|
||||
type Error = Error;
|
||||
type ResourceType = Resourcetype;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
|
||||
@@ -31,10 +31,9 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
|
||||
pub addressbook_id: String,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum AddressbookPropName {
|
||||
Resourcetype,
|
||||
Displayname,
|
||||
Getcontenttype,
|
||||
Owner,
|
||||
@@ -49,11 +48,10 @@ pub enum AddressbookPropName {
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize, From, TryInto)]
|
||||
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum AddressbookProp {
|
||||
// WebDAV (RFC 2518)
|
||||
Resourcetype(Resourcetype),
|
||||
Displayname(Option<String>),
|
||||
Getcontenttype(String),
|
||||
|
||||
@@ -83,7 +81,7 @@ pub enum AddressbookProp {
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
ExtCommonProperties(CommonPropertiesProp<AddressbookResource>),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -102,6 +100,7 @@ impl Resource for AddressbookResource {
|
||||
type PropName = AddressbookPropName;
|
||||
type Prop = AddressbookProp;
|
||||
type Error = Error;
|
||||
type ResourceType = Resourcetype;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
@@ -116,9 +115,6 @@ impl Resource for AddressbookResource {
|
||||
prop: &Self::PropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
AddressbookPropName::Resourcetype => {
|
||||
AddressbookProp::Resourcetype(Resourcetype::default())
|
||||
}
|
||||
AddressbookPropName::Owner => AddressbookProp::Owner(
|
||||
PrincipalResource::get_principal_url(rmap, &self.0.principal).into(),
|
||||
),
|
||||
@@ -146,7 +142,6 @@ impl Resource for AddressbookResource {
|
||||
|
||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookProp::Resourcetype(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::Displayname(displayname) => {
|
||||
self.0.displayname = displayname;
|
||||
@@ -169,7 +164,6 @@ impl Resource for AddressbookResource {
|
||||
|
||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookPropName::Resourcetype => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Displayname => {
|
||||
self.0.displayname = None;
|
||||
|
||||
@@ -35,12 +35,9 @@ pub struct Resourcetype {
|
||||
collection: (),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PrincipalProp {
|
||||
// WebDAV (RFC 2518)
|
||||
Resourcetype(Resourcetype),
|
||||
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
#[serde(rename = "principal-URL")]
|
||||
PrincipalUrl(HrefElement),
|
||||
@@ -54,7 +51,7 @@ pub enum PrincipalProp {
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtRFC5397RFC3477(CommonPropertiesProp),
|
||||
ExtRFC5397RFC3477(CommonPropertiesProp<PrincipalResource>),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -66,10 +63,9 @@ impl InvalidProperty for PrincipalProp {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum PrincipalPropName {
|
||||
Resourcetype,
|
||||
#[strum(serialize = "principal-URL")]
|
||||
PrincipalUrl,
|
||||
AddressbookHomeSet,
|
||||
@@ -90,6 +86,7 @@ impl Resource for PrincipalResource {
|
||||
type PropName = PrincipalPropName;
|
||||
type Prop = PrincipalProp;
|
||||
type Error = Error;
|
||||
type ResourceType = Resourcetype;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
@@ -106,7 +103,6 @@ impl Resource for PrincipalResource {
|
||||
let principal_href = HrefElement::new(Self::get_principal_url(rmap, &self.principal));
|
||||
|
||||
Ok(match prop {
|
||||
PrincipalPropName::Resourcetype => PrincipalProp::Resourcetype(Resourcetype::default()),
|
||||
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
|
||||
PrincipalPropName::AddressbookHomeSet => {
|
||||
PrincipalProp::AddressbookHomeSet(principal_href)
|
||||
|
||||
@@ -14,10 +14,9 @@ use rustical_store::auth::User;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{EnumString, VariantNames};
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum RootPropName {
|
||||
Resourcetype,
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
@@ -30,16 +29,13 @@ pub struct Resourcetype {
|
||||
collection: (),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum RootProp {
|
||||
// WebDAV (RFC 2518)
|
||||
Resourcetype(Resourcetype),
|
||||
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
ExtCommonProperties(CommonPropertiesProp<RootResource>),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -58,6 +54,7 @@ impl Resource for RootResource {
|
||||
type PropName = RootPropName;
|
||||
type Prop = RootProp;
|
||||
type Error = Error;
|
||||
type ResourceType = Resourcetype;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
@@ -67,14 +64,11 @@ impl Resource for RootResource {
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
prop: &Self::PropName,
|
||||
_rmap: &ResourceMap,
|
||||
_user: &User,
|
||||
_prop: &Self::PropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
RootPropName::Resourcetype => RootProp::Resourcetype(Resourcetype::default()),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
panic!("we shouldn't end up here")
|
||||
}
|
||||
|
||||
#[inline]
|
||||
|
||||
Reference in New Issue
Block a user