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

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

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_APPS": [
        # Django built-in apps
        "admin",
        "contenttypes",
        "sessions",
        "sites",
        # Other apps you wish to hide
    ],
    "HIDE_PERMS": [
        # Django built-in auth permissions
        "auth.view_permission",
        "auth.add_permission",
        "auth.change_permission",
        "auth.delete_permission",
        # Other app.codename perms you wish to hide
    ],
    "UNREGISTER_MODELS": [
        "django.contrib.sites.models.Site",
    ],
}

Optional

By default Django Perms Filter will do the following when the app is ready. However, feel free to override to extend your own built-in Django Group or User Model Admins.

from django.contrib import admin
from django.contrib.auth import get_user_model
from django.contrib.auth.admin import GroupAdmin, UserAdmin
from django.contrib.auth.models import Group

from django_perm_filter import PermissionFilterMixin
from django_perm_filter import unregister_models

User = get_user_model()


class MyGroupAdmin(PermissionFilterMixin, GroupAdmin):
    pass


class MyUserAdmin(PermissionFilterMixin, UserAdmin):
    pass


# Override default registered Admin for User and Group
admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, MyUserAdmin)
admin.site.register(Group, MyGroupAdmin)

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!

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.1.1.tar.gz (6.7 kB view details)

Uploaded Source

Built Distribution

django_perm_filter-0.1.1-py2.py3-none-any.whl (7.9 kB view details)

Uploaded Python 2Python 3

File details

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

File metadata

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

File hashes

Hashes for django-perm-filter-0.1.1.tar.gz
Algorithm Hash digest
SHA256 7d3c97e06f892ec76008504781e0d22f1994387f37133a1341cda9b143492ffa
MD5 e1d8e9ff0349cec640d320fe584fa520
BLAKE2b-256 61b1fafa789ccec0409e65275fb07348ceeffa3cd2d7373c02d55435eb4c3810

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_perm_filter-0.1.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 b1165a4d6b4dd64f8464be633a0a5c88b720f13edb258af70762ecbc3f1ded66
MD5 33a64a9d095d9baecb46815cec512c3d
BLAKE2b-256 1917d08af32cd032336dffbe500a220390a710d0137a1ddfe835730a427165b8

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