Skip to content
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

Closed
wants to merge 5 commits into from
Closed
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
10 changes: 10 additions & 0 deletions extra_settings/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@
list_editable = value_fields_names
sortable_by = ("name",)

def has_add_permission(self, request):
if settings.EXTRA_SETTINGS_ADMIN_ADD_PERMISSIO:
Copy link
Owner

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.

return False
Copy link
Owner

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.

return super().has_add_permission(request)

Check warning on line 99 in extra_settings/admin.py

View check run for this annotation

Codecov / codecov/patch

extra_settings/admin.py#L97-L99

Added lines #L97 - L99 were not covered by tests

def has_delete_permission(self, request, obj=None):
if settings.EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO:
return False
Copy link
Owner

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.

return super().has_delete_permission(request, obj)

Check warning on line 104 in extra_settings/admin.py

View check run for this annotation

Codecov / codecov/patch

extra_settings/admin.py#L102-L104

Added lines #L102 - L104 were not covered by tests
Copy link
Owner

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 get_changelist_form(self, request, **kwargs):
return SettingForm

Expand Down
6 changes: 6 additions & 0 deletions extra_settings/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,9 @@

if not hasattr(settings, "EXTRA_SETTINGS_VERBOSE_NAME"):
settings.EXTRA_SETTINGS_VERBOSE_NAME = "Extra Settings"

if not hasattr(settings, "EXTRA_SETTINGS_ADMIN_ADD_PERMISSIO"):
settings.EXTRA_SETTINGS_ADMIN_ADD_PERMISSIO = False

if not hasattr(settings, "EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO"):
settings.EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO = False