Skip to content

Commit bfcfb16

Browse files
committed
👔(dashboard) disallow delete action for consents in admin.
Added `has_delete_permission` method to disable the delete action for all users in the Consent admin. Included tests to ensure deletion is disallowed for existing objects and when no object is passed. Updated the changelog accordingly.
1 parent 6794110 commit bfcfb16

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/dashboard/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ and this project adheres to
2020
- add consent form to manage consents of one or many entities
2121
- add admin integration for Entity, DeliveryPoint and Consent
2222
- add mass admin action (make revoked) for consents
23+
- disallow mass action "delete" for consents in admin
2324
- block the updates of all new data if a consent has the status `VALIDATED`
2425
- block the deletion of consent if it has the status `VALIDATED`
2526
- block consent updates (via the consent form) if the consent status is not `AWAITING`

src/dashboard/apps/consent/admin.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ class ConsentAdmin(admin.ModelAdmin):
2828
date_hierarchy = "start"
2929
actions = ["make_revoked"]
3030

31+
def has_delete_permission(self, request, obj=None):
32+
"""Disable delete action permission for all users."""
33+
return False
34+
3135
@admin.action(description=_("Mark selected consents as revoked"))
3236
def make_revoked(self, request, queryset):
3337
"""Mark selected consents as revoked."""

src/dashboard/apps/consent/tests/test_admin.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,28 @@ def test_make_revoked_action(client, patch_timezone_now):
6262
assert consent.status == REVOKED
6363
assert consent.revoked_at == FAKE_TIME
6464
assert consent.updated_at == FAKE_TIME
65+
66+
67+
@pytest.mark.django_db
68+
def test_has_delete_permission_false_for_existing_object(rf):
69+
"""Test that the has_delete_permission disallows deletion of an existing object."""
70+
# Initialize admin
71+
admin = ConsentAdmin(Consent, AdminSite())
72+
request = rf.get(reverse("admin:qcd_consent_consent_changelist"))
73+
74+
# create a consent
75+
assert Consent.objects.count() == 0
76+
DeliveryPointFactory()
77+
assert Consent.objects.count() == 1
78+
79+
consent = Consent.objects.first()
80+
assert admin.has_delete_permission(request, obj=consent) is False
81+
82+
83+
@pytest.mark.django_db
84+
def test_has_delete_permission_false_for_none_object(rf):
85+
"""Test has_delete_permission disallows deletion when no object is passed (None)."""
86+
# Initialize admin
87+
admin = ConsentAdmin(Consent, AdminSite())
88+
request = rf.get(reverse("admin:qcd_consent_consent_changelist"))
89+
assert admin.has_delete_permission(request, obj=None) is False

0 commit comments

Comments
 (0)