Skip to main content

Django Perm Filter

Coverage

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:

python3 -m pip install django-perm-filter

Add it to your INSTALLED_APPS:

INSTALLED_APPS = (
    ...
    'django_perm_filter',
)

Settings

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",
    ],
}

Overrides

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.users.admin.UserAdmin",
  "GROUP_ADMIN": "myapp.users.admin.GroupAdmin",
}

Local Development

make env
make pip_install
make migrations
make migrate
make superuser
make serve

or simply make from_scratch

  • Visit http://127.0.0.1:8000/admin/ for the Django Admin

Testing

make pytest
make coverage
make open_coverage

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.2.4] - 2024-08-07

  • Set proper UserAdmin ordering field to username or email.

[0.2.3] - 2024-04-02

  • Update to use ruff and added more tests.

[0.2.2] - 2023-06-22

  • Update packaging method to use pyproject.toml.

[0.2.1] - 2022-09-19

  • Fixed issue if UserAdmin or GroupAdmin were already registered.

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

[0.1.1] - 2022-04-19

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

[0.1.0] - 2022-04-19

  • First release on PyPI.

Metadata

Release files for django-perm-filter 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-perm-filter 0.2.4
File Size Uploaded
django_perm_filter-0.2.4.tar.gz 11.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-perm-filter 0.2.4
File Interpreter ABI Platform
django_perm_filter-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 20.5 kB

Release files / django_perm_filter-0.2.4.tar.gz

Download URL django_perm_filter-0.2.4.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
2328e58ff811d8576b892d0fec67386af45bc7059947527850e2ba2f72fa5898
BLAKE2b-256 checksum
How to use checksums
7fcc3c8017544f14496b67c22ac838139fd7f646f5f22f98fd3bebd14fc47b65
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.11

Release files / django_perm_filter-0.2.4-py3-none-any.whl

Download URL django_perm_filter-0.2.4-py3-none-any.whl
Size 8.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f15d80ae39a172acb98154ebb31ebcb0f13d7d963656d7c26b7b4fe3bc1f6307
BLAKE2b-256 checksum
How to use checksums
0972467e5ebebc5a15cf432e378428a6582763902ee93eefc8035e9df2086f8c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.9.11

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

1 release file

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page