Skip to content

Commit

Permalink
🐛 debug: IranianCitiesAdminReadOnlyEnabled Mixin
Browse files Browse the repository at this point in the history
  • Loading branch information
ARYAN-NIKNEZHAD committed Sep 9, 2024
1 parent 7dd8ca4 commit 338b859
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions iranian_cities/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

# Default values for permissions
DEFAULT_SETTINGS: Dict[str, bool] = {
"IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED": True,
"IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED": True,
"IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED": True,
"IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED": False,
"IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED": False,
"IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED": False,
"IRANIAN_CITIES_ADMIN_INLINE_ENABLED": False,
}
6 changes: 3 additions & 3 deletions iranian_cities/mixins/dynamic_permission.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@

class IranianCitiesAdminReadOnlyEnabled:
def has_add_permission(self, request):
return sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED
return not sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_ADD_READONLY_ENABLED

def has_delete_permission(self, request, obj=None):
return sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED
return not sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED

def has_change_permission(self, request, obj=None):
return sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED
return not sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED


class DynamicInlineAdmin:
Expand Down
6 changes: 3 additions & 3 deletions tests/settings/test_admin_permissions.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,9 @@ def test_iranian_cities_admin_permissions(self) -> None:
sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_DELETE_READONLY_ENABLED = False
sage_iranian_cities_settings.IRANIAN_CITIES_ADMIN_CHANGE_READONLY_ENABLED = True

assert settings_instance.has_add_permission(request) is True
assert settings_instance.has_delete_permission(request) is False
assert settings_instance.has_change_permission(request) is True
assert settings_instance.has_add_permission(request) is False
assert settings_instance.has_delete_permission(request) is True
assert settings_instance.has_change_permission(request) is False

def test_dynamic_inline_admin(self) -> None:
"""
Expand Down

0 comments on commit 338b859

Please sign in to comment.