mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 17:52:24 +00:00
dav: Introduce resource extension for common properties
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
use crate::{principal::PrincipalResource, Error};
|
||||
use actix_web::{dev::ResourceMap, web::Data, HttpRequest};
|
||||
use async_trait::async_trait;
|
||||
use derive_more::derive::{From, Into};
|
||||
use derive_more::derive::{From, Into, TryInto};
|
||||
use rustical_dav::{
|
||||
extension::BoxedExtension,
|
||||
extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName},
|
||||
privileges::UserPrivilegeSet,
|
||||
resource::{InvalidProperty, Resource, ResourceService},
|
||||
xml::HrefElement,
|
||||
@@ -22,18 +24,20 @@ pub struct AddressObjectResourceService<AS: AddressbookStore + ?Sized> {
|
||||
pub object_id: String,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone)]
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum AddressObjectPropName {
|
||||
Getetag,
|
||||
AddressData,
|
||||
Getcontenttype,
|
||||
CurrentUserPrincipal,
|
||||
Owner,
|
||||
CurrentUserPrivilegeSet,
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug, Clone)]
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum AddressObjectProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -50,7 +54,13 @@ pub enum AddressObjectProp {
|
||||
// CalDAV (RFC 4791)
|
||||
#[serde(rename = "CARD:address-data")]
|
||||
AddressData(String),
|
||||
#[serde(other)]
|
||||
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
@@ -71,6 +81,12 @@ impl Resource for AddressObjectResource {
|
||||
type Prop = AddressObjectProp;
|
||||
type Error = Error;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
PrincipalResource,
|
||||
>::default())]
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
@@ -85,15 +101,10 @@ impl Resource for AddressObjectResource {
|
||||
AddressObjectPropName::Getcontenttype => {
|
||||
AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned())
|
||||
}
|
||||
AddressObjectPropName::CurrentUserPrincipal => AddressObjectProp::CurrentUserPrincipal(
|
||||
HrefElement::new(PrincipalResource::get_principal_url(rmap, &user.id)),
|
||||
),
|
||||
AddressObjectPropName::Owner => AddressObjectProp::Owner(
|
||||
PrincipalResource::get_principal_url(rmap, &self.principal).into(),
|
||||
),
|
||||
AddressObjectPropName::CurrentUserPrivilegeSet => {
|
||||
AddressObjectProp::CurrentUserPrivilegeSet(UserPrivilegeSet::all())
|
||||
}
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,11 @@ use actix_web::http::Method;
|
||||
use actix_web::web;
|
||||
use actix_web::{web::Data, HttpRequest};
|
||||
use async_trait::async_trait;
|
||||
use derive_more::derive::{From, Into};
|
||||
use derive_more::derive::{From, Into, TryInto};
|
||||
use rustical_dav::extension::BoxedExtension;
|
||||
use rustical_dav::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
|
||||
};
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
|
||||
use rustical_dav::xml::HrefElement;
|
||||
@@ -27,24 +31,25 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
|
||||
pub addressbook_id: String,
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone)]
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum AddressbookPropName {
|
||||
Resourcetype,
|
||||
Displayname,
|
||||
Getcontenttype,
|
||||
CurrentUserPrincipal,
|
||||
Owner,
|
||||
CurrentUserPrivilegeSet,
|
||||
AddressbookDescription,
|
||||
SupportedAddressData,
|
||||
SupportedReportSet,
|
||||
MaxResourceSize,
|
||||
SyncToken,
|
||||
Getctag,
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Deserialize, Serialize)]
|
||||
#[derive(Debug, Deserialize, Serialize, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum AddressbookProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -52,12 +57,8 @@ pub enum AddressbookProp {
|
||||
Displayname(Option<String>),
|
||||
Getcontenttype(String),
|
||||
|
||||
// WebDAV Current Principal Extension (RFC 5397)
|
||||
CurrentUserPrincipal(HrefElement),
|
||||
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
Owner(HrefElement),
|
||||
CurrentUserPrivilegeSet(UserPrivilegeSet),
|
||||
|
||||
// CardDAV (RFC 6352)
|
||||
#[serde(
|
||||
@@ -79,7 +80,12 @@ pub enum AddressbookProp {
|
||||
// Didn't find the spec
|
||||
Getctag(String),
|
||||
|
||||
#[serde(other)]
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
@@ -97,6 +103,12 @@ impl Resource for AddressbookResource {
|
||||
type Prop = AddressbookProp;
|
||||
type Error = Error;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
PrincipalResource,
|
||||
>::default())]
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
@@ -107,17 +119,9 @@ impl Resource for AddressbookResource {
|
||||
AddressbookPropName::Resourcetype => {
|
||||
AddressbookProp::Resourcetype(Resourcetype::default())
|
||||
}
|
||||
AddressbookPropName::CurrentUserPrincipal => {
|
||||
AddressbookProp::CurrentUserPrincipal(HrefElement::new(
|
||||
PrincipalResource::get_principal_url(rmap, &self.0.principal),
|
||||
))
|
||||
}
|
||||
AddressbookPropName::Owner => AddressbookProp::Owner(
|
||||
PrincipalResource::get_principal_url(rmap, &self.0.principal).into(),
|
||||
),
|
||||
AddressbookPropName::CurrentUserPrivilegeSet => {
|
||||
AddressbookProp::CurrentUserPrivilegeSet(UserPrivilegeSet::all())
|
||||
}
|
||||
AddressbookPropName::Displayname => {
|
||||
AddressbookProp::Displayname(self.0.displayname.clone())
|
||||
}
|
||||
@@ -136,13 +140,13 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
AddressbookPropName::SyncToken => AddressbookProp::SyncToken(self.0.format_synctoken()),
|
||||
AddressbookPropName::Getctag => AddressbookProp::Getctag(self.0.format_synctoken()),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
}
|
||||
|
||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookProp::Resourcetype(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::CurrentUserPrincipal(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::Displayname(displayname) => {
|
||||
self.0.displayname = displayname;
|
||||
@@ -154,19 +158,18 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
AddressbookProp::Getcontenttype(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::MaxResourceSize(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::CurrentUserPrivilegeSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::SupportedReportSet(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
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),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
}
|
||||
}
|
||||
|
||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookPropName::Resourcetype => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::CurrentUserPrincipal => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Displayname => {
|
||||
self.0.displayname = None;
|
||||
@@ -178,11 +181,11 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
AddressbookPropName::Getcontenttype => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::MaxResourceSize => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::CurrentUserPrivilegeSet => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::SupportedReportSet => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::SupportedAddressData => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::SyncToken => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Getctag => Err(rustical_dav::Error::PropReadOnly),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,11 @@ use actix_web::dev::ResourceMap;
|
||||
use actix_web::web::Data;
|
||||
use actix_web::HttpRequest;
|
||||
use async_trait::async_trait;
|
||||
use derive_more::derive::{From, TryInto};
|
||||
use rustical_dav::extension::BoxedExtension;
|
||||
use rustical_dav::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
|
||||
};
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
|
||||
use rustical_dav::xml::HrefElement;
|
||||
@@ -18,7 +23,7 @@ pub struct PrincipalResourceService<A: AddressbookStore + ?Sized> {
|
||||
addr_store: Arc<A>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct PrincipalResource {
|
||||
principal: String,
|
||||
}
|
||||
@@ -30,7 +35,7 @@ pub struct Resourcetype {
|
||||
collection: (),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum PrincipalProp {
|
||||
// WebDAV (RFC 2518)
|
||||
@@ -40,15 +45,18 @@ pub enum PrincipalProp {
|
||||
#[serde(rename = "principal-URL")]
|
||||
PrincipalUrl(HrefElement),
|
||||
|
||||
// WebDAV Current Principal Extension (RFC 5397)
|
||||
CurrentUserPrincipal(HrefElement),
|
||||
|
||||
// CardDAV (RFC 6352)
|
||||
#[serde(rename = "CARD:addressbook-home-set")]
|
||||
AddressbookHomeSet(HrefElement),
|
||||
#[serde(rename = "CARD:principal-address")]
|
||||
PrincipalAddress(Option<HrefElement>),
|
||||
#[serde(other)]
|
||||
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtRFC5397RFC3477(CommonPropertiesProp),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
}
|
||||
|
||||
@@ -58,15 +66,18 @@ impl InvalidProperty for PrincipalProp {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone)]
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum PrincipalPropName {
|
||||
Resourcetype,
|
||||
CurrentUserPrincipal,
|
||||
#[strum(serialize = "principal-URL")]
|
||||
PrincipalUrl,
|
||||
AddressbookHomeSet,
|
||||
PrincipalAddress,
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
ExtRFC5397(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
impl PrincipalResource {
|
||||
@@ -80,6 +91,12 @@ impl Resource for PrincipalResource {
|
||||
type Prop = PrincipalProp;
|
||||
type Error = Error;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
PrincipalResource,
|
||||
>::default())]
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
@@ -90,14 +107,12 @@ impl Resource for PrincipalResource {
|
||||
|
||||
Ok(match prop {
|
||||
PrincipalPropName::Resourcetype => PrincipalProp::Resourcetype(Resourcetype::default()),
|
||||
PrincipalPropName::CurrentUserPrincipal => {
|
||||
PrincipalProp::CurrentUserPrincipal(principal_href)
|
||||
}
|
||||
PrincipalPropName::PrincipalUrl => PrincipalProp::PrincipalUrl(principal_href),
|
||||
PrincipalPropName::AddressbookHomeSet => {
|
||||
PrincipalProp::AddressbookHomeSet(principal_href)
|
||||
}
|
||||
PrincipalPropName::PrincipalAddress => PrincipalProp::PrincipalAddress(None),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@@ -3,19 +3,25 @@ use crate::Error;
|
||||
use actix_web::dev::ResourceMap;
|
||||
use actix_web::HttpRequest;
|
||||
use async_trait::async_trait;
|
||||
use derive_more::{From, TryInto};
|
||||
use rustical_dav::extension::BoxedExtension;
|
||||
use rustical_dav::extensions::{
|
||||
CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName,
|
||||
};
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
|
||||
use rustical_dav::xml::HrefElement;
|
||||
use rustical_store::auth::User;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use strum::{EnumString, VariantNames};
|
||||
|
||||
#[derive(EnumString, Debug, VariantNames, Clone)]
|
||||
#[derive(EnumString, Debug, VariantNames, Clone, From, TryInto)]
|
||||
#[strum(serialize_all = "kebab-case")]
|
||||
pub enum RootPropName {
|
||||
Resourcetype,
|
||||
CurrentUserPrincipal,
|
||||
CurrentUserPrivilegeSet,
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Default, Debug)]
|
||||
@@ -24,17 +30,16 @@ pub struct Resourcetype {
|
||||
collection: (),
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize, Debug)]
|
||||
#[derive(Deserialize, Serialize, Debug, From, TryInto)]
|
||||
#[serde(rename_all = "kebab-case")]
|
||||
pub enum RootProp {
|
||||
// WebDAV (RFC 2518)
|
||||
Resourcetype(Resourcetype),
|
||||
|
||||
// WebDAV Current Principal Extension (RFC 5397)
|
||||
CurrentUserPrincipal(HrefElement),
|
||||
|
||||
// WebDAV Access Control Protocol (RFC 3477)
|
||||
CurrentUserPrivilegeSet(UserPrivilegeSet),
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtCommonProperties(CommonPropertiesProp),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -54,6 +59,12 @@ impl Resource for RootResource {
|
||||
type Prop = RootProp;
|
||||
type Error = Error;
|
||||
|
||||
fn list_extensions() -> Vec<BoxedExtension<Self>> {
|
||||
vec![BoxedExtension::from_ext(CommonPropertiesExtension::<
|
||||
PrincipalResource,
|
||||
>::default())]
|
||||
}
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
@@ -62,12 +73,7 @@ impl Resource for RootResource {
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
RootPropName::Resourcetype => RootProp::Resourcetype(Resourcetype::default()),
|
||||
RootPropName::CurrentUserPrincipal => RootProp::CurrentUserPrincipal(
|
||||
PrincipalResource::get_principal_url(rmap, &user.id).into(),
|
||||
),
|
||||
RootPropName::CurrentUserPrivilegeSet => {
|
||||
RootProp::CurrentUserPrivilegeSet(self.get_user_privileges(user)?)
|
||||
}
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user