Skip to main content

The goal of dj_auth is to limit data access for certain user over your django project.

Project description

dj_auth

https://badge.fury.io/py/dj_auth.png

https://gitlab.com/systent/dj_auth/badges/master/build.svg https://gitlab.com/systent/dj_auth/badges/master/coverage.svg

The goal of dj_auth is to limit data access for certain user over your django project.

Requirements

Django 1.9

Quickstart

Install dj_auth:

pip install dj_auth

Put dj_auth into your INSTALLED_APPS at settings module:

INSTALLED_APPS = (
   ...
   'dj_auth',
)

Create dj_auth database tables by running:

python manage.py migrate

Extend the Queryset methods of your Models:

from django.db import models

from dj_auth.models import ObjectFilterQuerySetMixin

class YourModelQuerySet(ObjectFilterQuerySetMixin, models.QuerySet):

    def sichtbar(self, sichtbar=True):
        return self.filter(sichtbar=sichtbar)


class YourModel(models.Model):
    your_fielfs = models.SmallIntegerField()

    objects = YourModelQuerySet.as_manager()

Set DJ_AUTH constant in your settings.py:

DJ_AUTH = {'content_type_exclude': ('contenttypes.contenttype', 'sessions.session', 'sites.site',
                                    'auth.user', 'auth.group', 'auth.permission', 'admin.logentry',
                                    'dj_auth.objectfilter',),
           'content_type_include': (),
           'global_fields_exclude':  ('user', ),
           'related_filter_fields_exclude': {'auth.user': ('groups', ), },
           }

In “content_type_exclude” you put the models on which you don’t want create ObjectFilters

In “content_type_include” you put the models on which you want create ObjectFilters

In “global_fields_exclude” you put the fieldnames on which you don’t want apply the ObjectFilter globally

In “related_filter_fields_exclude” you put the fieldnames on which you don’t want apply the ObjectFilter for a specific Model

Features

ObjectFilterFormMixin

First of all you have to create an ObjectFilter record for a specific user. Therefore you can should use ObjectFilterFormMixin:

from django import forms

from dj_auth.forms import ObjectFilterFormMixin

class ObjectFilterForm(ObjectFilterFormMixin, forms.ModelForm):
    pass

ObjectFilterListMixin

To limit data in ListView use ObjectFilterListMixin:

from django.views.generic import ListView
from django.contrib.auth import get_user_model

from dj_auth.views import ObjectFilterListMixin

class UserListView(ObjectFilterListMixin, ListView):
    model = get_user_model()

ObjectFilterDetailMixin

To limit data in DetailView use ObjectFilterDetailMixin:

from django.views.generic import DetailView
from django.contrib.auth import get_user_model

from dj_auth.views import ObjectFilterDetailMixin

class UserDetailView(ObjectFilterDetailMixin, DetailView):
    model = get_user_model()

ObjectFilterUpdateMixin

To limit data in UpdateView use ObjectFilterUpdateMixin:

from django.views.generic import UpdateView
from django.contrib.auth import get_user_model

from dj_auth.views import ObjectFilterUpdateMixin

class UserDetailView(ObjectFilterUpdateMixin, UpdateView):
    model = get_user_model()

ObjectFilterDeleteMixin

To limit data in UpdateView use ObjectFilterDeleteMixin:

from django.views.generic import DeleteView
from django.contrib.auth import get_user_model

from dj_auth.views import ObjectFilterDeleteMixin

class UserDetailView(ObjectFilterDeleteMixin, DeleteView):
    model = get_user_model()

Todo

Running Tests

Does the code actually work?

source <YOURVIRTUALENV>/bin/activate
(myenv) $ pip install -r requirements_test.txt
(myenv) $ coverage run --source=dj_auth runtests.py && coverage html

Credits

Tools used in rendering this package:

History

0.1.0 (2016-07-29)

  • First release on PyPI.

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

dj_auth-1.5.1.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

dj_auth-1.5.1-py2.py3-none-any.whl (16.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file dj_auth-1.5.1.tar.gz.

File metadata

  • Download URL: dj_auth-1.5.1.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for dj_auth-1.5.1.tar.gz
Algorithm Hash digest
SHA256 845df13beb3695b76d939c6603a26459a5401da0c6be938f0abcd1cb89b3d65a
MD5 1c3e0cd885bd6ad55fabac6cccca4d41
BLAKE2b-256 caaa0558ae1e68f2b0560e58b2ae8d224d872f8491485ad3e1c35502d70856ca

See more details on using hashes here.

File details

Details for the file dj_auth-1.5.1-py2.py3-none-any.whl.

File metadata

  • Download URL: dj_auth-1.5.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.8

File hashes

Hashes for dj_auth-1.5.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 836c7b6f5dbc5d517e08ac36b59e62be4625e18c037fd6c9d4562a76896b7fb5
MD5 1db91674f5d13595c05c14ae3155c83d
BLAKE2b-256 46eccd58ce84e66deeaacbf2b4d3b625ffcf1b991ee41ba13f2073306be92a1c

See more details on using hashes here.

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