-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can configure admin to add and delete permissions #117
Conversation
web222vip
commented
Nov 14, 2023
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## main #117 +/- ##
==========================================
- Coverage 85.51% 84.56% -0.96%
==========================================
Files 21 21
Lines 435 447 +12
==========================================
+ Hits 372 378 +6
- Misses 63 69 +6
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
@web222vip please try to always open an issue before opening a PR. Why don't using django's permission system? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm not understanding well, but why don't just use the default django's permissions system?
@@ -93,6 +93,16 @@ class SettingAdmin(admin.ModelAdmin): | |||
list_editable = value_fields_names | |||
sortable_by = ("name",) | |||
|
|||
def has_add_permission(self, request): | |||
if settings.EXTRA_SETTINGS_ADMIN_ADD_PERMISSIO: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the setting name, it should be .._PERMISSION
.
def has_delete_permission(self, request, obj=None): | ||
if settings.EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO: | ||
return False | ||
return super().has_delete_permission(request, obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a typo in the setting name, it should be .._PERMISSION
.
|
||
def has_delete_permission(self, request, obj=None): | ||
if settings.EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO: | ||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the setting value is True
, the function should return True
instead of False
.
@@ -93,6 +93,16 @@ class SettingAdmin(admin.ModelAdmin): | |||
list_editable = value_fields_names | |||
sortable_by = ("name",) | |||
|
|||
def has_add_permission(self, request): | |||
if settings.EXTRA_SETTINGS_ADMIN_ADD_PERMISSIO: | |||
return False |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the setting value is True
, the function should return True
instead of False
.
You're right, |