Package: django-roles-access
Django Roles AccessApplication for securing access to views with roles
(Django contrib Groups).django_roles_accessis a Django app for securing access to views. It's
built on top of Django contrib Groups interpreted as role. The objective of
the app are:Provide secure access to views.Be able to administrate access to views without the need to restart the
server (at run time).Minimize the need of new code, or eliminate it at all (when usingdjango_roles_accessmiddleware). Also free developers from the task
of coding any view access.django_roles_accessalso provides a security report by registeringcheckviewaccessaction.Works with:Django 1.10+ (Python 2.7, Python 3.5+)Django 2 (Python 3.5+)DocumentationRequirementsDjango roles access useDjango contrib Groups,Django contrib User. AlsoDjango
admin interfaceis necessary to create and administrateviews access(django_roles_access.models.ViewAccess).
So Django roles access is dependent ofDjango admin siteand because of
this it has the same requirements than it. This can be checked in theofficial documentation:Quick startInstallation and configurationInstalldjango_roles_accessfrom pypi:pip install django-roles-accessAdd'django_roles_access'to your INSTALLED_APPS setting:INSTALLED_APPS = [
...
'django_roles_access',
]Run migrations to create thedjango_roles_accessmodels:python manage.py migrateNote:If nothing else is done, then Django site security keeps without
modification.Access configurationQuick view access configuration in two steps.Step 1InDjango admininterface create adjango_roles_access.models.ViewAccessobject and configure it:viewattribute: name of the view you to be secured. Format used:<app_name:view_name>(Namespaces and View name).typeattribute: select theaccess typefor the view:Public: Any visitor can access the view.Authorized: Only authorized (logged)Django contrib Usercan access
the view.By roles: OnlyDjango contrib Userbelonging to any addedDjango
contrib userwill access the view.rolesattribute: WhenBy rolesis selected asaccess type, this
attribute hold anyDjango contrib Groupwhose members will access the view.Step 2In the view to be secured use:access_by_rolesdecorator in case of view function
(django_roles_access.decorators.access_by_roles)RolesMixinmixin in case of classes based views
(django_roles_access.mixin.RolesMixin)For example:In case of view is a function:from django_roles_access.decorators import access_by_role

@access_by_role()
myview(request):
   ...In case of classes based views use mixin:from django_roles_access.mixin import RolesMixin

class MyView(RolesMixin, View):

    ...Note:When user has no access to a view, by defaultdjango_roles_accessresponse withdjango.http.HttpResponseForbidden.Warning:Pre existent security behavior can be modified if adjango_roles_accessconfiguration for the same view results in a more restricted view access.Test Django roles accessYou can check thedjango_roles_accesstest execution atTravis CI integration()You can also checkdajngo_roles_accesstest coverage atCoverage()Or:Create a virtual environment.Get into and activate virtual environment.Clonedjango_roles_access:git clonehttps://github.com/django-roles-access/master.gitInstall tox:pip install toxRun the tests:toxRelated sitesDocumentationPackage at pypi.orgsource codeTravis CI integrationCodecov