Skip to main content

Your project description goes here

Project description

Django Perm Filter

A simple app that can be included in Django projects which hides app specific permissions from any type of User. Easily add entire apps, specific permissions or models and it will take care of the rest. Non-destructive (Does not delete permissions).

For example, typically we have no reason, in any Django project, to expose the following permissions for Users or Groups:

App Model Permission
admin log entry Can view/add/change/delete log entry
auth permission Can view/add/change/delete permission
contenttypes content type Can view/add/change/delete content type
sessions session Can view/add/change/delete session

Features

  • Hide all permissions for an App
  • Hide permissions using app and codename (more granular)
  • Hide models from the Django Admin

Requirements

Django 3 or 4 Python 3

Quickstart

Install Django Perm Filter::

pip install django-perm-filter

Add it to your INSTALLED_APPS at the bottom:

INSTALLED_APPS = (
    ...
    'django_perm_filter',
)

In your settings.py add a entry for PERM_FILTER:

PERM_FILTER = {
    "HIDE_PERMS": [
        # Use app name only to hide all app related permissions
        "admin",
        "contenttypes",
        "sessions",
        "sites",
        # Use app.codename to get more granular
        "auth.view_permission",
        "auth.add_permission",
        "auth.change_permission",
        "auth.delete_permission",
    ],
    "UNREGISTER_MODELS": [
        "django.contrib.sites.models.Site",
    ],
}

Optional

By default django_perm_filter will register a new UserAdmin and GroupAdmin which extend django.contrib.auth.admin.UserAdmin and django.contrib.auth.admin.GroupAdmin that simply adds permissions filtering. If you would like it to extend your own custom UserAdmin or GroupAdmin classes, then set the class path in the PERM_FILTER settings.

PERM_FILTER = {
  ...
  "USER_ADMIN": "myapp.user.admin.UserAdmin",
  "GROUP_ADMIN": "myapp.user.admin.GroupAdmin",
}

Development

Assumes you have pyenv and make installed (you should!).

make scratch

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install tox
(myenv) $ tox

Development commands

pip install -r requirements_dev.txt
invoke -l

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog, and this project adheres to Semantic Versioning.

[0.1.0] - 2022-04-19

  • First release on PyPI.

[0.1.1] - 2022-04-19

  • Sorry, pushed copy/pasted changelog on first release!

[0.2.0] - 2022-08-11

  • Merged HIDE_APPS and HIDE_PERMS to make more clear that we're hiding perms only.
  • Added ability to extend your own custom UserAdmin and GroupAdmin if need be.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-perm-filter-0.2.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

django_perm_filter-0.2.0-py2.py3-none-any.whl (8.1 kB view details)

Uploaded Python 2Python 3

File details

Details for the file django-perm-filter-0.2.0.tar.gz.

File metadata

  • Download URL: django-perm-filter-0.2.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.11

File hashes

Hashes for django-perm-filter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a9447273e0f04940f3312366df973e1112425743939ba833f281329ddfe68430
MD5 c335f5021379d5c83dc73638c76d7f2c
BLAKE2b-256 90709a5b993dbae0a7869757e28ad3ecf72267b87d6389078844f095aec6334f

See more details on using hashes here.

File details

Details for the file django_perm_filter-0.2.0-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for django_perm_filter-0.2.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5252c28ae8ef9d12ab852fee9d8350dc42318f3e5a7e29cf1b45f0764263b208
MD5 59279e648c212d0e544c699d34642d68
BLAKE2b-256 cb34b3129d70e776bc0ac14bc3c08edf2c5baa0acf62fd85981662d2d16a814a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page