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] - 2021-07-23

  • First release on PyPI.

[0.2.2] - 2021-07-29

Added

  • Link to mobile and desktop app stores.

Fixed

  • Broken app store links in app listing

[0.2.3] - 2021-07-29

Changed

  • Don't assume url pattern

[0.2.4] - 2021-07-29

Added

  • Capture query params in visit

[0.2.5] - 2021-07-29

Changed

  • Removed print statement
  • Moved get_querystring_as_dict into helpers

[0.2.6] - 2021-08-04

Fixed

  • Added missing migrations.

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

Uploaded Source

Built Distribution

django_perm_filter-0.1.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.1.0.tar.gz.

File metadata

  • Download URL: django-perm-filter-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 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.0.tar.gz
Algorithm Hash digest
SHA256 f7c33ad2a398be8809cee8e58a4d2a14a2e619086fad6e49517233a459a9331a
MD5 b07bd4e709fe3954461044a9dbb779a6
BLAKE2b-256 0aa493ce3f56dad89bc29d2e2a34dbb596ef7d11c68b8c346ab5e965e8886c28

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for django_perm_filter-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 67ffea3fb02f60892d370bce05dbeade60826bef2183dd9f58621ed1131840ed
MD5 751024c31d297fdb91d8e71977289e7c
BLAKE2b-256 b5a0e0c510ae564ed594072e3cdbd1a7189f24334ca1b9326d8d15efb0b810e4

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