Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/backend/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,7 +1400,7 @@ def get_abilities(self, user): # pylint: disable=too-many-locals
"leave": can_leave,
"move": is_owner_or_admin and not is_deleted,
"partial_update": can_update,
"restore": is_owner,
"restore": is_owner and bool(self.deleted_at),
"retrieve": retrieve,
"media_auth": can_get,
"link_select_options": link_select_options,
Expand Down
18 changes: 18 additions & 0 deletions src/backend/core/tests/documents/test_api_documents_restore.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,24 @@ def test_api_documents_restore_authenticated_owner_ancestor_deleted():
assert grand_parent_deleted_at > document_deleted_at


def test_api_documents_restore_ability_false_when_only_ancestor_deleted():
"""The restore ability should be false when only an ancestor is deleted."""
user = factories.UserFactory()
client = APIClient()
client.force_login(user)

parent = factories.DocumentFactory()
document = factories.DocumentFactory(parent=parent)
factories.UserDocumentAccessFactory(document=document, user=user, role="owner")

parent.soft_delete()

response = client.get(f"/api/v1.0/documents/{document.id!s}/")

assert response.status_code == 200
assert response.json()["abilities"]["restore"] is False


def test_api_documents_restore_authenticated_owner_expired():
"""It should not be possible to restore a document beyond the allowed time limit."""
user = factories.UserFactory()
Expand Down