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

@@ -26,8 +26,8 @@ pub async fn get_object<AS: AddressbookStore>(
object_id,
} = path.into_inner();
if user.id != principal {
return Ok(HttpResponse::Unauthorized().body(""));
if !user.is_principal(&principal) {
return Err(Error::Unauthorized);
}
let addressbook = store.get_addressbook(&principal, &addressbook_id).await?;
@@ -64,8 +64,8 @@ pub async fn put_object<AS: AddressbookStore>(
object_id,
} = path.into_inner();
if user.id != principal {
return Ok(HttpResponse::Unauthorized().body(""));
if !user.is_principal(&principal) {
return Err(Error::Unauthorized);
}
// TODO: implement If-Match
@@ -79,5 +79,5 @@ pub async fn put_object<AS: AddressbookStore>(
.put_object(principal, addressbook_id, object, overwrite)
.await?;
Ok(HttpResponse::Created().body(""))
Ok(HttpResponse::Created().finish())
}

View File

@@ -87,7 +87,9 @@ impl Resource for AddressObjectResource {
}
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
Ok(UserPrivilegeSet::owner_only(self.principal == user.id))
Ok(UserPrivilegeSet::owner_only(
user.is_principal(&self.principal),
))
}
}