outsource owner property

This commit is contained in:
Lennart
2024-11-03 23:00:20 +01:00
parent f1997f2c18
commit f2d39e3351
8 changed files with 44 additions and 61 deletions

View File

@@ -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))
}