Add guardian for Application permissions
This commit is contained in:
parent
35b6bb6b3f
commit
8536ef9e23
|
@ -0,0 +1,17 @@
|
||||||
|
# Generated by Django 2.2 on 2019-04-09 16:13
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('passbook_core', '0021_policy_timeout'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RemoveField(
|
||||||
|
model_name='user',
|
||||||
|
name='applications',
|
||||||
|
),
|
||||||
|
]
|
|
@ -47,7 +47,6 @@ class User(AbstractUser):
|
||||||
name = models.TextField()
|
name = models.TextField()
|
||||||
|
|
||||||
sources = models.ManyToManyField('Source', through='UserSourceConnection')
|
sources = models.ManyToManyField('Source', through='UserSourceConnection')
|
||||||
applications = models.ManyToManyField('Application')
|
|
||||||
groups = models.ManyToManyField('Group')
|
groups = models.ManyToManyField('Group')
|
||||||
password_change_date = models.DateTimeField(auto_now_add=True)
|
password_change_date = models.DateTimeField(auto_now_add=True)
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
celery
|
celery
|
||||||
cherrypy
|
cherrypy
|
||||||
colorlog
|
colorlog
|
||||||
|
django-guardian
|
||||||
django-ipware
|
django-ipware
|
||||||
django-model-utils
|
django-model-utils
|
||||||
django-redis
|
django-redis
|
||||||
|
|
|
@ -58,7 +58,8 @@ SESSION_CACHE_ALIAS = "default"
|
||||||
LANGUAGE_COOKIE_NAME = 'passbook_language'
|
LANGUAGE_COOKIE_NAME = 'passbook_language'
|
||||||
|
|
||||||
AUTHENTICATION_BACKENDS = [
|
AUTHENTICATION_BACKENDS = [
|
||||||
'django.contrib.auth.backends.ModelBackend'
|
'django.contrib.auth.backends.ModelBackend',
|
||||||
|
'guardian.backends.ObjectPermissionBackend',
|
||||||
]
|
]
|
||||||
|
|
||||||
# Application definition
|
# Application definition
|
||||||
|
@ -73,6 +74,8 @@ INSTALLED_APPS = [
|
||||||
'django.contrib.postgres',
|
'django.contrib.postgres',
|
||||||
'rest_framework',
|
'rest_framework',
|
||||||
'drf_yasg',
|
'drf_yasg',
|
||||||
|
'guardian',
|
||||||
|
'raven.contrib.django.raven_compat',
|
||||||
'passbook.core.apps.PassbookCoreConfig',
|
'passbook.core.apps.PassbookCoreConfig',
|
||||||
'passbook.admin.apps.PassbookAdminConfig',
|
'passbook.admin.apps.PassbookAdminConfig',
|
||||||
'passbook.api.apps.PassbookAPIConfig',
|
'passbook.api.apps.PassbookAPIConfig',
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.views.generic import TemplateView
|
from django.views.generic import TemplateView
|
||||||
|
from guardian.shortcuts import get_objects_for_user
|
||||||
|
|
||||||
from passbook.core.models import Application
|
from passbook.core.models import Application
|
||||||
|
|
||||||
|
@ -13,7 +14,6 @@ class OverviewView(LoginRequiredMixin, TemplateView):
|
||||||
template_name = 'overview/index.html'
|
template_name = 'overview/index.html'
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
kwargs['applications'] = self.request.user.applications.all()
|
kwargs['applications'] = get_objects_for_user(self.request.user,
|
||||||
if self.request.user.is_superuser:
|
'passbook_core.view_application')
|
||||||
kwargs['applications'] = Application.objects.all()
|
|
||||||
return super().get_context_data(**kwargs)
|
return super().get_context_data(**kwargs)
|
||||||
|
|
Reference in New Issue