mirror of
https://github.com/lennart-k/rustical.git
synced 2025-12-14 14:02:29 +00:00
Some preparations for supporting principal memberships
This commit is contained in:
@@ -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())
|
||||
}
|
||||
|
||||
@@ -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),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -48,7 +48,7 @@ pub async fn route_mkcol<AS: AddressbookStore>(
|
||||
root_span: RootSpan,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, addressbook_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ pub async fn route_post<A: AddressbookStore, S: SubscriptionStore>(
|
||||
req: HttpRequest,
|
||||
) -> Result<HttpResponse, Error> {
|
||||
let (principal, addressbook_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ pub async fn route_report_addressbook<AS: AddressbookStore>(
|
||||
addr_store: Data<AS>,
|
||||
) -> Result<impl Responder, Error> {
|
||||
let (principal, addressbook_id) = path.into_inner();
|
||||
if principal != user.id {
|
||||
if !user.is_principal(&principal) {
|
||||
return Err(Error::Unauthorized);
|
||||
}
|
||||
|
||||
|
||||
@@ -185,7 +185,9 @@ impl Resource for AddressbookResource {
|
||||
}
|
||||
|
||||
fn get_user_privileges(&self, user: &User) -> Result<UserPrivilegeSet, Self::Error> {
|
||||
Ok(UserPrivilegeSet::owner_only(self.0.principal == user.id))
|
||||
Ok(UserPrivilegeSet::owner_only(
|
||||
user.is_principal(&self.0.principal),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,9 @@ impl Resource for PrincipalResource {
|
||||
}
|
||||
|
||||
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),
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user