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

Conversation

web222vip
Copy link

image

Copy link

codecov bot commented Nov 14, 2023

Codecov Report

Attention: 6 lines in your changes are missing coverage. Please review.

Comparison is base (c810900) 85.51% compared to head (0487d92) 84.56%.

Files Patch % Lines
extra_settings/admin.py 25.00% 6 Missing ⚠️
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     
Flag Coverage Δ
unittests 84.56% <50.00%> (-0.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@fabiocaccamo
Copy link
Owner

@web222vip please try to always open an issue before opening a PR.

Why don't using django's permission system?

Copy link
Owner

@fabiocaccamo fabiocaccamo left a 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:
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 has_delete_permission(self, request, obj=None):
if settings.EXTRA_SETTINGS_ADMIN_DELETE_PERMISSIO:
return False
return super().has_delete_permission(request, obj)
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 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.

@@ -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
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.

@web222vip
Copy link
Author

You're right,
Use the default django permission system

@web222vip web222vip closed this Nov 15, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants