Browse Source

feat: implement `limitCollectionDeletion` checks

pull/7452/head
Raphaël Roumezin 1 day ago
parent
commit
2d4843e92d
  1. 9
      src/api/core/organizations.rs
  2. 3
      src/auth.rs

9
src/api/core/organizations.rs

@ -767,9 +767,18 @@ async fn delete_organization_collection_impl(
if org_id != &headers.org_id { if org_id != &headers.org_id {
err!("Organization not found", "Organization id's do not match"); err!("Organization not found", "Organization id's do not match");
} }
let Some(org_settings) = Organization::find_collection_settings_by_uuid(&org_id, &conn).await else {
err!("Can't find organization details")
};
let Some(collection) = Collection::find_by_uuid_and_org(col_id, org_id, conn).await else { let Some(collection) = Collection::find_by_uuid_and_org(col_id, org_id, conn).await else {
err!("Collection not found", "Collection does not exist or does not belong to this organization") err!("Collection not found", "Collection does not exist or does not belong to this organization")
}; };
if headers.membership_type <= MembershipType::Manager && org_settings.limit_collection_deletion {
err!("The current user isn't allowed to delete this collection")
}
log_event( log_event(
EventType::CollectionDeleted as i32, EventType::CollectionDeleted as i32,
&collection.uuid, &collection.uuid,

3
src/auth.rs

@ -868,6 +868,7 @@ pub struct ManagerHeaders {
pub host: String, pub host: String,
pub device: Device, pub device: Device,
pub user: User, pub user: User,
pub membership_type: MembershipType,
pub ip: ClientIp, pub ip: ClientIp,
pub org_id: OrganizationId, pub org_id: OrganizationId,
} }
@ -895,6 +896,7 @@ impl<'r> FromRequest<'r> for ManagerHeaders {
host: headers.host, host: headers.host,
device: headers.device, device: headers.device,
user: headers.user, user: headers.user,
membership_type: headers.membership_type,
ip: headers.ip, ip: headers.ip,
org_id: headers.membership.org_uuid, org_id: headers.membership.org_uuid,
}) })
@ -975,6 +977,7 @@ impl ManagerHeaders {
host: h.host, host: h.host,
device: h.device, device: h.device,
user: h.user, user: h.user,
membership_type: MembershipType::from_i32(h.membership.atype).unwrap(),
ip: h.ip, ip: h.ip,
org_id: h.membership.org_uuid, org_id: h.membership.org_uuid,
}) })

Loading…
Cancel
Save