Some preparations for supporting principal memberships

This commit is contained in:
Lennart
2025-02-02 11:34:10 +01:00
parent 93d16f02d9
commit 031d94c9d1
18 changed files with 54 additions and 27 deletions

View File

@@ -57,7 +57,7 @@ pub async fn route_mkcalendar<C: CalendarStore>(
root_span: RootSpan,
) -> Result<HttpResponse, Error> {
let (principal, cal_id) = path.into_inner();
if principal != user.id {
if !user.is_principal(&principal) {
return Err(Error::Unauthorized);
}

View File

@@ -23,7 +23,7 @@ pub async fn route_post<C: CalendarStore, S: SubscriptionStore>(
req: HttpRequest,
) -> Result<HttpResponse, Error> {
let (principal, cal_id) = path.into_inner();
if principal != user.id {
if !user.is_principal(&principal) {
return Err(Error::Unauthorized);
}

View File

@@ -34,7 +34,7 @@ pub async fn route_report_calendar<C: CalendarStore>(
cal_store: Data<C>,
) -> Result<impl Responder, Error> {
let (principal, cal_id) = path.into_inner();
if principal != user.id {
if !user.is_principal(&principal) {
return Err(Error::Unauthorized);
}

View File

@@ -300,10 +300,14 @@ impl Resource for CalendarResource {
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
if self.cal.subscription_url.is_some() || self.read_only {
return Ok(UserPrivilegeSet::owner_read(self.cal.principal == user.id));
return Ok(UserPrivilegeSet::owner_read(
user.is_principal(&self.cal.principal),
));
}
Ok(UserPrivilegeSet::owner_only(self.cal.principal == user.id))
Ok(UserPrivilegeSet::owner_only(
user.is_principal(&self.cal.principal),
))
}
}