File tree Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Expand file tree Collapse file tree 3 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,7 @@ and this project adheres to
20
20
- add consent form to manage consents of one or many entities
21
21
- add admin integration for Entity, DeliveryPoint and Consent
22
22
- add mass admin action (make revoked) for consents
23
+ - disallow mass action "delete" for consents in admin
23
24
- block the updates of all new data if a consent has the status ` VALIDATED `
24
25
- block the deletion of consent if it has the status ` VALIDATED `
25
26
- block consent updates (via the consent form) if the consent status is not ` AWAITING `
Original file line number Diff line number Diff line change @@ -28,6 +28,10 @@ class ConsentAdmin(admin.ModelAdmin):
28
28
date_hierarchy = "start"
29
29
actions = ["make_revoked" ]
30
30
31
+ def has_delete_permission (self , request , obj = None ):
32
+ """Disable delete action permission for all users."""
33
+ return False
34
+
31
35
@admin .action (description = _ ("Mark selected consents as revoked" ))
32
36
def make_revoked (self , request , queryset ):
33
37
"""Mark selected consents as revoked."""
Original file line number Diff line number Diff line change @@ -62,3 +62,28 @@ def test_make_revoked_action(client, patch_timezone_now):
62
62
assert consent .status == REVOKED
63
63
assert consent .revoked_at == FAKE_TIME
64
64
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
You can’t perform that action at this time.
0 commit comments