Janky fix to make birthday calendar set read_only

This commit is contained in:
Lennart
2025-01-19 13:34:00 +01:00
parent 3b99508065
commit 6448b23f8c
3 changed files with 13 additions and 6 deletions

View File

@@ -15,6 +15,7 @@ use std::sync::Arc;
#[derive(Clone)]
pub struct CalendarSetResource {
pub(crate) principal: String,
pub(crate) read_only: bool,
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone, EnumVariants, EnumUnitVariants)]
@@ -53,7 +54,11 @@ impl Resource for CalendarSetResource {
}
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
Ok(UserPrivilegeSet::owner_only(self.principal == user.id))
Ok(if self.read_only {
UserPrivilegeSet::owner_read(self.principal == user.id)
} else {
UserPrivilegeSet::owner_only(self.principal == user.id)
})
}
}
@@ -80,6 +85,7 @@ impl<C: CalendarStore> ResourceService for CalendarSetResourceService<C> {
) -> Result<Self::Resource, Self::Error> {
Ok(CalendarSetResource {
principal: principal.to_owned(),
read_only: self.cal_store.is_read_only(),
})
}

View File

@@ -72,7 +72,7 @@ pub fn configure_dav<
web::scope("/user").service(
web::scope("/{principal}")
.service(PrincipalResourceService(&[
"calendar", "birthdays"
("calendar", false), ("birthdays", true)
]).actix_resource().name(PrincipalResource::route_name()))
.service(web::scope("/calendar")
.service(CalendarSetResourceService::new(store.clone()).actix_resource())

View File

@@ -12,7 +12,7 @@ use rustical_xml::{EnumUnitVariants, EnumVariants, XmlDeserialize, XmlSerialize}
#[derive(Clone)]
pub struct PrincipalResource {
principal: String,
home_set: &'static [&'static str],
home_set: &'static [(&'static str, bool)],
}
#[derive(XmlDeserialize, XmlSerialize, PartialEq, Clone)]
@@ -80,7 +80,7 @@ impl Resource for PrincipalResource {
let home_set = CalendarHomeSet(
self.home_set
.iter()
.map(|&home_name| format!("{}/{}", principal_url, home_name).into())
.map(|&(home_name, _read_only)| format!("{}/{}", principal_url, home_name).into())
.collect(),
);
@@ -117,7 +117,7 @@ impl Resource for PrincipalResource {
}
}
pub struct PrincipalResourceService(pub &'static [&'static str]);
pub struct PrincipalResourceService(pub &'static [(&'static str, bool)]);
#[async_trait(?Send)]
impl ResourceService for PrincipalResourceService {
@@ -143,11 +143,12 @@ impl ResourceService for PrincipalResourceService {
Ok(self
.0
.iter()
.map(|&set_name| {
.map(|&(set_name, read_only)| {
(
set_name.to_string(),
CalendarSetResource {
principal: principal.to_owned(),
read_only,
},
)
})