mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-13 22:52:22 +00:00
outsource owner property
This commit is contained in:
@@ -7,7 +7,6 @@ use rustical_dav::{
|
||||
extensions::{CommonPropertiesExtension, CommonPropertiesProp, CommonPropertiesPropName},
|
||||
privileges::UserPrivilegeSet,
|
||||
resource::{InvalidProperty, Resource, ResourceService},
|
||||
xml::HrefElement,
|
||||
};
|
||||
use rustical_store::{auth::User, AddressObject, AddressbookStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -30,7 +29,6 @@ pub enum AddressObjectPropName {
|
||||
Getetag,
|
||||
AddressData,
|
||||
Getcontenttype,
|
||||
Owner,
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
@@ -44,13 +42,6 @@ pub enum AddressObjectProp {
|
||||
Getetag(String),
|
||||
Getcontenttype(String),
|
||||
|
||||
// WebDAV Current Principal Extension (RFC 5397)
|
||||
CurrentUserPrincipal(HrefElement),
|
||||
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
Owner(HrefElement),
|
||||
CurrentUserPrivilegeSet(UserPrivilegeSet),
|
||||
|
||||
// CalDAV (RFC 4791)
|
||||
#[serde(rename = "CARD:address-data")]
|
||||
AddressData(String),
|
||||
@@ -109,9 +100,6 @@ impl Resource for AddressObjectResource {
|
||||
AddressObjectPropName::Getcontenttype => {
|
||||
AddressObjectProp::Getcontenttype("text/vcard;charset=utf-8".to_owned())
|
||||
}
|
||||
AddressObjectPropName::Owner => AddressObjectProp::Owner(
|
||||
PrincipalResource::get_principal_url(rmap, &self.principal).into(),
|
||||
),
|
||||
_ => panic!("we shouldn't end up here"),
|
||||
})
|
||||
}
|
||||
@@ -121,6 +109,10 @@ impl Resource for AddressObjectResource {
|
||||
"carddav_address_object"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Option<&str> {
|
||||
Some(&self.principal)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(self.principal == user.id))
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ use rustical_dav::extensions::{
|
||||
};
|
||||
use rustical_dav::privileges::UserPrivilegeSet;
|
||||
use rustical_dav::resource::{InvalidProperty, Resource, ResourceService};
|
||||
use rustical_dav::xml::HrefElement;
|
||||
use rustical_store::auth::User;
|
||||
use rustical_store::{Addressbook, AddressbookStore};
|
||||
use serde::{Deserialize, Serialize};
|
||||
@@ -36,7 +35,6 @@ pub struct AddressbookResourceService<AS: AddressbookStore + ?Sized> {
|
||||
pub enum AddressbookPropName {
|
||||
Displayname,
|
||||
Getcontenttype,
|
||||
Owner,
|
||||
AddressbookDescription,
|
||||
SupportedAddressData,
|
||||
SupportedReportSet,
|
||||
@@ -55,9 +53,6 @@ pub enum AddressbookProp {
|
||||
Displayname(Option<String>),
|
||||
Getcontenttype(String),
|
||||
|
||||
// WebDAV Access Control (RFC 3744)
|
||||
Owner(HrefElement),
|
||||
|
||||
// CardDAV (RFC 6352)
|
||||
#[serde(
|
||||
rename = "CARD:addressbook-description",
|
||||
@@ -110,14 +105,11 @@ impl Resource for AddressbookResource {
|
||||
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
_rmap: &ResourceMap,
|
||||
_user: &User,
|
||||
prop: &Self::PropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
Ok(match prop {
|
||||
AddressbookPropName::Owner => AddressbookProp::Owner(
|
||||
PrincipalResource::get_principal_url(rmap, &self.0.principal).into(),
|
||||
),
|
||||
AddressbookPropName::Displayname => {
|
||||
AddressbookProp::Displayname(self.0.displayname.clone())
|
||||
}
|
||||
@@ -142,7 +134,6 @@ impl Resource for AddressbookResource {
|
||||
|
||||
fn set_prop(&mut self, prop: Self::Prop) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookProp::Owner(_) => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookProp::Displayname(displayname) => {
|
||||
self.0.displayname = displayname;
|
||||
Ok(())
|
||||
@@ -164,7 +155,6 @@ impl Resource for AddressbookResource {
|
||||
|
||||
fn remove_prop(&mut self, prop: &Self::PropName) -> Result<(), rustical_dav::Error> {
|
||||
match prop {
|
||||
AddressbookPropName::Owner => Err(rustical_dav::Error::PropReadOnly),
|
||||
AddressbookPropName::Displayname => {
|
||||
self.0.displayname = None;
|
||||
Ok(())
|
||||
@@ -188,6 +178,10 @@ impl Resource for AddressbookResource {
|
||||
"carddav_addressbook"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Option<&str> {
|
||||
Some(&self.0.principal)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(self.0.principal == user.id))
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ pub enum PrincipalProp {
|
||||
#[serde(skip_deserializing, untagged)]
|
||||
#[from]
|
||||
#[try_into]
|
||||
ExtRFC5397RFC3477(CommonPropertiesProp<PrincipalResource>),
|
||||
ExtCommonProperties(CommonPropertiesProp<PrincipalResource>),
|
||||
|
||||
#[serde(untagged)]
|
||||
Invalid,
|
||||
@@ -73,7 +73,7 @@ pub enum PrincipalPropName {
|
||||
#[from]
|
||||
#[try_into]
|
||||
#[strum(disabled)]
|
||||
ExtRFC5397(CommonPropertiesPropName),
|
||||
ExtCommonProperties(CommonPropertiesPropName),
|
||||
}
|
||||
|
||||
impl PrincipalResource {
|
||||
@@ -97,7 +97,7 @@ impl Resource for PrincipalResource {
|
||||
fn get_prop(
|
||||
&self,
|
||||
rmap: &ResourceMap,
|
||||
user: &User,
|
||||
_user: &User,
|
||||
prop: &Self::PropName,
|
||||
) -> Result<Self::Prop, Self::Error> {
|
||||
let principal_href = HrefElement::new(Self::get_principal_url(rmap, &self.principal));
|
||||
@@ -117,6 +117,10 @@ impl Resource for PrincipalResource {
|
||||
"carddav_principal"
|
||||
}
|
||||
|
||||
fn get_owner(&self) -> Option<&str> {
|
||||
Some(&self.principal)
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(self.principal == user.id))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user