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

Uploaded Source

Built Distribution

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

Uploaded Python 2 Python 3

Supported by

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