Skip to content

Commit 9472ac5

Browse files
committed
Enhance project ACL handling and add tests for permission deletion on new projects
1 parent b5d71b4 commit 9472ac5

File tree

4 files changed

+51
-3
lines changed

4 files changed

+51
-3
lines changed

synapseclient/models/mixins/access_control.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ async def delete_permissions_async(
235235
determined by its own ACL.
236236
237237
If the ACL of an Entity is deleted, then its benefactor will automatically be set
238-
to its parent's benefactor. The ACL for a Project cannot be deleted.
238+
to its parent's benefactor.
239+
240+
**Special notice for Projects:** The ACL for a Project cannot be deleted, you
241+
must individually update or revoke the permissions for each user or group.
239242
240243
Arguments:
241244
include_self: If True (default), delete the ACL of the current entity.
@@ -411,6 +414,9 @@ async def _delete_current_entity_acl(
411414
Exception: For any other errors that may occur during deletion.
412415
"""
413416
if not entity_info["is_target_type"] and entity_info["entity_type"] is not None:
417+
client.logger.debug(
418+
f"Skipping ACL deletion for entity {self.id} as its type '{entity_info['entity_type']}' does not match the target types."
419+
)
414420
return
415421

416422
try:

synapseclient/models/protocols/access_control_protocol.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,10 @@ def delete_permissions(
183183
determined by its own ACL.
184184
185185
If the ACL of an Entity is deleted, then its benefactor will automatically be set
186-
to its parent's benefactor. The ACL for a Project cannot be deleted.
186+
to its parent's benefactor.
187+
188+
**Special notice for Projects:** The ACL for a Project cannot be deleted, you
189+
must individually update or revoke the permissions for each user or group.
187190
188191
Arguments:
189192
include_self: If True (default), delete the ACL of the current entity.

tests/integration/synapseclient/models/async/test_permissions_async.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -859,4 +859,23 @@ async def test_delete_permissions_invalid_entity_type(
859859
# AND the error message should mention allowed values
860860
assert "Invalid entity type" in str(exc_info.value)
861861
assert "folder" in str(exc_info.value)
862-
assert "file" in str(exc_info.value)
862+
863+
async def test_delete_permissions_on_new_project(
864+
self, caplog: pytest.LogCaptureFixture
865+
) -> None:
866+
"""Test deleting permissions on a newly created project."""
867+
# GIVEN a newly created project with custom permissions
868+
project = await Project(name=f"test_project_{uuid.uuid4()}").store_async()
869+
self.schedule_for_cleanup(project.id)
870+
871+
# AND custom permissions are set for authenticated users
872+
await self._set_custom_permissions(project)
873+
874+
# WHEN I delete permissions on the project
875+
await project.delete_permissions_async()
876+
877+
# THEN the permissions should not be deleted
878+
assert (
879+
"Cannot restore inheritance for resource which has no parent."
880+
in caplog.text
881+
)

tests/integration/synapseclient/models/synchronous/test_permissions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,3 +850,23 @@ async def test_delete_permissions_invalid_entity_type(
850850
assert "Invalid entity type" in str(exc_info.value)
851851
assert "folder" in str(exc_info.value)
852852
assert "file" in str(exc_info.value)
853+
854+
async def test_delete_permissions_on_new_project(
855+
self, caplog: pytest.LogCaptureFixture
856+
) -> None:
857+
"""Test deleting permissions on a newly created project."""
858+
# GIVEN a newly created project with custom permissions
859+
project = await Project(name=f"test_project_{uuid.uuid4()}").store_async()
860+
self.schedule_for_cleanup(project.id)
861+
862+
# AND custom permissions are set for authenticated users
863+
await self._set_custom_permissions(project)
864+
865+
# WHEN I delete permissions on the project
866+
await project.delete_permissions()
867+
868+
# THEN the permissions should not be deleted
869+
assert (
870+
"Cannot restore inheritance for resource which has no parent."
871+
in caplog.text
872+
)

0 commit comments

Comments
 (0)