mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 12:52:27 +00:00
outsource resourcetype to extension
This commit is contained in:
@@ -34,10 +34,9 @@ pub struct CalendarResourceService<C: CalendarStore + ?Sized> {
|
|||||||
pub calendar_id: String,
|
pub calendar_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum CalendarPropName {
|
pub enum CalendarPropName {
|
||||||
Resourcetype,
|
|
||||||
Owner,
|
Owner,
|
||||||
Displayname,
|
Displayname,
|
||||||
CalendarColor,
|
CalendarColor,
|
||||||
@@ -57,11 +56,10 @@ pub enum CalendarPropName {
|
|||||||
ExtCommonProperties(CommonPropertiesPropName),
|
ExtCommonProperties(CommonPropertiesPropName),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum CalendarProp {
|
pub enum CalendarProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
Resourcetype(Resourcetype),
|
|
||||||
Displayname(Option<String>),
|
Displayname(Option<String>),
|
||||||
Getcontenttype(String),
|
Getcontenttype(String),
|
||||||
|
|
||||||
@@ -99,7 +97,7 @@ pub enum CalendarProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<CalendarResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -118,6 +116,7 @@ impl Resource for CalendarResource {
|
|||||||
type PropName = CalendarPropName;
|
type PropName = CalendarPropName;
|
||||||
type Prop = CalendarProp;
|
type Prop = CalendarProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
@@ -132,7 +131,6 @@ impl Resource for CalendarResource {
|
|||||||
prop: &Self::PropName,
|
prop: &Self::PropName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
CalendarPropName::Resourcetype => CalendarProp::Resourcetype(Resourcetype::default()),
|
|
||||||
CalendarPropName::Owner => CalendarProp::Owner(HrefElement::new(
|
CalendarPropName::Owner => CalendarProp::Owner(HrefElement::new(
|
||||||
PrincipalResource::get_url(rmap, vec![&self.0.principal]).unwrap(),
|
PrincipalResource::get_url(rmap, vec![&self.0.principal]).unwrap(),
|
||||||
)),
|
)),
|
||||||
@@ -181,7 +179,6 @@ impl Resource for CalendarResource {
|
|||||||
|
|
||||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||||
match prop {
|
match prop {
|
||||||
CalendarProp::Resourcetype(_) => Err(rustical_dav::Error::PropReadOnly),
|
|
||||||
CalendarProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
CalendarProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
CalendarProp::Displayname(displayname) => {
|
CalendarProp::Displayname(displayname) => {
|
||||||
self.0.displayname = displayname;
|
self.0.displayname = displayname;
|
||||||
@@ -220,7 +217,6 @@ impl Resource for CalendarResource {
|
|||||||
|
|
||||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||||
match prop {
|
match prop {
|
||||||
CalendarPropName::Resourcetype => Err(rustical_dav::Error::PropReadOnly),
|
|
||||||
CalendarPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
CalendarPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
||||||
CalendarPropName::Displayname => {
|
CalendarPropName::Displayname => {
|
||||||
self.0.displayname = None;
|
self.0.displayname = None;
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ pub struct CalendarObjectResourceService<C: CalendarStore + ?Sized> {
|
|||||||
pub object_id: String,
|
pub object_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum CalendarObjectPropName {
|
pub enum CalendarObjectPropName {
|
||||||
Getetag,
|
Getetag,
|
||||||
@@ -36,7 +36,7 @@ pub enum CalendarObjectPropName {
|
|||||||
ExtCommonProperties(CommonPropertiesPropName),
|
ExtCommonProperties(CommonPropertiesPropName),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum CalendarObjectProp {
|
pub enum CalendarObjectProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -53,7 +53,7 @@ pub enum CalendarObjectProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<CalendarObjectResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -71,10 +71,18 @@ pub struct CalendarObjectResource {
|
|||||||
pub principal: String,
|
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 CalendarObjectResource {
|
impl Resource for CalendarObjectResource {
|
||||||
type PropName = CalendarObjectPropName;
|
type PropName = CalendarObjectPropName;
|
||||||
type Prop = CalendarObjectProp;
|
type Prop = CalendarObjectProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
@@ -85,7 +93,7 @@ impl Resource for CalendarObjectResource {
|
|||||||
fn get_prop(
|
fn get_prop(
|
||||||
&self,
|
&self,
|
||||||
rmap: &ResourceMap,
|
rmap: &ResourceMap,
|
||||||
user: &User,
|
_user: &User,
|
||||||
prop: &Self::PropName,
|
prop: &Self::PropName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ pub struct Resourcetype {
|
|||||||
collection: (),
|
collection: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum PrincipalProp {
|
pub enum PrincipalProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -57,7 +57,7 @@ pub enum PrincipalProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<PrincipalResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -69,7 +69,7 @@ impl InvalidProperty for PrincipalProp {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum PrincipalPropName {
|
pub enum PrincipalPropName {
|
||||||
Resourcetype,
|
Resourcetype,
|
||||||
@@ -94,6 +94,7 @@ impl Resource for PrincipalResource {
|
|||||||
type PropName = PrincipalPropName;
|
type PropName = PrincipalPropName;
|
||||||
type Prop = PrincipalProp;
|
type Prop = PrincipalProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ use rustical_store::auth::User;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum RootPropName {
|
pub enum RootPropName {
|
||||||
Resourcetype,
|
Resourcetype,
|
||||||
@@ -30,7 +30,7 @@ pub struct Resourcetype {
|
|||||||
collection: (),
|
collection: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum RootProp {
|
pub enum RootProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -39,7 +39,7 @@ pub enum RootProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<RootResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -58,6 +58,7 @@ impl Resource for RootResource {
|
|||||||
type PropName = RootPropName;
|
type PropName = RootPropName;
|
||||||
type Prop = RootProp;
|
type Prop = RootProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ pub struct AddressObjectResourceService<AS: AddressbookStore + ?Sized> {
|
|||||||
pub object_id: String,
|
pub object_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum AddressObjectPropName {
|
pub enum AddressObjectPropName {
|
||||||
Getetag,
|
Getetag,
|
||||||
@@ -37,7 +37,7 @@ pub enum AddressObjectPropName {
|
|||||||
ExtCommonProperties(CommonPropertiesPropName),
|
ExtCommonProperties(CommonPropertiesPropName),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum AddressObjectProp {
|
pub enum AddressObjectProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
@@ -58,7 +58,7 @@ pub enum AddressObjectProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<AddressObjectResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -76,10 +76,18 @@ pub struct AddressObjectResource {
|
|||||||
pub principal: String,
|
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 {
|
impl Resource for AddressObjectResource {
|
||||||
type PropName = AddressObjectPropName;
|
type PropName = AddressObjectPropName;
|
||||||
type Prop = AddressObjectProp;
|
type Prop = AddressObjectProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
|
|||||||
@@ -31,10 +31,9 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
|
|||||||
pub addressbook_id: String,
|
pub addressbook_id: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum AddressbookPropName {
|
pub enum AddressbookPropName {
|
||||||
Resourcetype,
|
|
||||||
Displayname,
|
Displayname,
|
||||||
Getcontenttype,
|
Getcontenttype,
|
||||||
Owner,
|
Owner,
|
||||||
@@ -49,11 +48,10 @@ pub enum AddressbookPropName {
|
|||||||
ExtCommonProperties(CommonPropertiesPropName),
|
ExtCommonProperties(CommonPropertiesPropName),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Deserialize, Serialize, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum AddressbookProp {
|
pub enum AddressbookProp {
|
||||||
// WebDAV (RFC 2518)
|
// WebDAV (RFC 2518)
|
||||||
Resourcetype(Resourcetype),
|
|
||||||
Displayname(Option<String>),
|
Displayname(Option<String>),
|
||||||
Getcontenttype(String),
|
Getcontenttype(String),
|
||||||
|
|
||||||
@@ -83,7 +81,7 @@ pub enum AddressbookProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<AddressbookResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -102,6 +100,7 @@ impl Resource for AddressbookResource {
|
|||||||
type PropName = AddressbookPropName;
|
type PropName = AddressbookPropName;
|
||||||
type Prop = AddressbookProp;
|
type Prop = AddressbookProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
@@ -116,9 +115,6 @@ impl Resource for AddressbookResource {
|
|||||||
prop: &Self::PropName,
|
prop: &Self::PropName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
AddressbookPropName::Resourcetype => {
|
|
||||||
AddressbookProp::Resourcetype(Resourcetype::default())
|
|
||||||
}
|
|
||||||
AddressbookPropName::Owner => AddressbookProp::Owner(
|
AddressbookPropName::Owner => AddressbookProp::Owner(
|
||||||
PrincipalResource::get_principal_url(rmap, &self.0.principal).into(),
|
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> {
|
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||||
match prop {
|
match prop {
|
||||||
AddressbookProp::Resourcetype(_) => Err(rustical_dav::Error::PropReadOnly),
|
|
||||||
AddressbookProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
AddressbookProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||||
AddressbookProp::Displayname(displayname) => {
|
AddressbookProp::Displayname(displayname) => {
|
||||||
self.0.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> {
|
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||||
match prop {
|
match prop {
|
||||||
AddressbookPropName::Resourcetype => Err(rustical_dav::Error::PropReadOnly),
|
|
||||||
AddressbookPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
AddressbookPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
||||||
AddressbookPropName::Displayname => {
|
AddressbookPropName::Displayname => {
|
||||||
self.0.displayname = None;
|
self.0.displayname = None;
|
||||||
|
|||||||
@@ -35,12 +35,9 @@ pub struct Resourcetype {
|
|||||||
collection: (),
|
collection: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum PrincipalProp {
|
pub enum PrincipalProp {
|
||||||
// WebDAV (RFC 2518)
|
|
||||||
Resourcetype(Resourcetype),
|
|
||||||
|
|
||||||
// WebDAV Access Control (RFC 3744)
|
// WebDAV Access Control (RFC 3744)
|
||||||
#[serde(rename = "principal-URL")]
|
#[serde(rename = "principal-URL")]
|
||||||
PrincipalUrl(HrefElement),
|
PrincipalUrl(HrefElement),
|
||||||
@@ -54,7 +51,7 @@ pub enum PrincipalProp {
|
|||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtRFC5397RFC3477(CommonPropertiesProp),
|
ExtRFC5397RFC3477(CommonPropertiesProp<PrincipalResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
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")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum PrincipalPropName {
|
pub enum PrincipalPropName {
|
||||||
Resourcetype,
|
|
||||||
#[strum(serialize = "principal-URL")]
|
#[strum(serialize = "principal-URL")]
|
||||||
PrincipalUrl,
|
PrincipalUrl,
|
||||||
AddressbookHomeSet,
|
AddressbookHomeSet,
|
||||||
@@ -90,6 +86,7 @@ impl Resource for PrincipalResource {
|
|||||||
type PropName = PrincipalPropName;
|
type PropName = PrincipalPropName;
|
||||||
type Prop = PrincipalProp;
|
type Prop = PrincipalProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
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));
|
let principal_href = HrefElement::new(Self::get_principal_url(rmap, &self.principal));
|
||||||
|
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
PrincipalPropName::Resourcetype => PrincipalProp::Resourcetype(Resourcetype::default()),
|
|
||||||
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
|
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
|
||||||
PrincipalPropName::AddressbookHomeSet => {
|
PrincipalPropName::AddressbookHomeSet => {
|
||||||
PrincipalProp::AddressbookHomeSet(principal_href)
|
PrincipalProp::AddressbookHomeSet(principal_href)
|
||||||
|
|||||||
@@ -14,10 +14,9 @@ use rustical_store::auth::User;
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use strum::{EnumString, VariantNames};
|
use strum::{EnumString, VariantNames};
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
#[derive(EnumString, VariantNames, Clone, From, TryInto)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum RootPropName {
|
pub enum RootPropName {
|
||||||
Resourcetype,
|
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
#[strum(disabled)]
|
#[strum(disabled)]
|
||||||
@@ -30,16 +29,13 @@ pub struct Resourcetype {
|
|||||||
collection: (),
|
collection: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
#[derive(Deserialize, Serialize, From, TryInto)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum RootProp {
|
pub enum RootProp {
|
||||||
// WebDAV (RFC 2518)
|
|
||||||
Resourcetype(Resourcetype),
|
|
||||||
|
|
||||||
#[serde(skip_deserializing, untagged)]
|
#[serde(skip_deserializing, untagged)]
|
||||||
#[from]
|
#[from]
|
||||||
#[try_into]
|
#[try_into]
|
||||||
ExtCommonProperties(CommonPropertiesProp),
|
ExtCommonProperties(CommonPropertiesProp<RootResource>),
|
||||||
|
|
||||||
#[serde(untagged)]
|
#[serde(untagged)]
|
||||||
Invalid,
|
Invalid,
|
||||||
@@ -58,6 +54,7 @@ impl Resource for RootResource {
|
|||||||
type PropName = RootPropName;
|
type PropName = RootPropName;
|
||||||
type Prop = RootProp;
|
type Prop = RootProp;
|
||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
type ResourceType = Resourcetype;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||||
@@ -67,14 +64,11 @@ impl Resource for RootResource {
|
|||||||
|
|
||||||
fn get_prop(
|
fn get_prop(
|
||||||
&self,
|
&self,
|
||||||
rmap: &ResourceMap,
|
_rmap: &ResourceMap,
|
||||||
user: &User,
|
_user: &User,
|
||||||
prop: &Self::PropName,
|
_prop: &Self::PropName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
Ok(match prop {
|
panic!("we shouldn't end up here")
|
||||||
RootPropName::Resourcetype => RootProp::Resourcetype(Resourcetype::default()),
|
|
||||||
_ => panic!("we shouldn't end up here"),
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
use std::marker::PhantomData;
|
|
||||||
|
|
||||||
use actix_web::dev::ResourceMap;
|
|
||||||
use rustical_store::auth::User;
|
|
||||||
use serde::{Deserialize, Serialize};
|
|
||||||
use strum::{EnumString, VariantNames};
|
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
extension::ResourceExtension,
|
extension::ResourceExtension,
|
||||||
privileges::UserPrivilegeSet,
|
privileges::UserPrivilegeSet,
|
||||||
resource::{InvalidProperty, Resource},
|
resource::{InvalidProperty, Resource},
|
||||||
xml::HrefElement,
|
xml::HrefElement,
|
||||||
};
|
};
|
||||||
|
use actix_web::dev::ResourceMap;
|
||||||
|
use rustical_store::auth::User;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::marker::PhantomData;
|
||||||
|
use strum::{EnumString, VariantNames};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Clone)]
|
||||||
pub struct CommonPropertiesExtension<PR: Resource>(PhantomData<PR>);
|
pub struct CommonPropertiesExtension<PR: Resource>(PhantomData<PR>);
|
||||||
|
|
||||||
impl<PR: Resource> Default for CommonPropertiesExtension<PR> {
|
impl<PR: Resource> Default for CommonPropertiesExtension<PR> {
|
||||||
@@ -21,9 +19,12 @@ impl<PR: Resource> Default for CommonPropertiesExtension<PR> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug)]
|
#[derive(Deserialize, Serialize)]
|
||||||
#[serde(rename_all = "kebab-case")]
|
#[serde(rename_all = "kebab-case")]
|
||||||
pub enum CommonPropertiesProp {
|
pub enum CommonPropertiesProp<R: Resource> {
|
||||||
|
// WebDAV (RFC 2518)
|
||||||
|
Resourcetype(R::ResourceType),
|
||||||
|
|
||||||
// WebDAV Current Principal Extension (RFC 5397)
|
// WebDAV Current Principal Extension (RFC 5397)
|
||||||
CurrentUserPrincipal(HrefElement),
|
CurrentUserPrincipal(HrefElement),
|
||||||
|
|
||||||
@@ -34,15 +35,16 @@ pub enum CommonPropertiesProp {
|
|||||||
Invalid,
|
Invalid,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InvalidProperty for CommonPropertiesProp {
|
impl<R: Resource> InvalidProperty for CommonPropertiesProp<R> {
|
||||||
fn invalid_property(&self) -> bool {
|
fn invalid_property(&self) -> bool {
|
||||||
matches!(self, Self::Invalid)
|
matches!(self, Self::Invalid)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(EnumString, Debug, VariantNames, Clone)]
|
#[derive(EnumString, VariantNames, Clone)]
|
||||||
#[strum(serialize_all = "kebab-case")]
|
#[strum(serialize_all = "kebab-case")]
|
||||||
pub enum CommonPropertiesPropName {
|
pub enum CommonPropertiesPropName {
|
||||||
|
Resourcetype,
|
||||||
CurrentUserPrincipal,
|
CurrentUserPrincipal,
|
||||||
CurrentUserPrivilegeSet,
|
CurrentUserPrivilegeSet,
|
||||||
}
|
}
|
||||||
@@ -50,9 +52,9 @@ pub enum CommonPropertiesPropName {
|
|||||||
impl<R: Resource, PR: Resource> ResourceExtension<R> for CommonPropertiesExtension<PR>
|
impl<R: Resource, PR: Resource> ResourceExtension<R> for CommonPropertiesExtension<PR>
|
||||||
where
|
where
|
||||||
R::PropName: TryInto<CommonPropertiesPropName>,
|
R::PropName: TryInto<CommonPropertiesPropName>,
|
||||||
R::Prop: From<CommonPropertiesProp>,
|
R::Prop: From<CommonPropertiesProp<R>>,
|
||||||
{
|
{
|
||||||
type Prop = CommonPropertiesProp;
|
type Prop = CommonPropertiesProp<R>;
|
||||||
type PropName = CommonPropertiesPropName;
|
type PropName = CommonPropertiesPropName;
|
||||||
type Error = R::Error;
|
type Error = R::Error;
|
||||||
|
|
||||||
@@ -64,6 +66,9 @@ where
|
|||||||
prop: Self::PropName,
|
prop: Self::PropName,
|
||||||
) -> Result<Self::Prop, Self::Error> {
|
) -> Result<Self::Prop, Self::Error> {
|
||||||
Ok(match prop {
|
Ok(match prop {
|
||||||
|
CommonPropertiesPropName::Resourcetype => {
|
||||||
|
CommonPropertiesProp::Resourcetype(R::ResourceType::default())
|
||||||
|
}
|
||||||
CommonPropertiesPropName::CurrentUserPrincipal => {
|
CommonPropertiesPropName::CurrentUserPrincipal => {
|
||||||
CommonPropertiesProp::CurrentUserPrincipal(
|
CommonPropertiesProp::CurrentUserPrincipal(
|
||||||
PR::get_url(rmap, &[&user.id]).unwrap().into(),
|
PR::get_url(rmap, &[&user.id]).unwrap().into(),
|
||||||
|
|||||||
@@ -11,15 +11,14 @@ use actix_web::test::TestRequest;
|
|||||||
use actix_web::web;
|
use actix_web::web;
|
||||||
use actix_web::{http::StatusCode, HttpRequest, ResponseError};
|
use actix_web::{http::StatusCode, HttpRequest, ResponseError};
|
||||||
use async_trait::async_trait;
|
use async_trait::async_trait;
|
||||||
use core::fmt;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use rustical_store::auth::User;
|
use rustical_store::auth::User;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use strum::VariantNames;
|
use strum::VariantNames;
|
||||||
|
|
||||||
pub trait ResourceReadProp: Serialize + fmt::Debug + InvalidProperty {}
|
pub trait ResourceReadProp: Serialize + InvalidProperty {}
|
||||||
impl<T: Serialize + fmt::Debug + InvalidProperty> ResourceReadProp for T {}
|
impl<T: Serialize + InvalidProperty> ResourceReadProp for T {}
|
||||||
|
|
||||||
pub trait ResourceProp: ResourceReadProp + for<'de> Deserialize<'de> {}
|
pub trait ResourceProp: ResourceReadProp + for<'de> Deserialize<'de> {}
|
||||||
impl<T: ResourceReadProp + for<'de> Deserialize<'de>> ResourceProp for T {}
|
impl<T: ResourceReadProp + for<'de> Deserialize<'de>> ResourceProp for T {}
|
||||||
@@ -31,6 +30,7 @@ pub trait Resource: Clone {
|
|||||||
type PropName: ResourcePropName;
|
type PropName: ResourcePropName;
|
||||||
type Prop: ResourceProp;
|
type Prop: ResourceProp;
|
||||||
type Error: ResponseError + From<crate::Error>;
|
type Error: ResponseError + From<crate::Error>;
|
||||||
|
type ResourceType: Default + Serialize + for<'de> Deserialize<'de>;
|
||||||
|
|
||||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||||
vec![]
|
vec![]
|
||||||
|
|||||||
Reference in New Issue
Block a user