Skip to content
This repository has been archived by the owner on Jul 26, 2024. It is now read-only.

Configurable access control #12

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

baudhuina
Copy link

Rationale for this pull request

As of v1.2.1:

  • clearcache is only accessible to superuser. We would like some regular users with extended privileges (sysadmins) to be able to clear caches in an operational environment.
  • clearcache is visible on the Admin homepage of any user with access to Admin, even non superusers, which can attempt a clear cache, before being forbidden by the clearcache view.

Both issue are nicely solved by using a specific permission (clearcache.use_clearcache), to control the access to both the service and the display its section in the Admin's homepage.

Testing for the permission in the existing test_func() of the view preserves the current behaviour as long as the permission is not granted to anyone, since superusers have all permissions.

Changes summary

  • Added model “CustomPermissions” (without databasse tables) to create clearcache.use_clearcache permission, and made migration.
  • Changed ClearCacheAdminView.test_func() to test for the permission (this is backward compatible with the previous test of “is_superuser”, since superusers have all permissions).
  • Now test for the permission in admin/index.html template, to avoid displaying the clearcache section on Admin’s homepage if the user is not authorized.
  • Added tests to check permissions with regular user:
    • Created tests folder.
    • Original tests unchanged to assert backward compatibility, as test_superuser.py. Just moved CACHE_EXPIRE_IN_SEC constant at module level to avoid PEP8 violation (all-caps constants not supposed to be in functions).
    • Additional test as test_regular_user.py.
  • Added python 3.11 and django 4.0, 4.1, 4.2 to test matrix.
    • Since Django 4.x does not support Python 3.7, split the only job of the workflow in 2 jobs (one for python python3.7, one for all other python versions) and issued a different tox command in each one.
    • Added pytest and pytest-django in dependencies in tox.ini as required by “Missing dependency” tox warning.
    • Upgraded workflow actions to v3 (checkout and python setup). v2 runs on node12 which is deprecated.
    • Added workflow_dispatch: event to be able to manually trigger the workflow. It could be removed, but I guess it doesn't hurt.
    • Slightly updated documentation to reflect the improved access control.

All tests are ok.

… permission, and made migration.

- Changed ClearCacheAdminView.test_func() to test for the permission (this is backward compatible with the previous test of “is_superuser”, since superusers have all permissions.
- Now test for the permission in admin/index.html template, to avoid displaying the clearcache section on Admin’s homepage if the user is not allowed to make use of clearcache.
- Added tests to check permissions with regular user:
     Created “tests” folder.
     Original tests unchanged to assert backward compatibility, as test_superuser.py
     Just moved CACHE_EXPIRE_IN_SEC constant at module level to avoid PEP8 violation (all-caps constants not supposed to be in functions).
      Additional test as test_regular_user.py.
1) Added python 3.11 and django 4.2 to test matrix. Since Django 4.2 is not supported on Python 3.7, I had to run 2 jobs in the workflow (python3.7 and all other python versions) and issue a different tox command in each one.
2) Added pytest and pytest-django in dependencies in tox.ini as required by “Missing dependency” tox warning.
3) Upgraded actions to v3 (checkout and python setup). v2 runs on node12 which is deprecated.
4) Added workflow_dispatch: event to be able to manually trigger the workflow
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant