diff --git a/passbook/core/migrations/0023_remove_user_applications.py b/passbook/core/migrations/0023_remove_user_applications.py new file mode 100644 index 000000000..daaaefcd2 --- /dev/null +++ b/passbook/core/migrations/0023_remove_user_applications.py @@ -0,0 +1,17 @@ +# Generated by Django 2.2 on 2019-04-13 15:51 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('passbook_core', '0022_nonce_expiring'), + ] + + operations = [ + migrations.RemoveField( + model_name='user', + name='applications', + ), + ] diff --git a/passbook/core/models.py b/passbook/core/models.py index cc4642ebb..04140a167 100644 --- a/passbook/core/models.py +++ b/passbook/core/models.py @@ -47,7 +47,6 @@ class User(AbstractUser): name = models.TextField() sources = models.ManyToManyField('Source', through='UserSourceConnection') - applications = models.ManyToManyField('Application') groups = models.ManyToManyField('Group') password_change_date = models.DateTimeField(auto_now_add=True) diff --git a/passbook/core/requirements.txt b/passbook/core/requirements.txt index 78e07757a..782bc5b10 100644 --- a/passbook/core/requirements.txt +++ b/passbook/core/requirements.txt @@ -1,5 +1,6 @@ celery colorlog +django-guardian django-ipware django-model-utils django-redis diff --git a/passbook/core/settings.py b/passbook/core/settings.py index 2d0b26b18..d139e2ec7 100644 --- a/passbook/core/settings.py +++ b/passbook/core/settings.py @@ -58,7 +58,8 @@ SESSION_CACHE_ALIAS = "default" LANGUAGE_COOKIE_NAME = 'passbook_language' AUTHENTICATION_BACKENDS = [ - 'django.contrib.auth.backends.ModelBackend' + 'django.contrib.auth.backends.ModelBackend', + 'guardian.backends.ObjectPermissionBackend', ] # Application definition @@ -73,6 +74,7 @@ INSTALLED_APPS = [ 'django.contrib.postgres', 'rest_framework', 'drf_yasg', + 'guardian', 'passbook.core.apps.PassbookCoreConfig', 'passbook.admin.apps.PassbookAdminConfig', 'passbook.api.apps.PassbookAPIConfig', diff --git a/passbook/core/views/overview.py b/passbook/core/views/overview.py index 07b55ace8..7c85b3d63 100644 --- a/passbook/core/views/overview.py +++ b/passbook/core/views/overview.py @@ -2,8 +2,7 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.views.generic import TemplateView - -from passbook.core.models import Application +from guardian.shortcuts import get_objects_for_user class OverviewView(LoginRequiredMixin, TemplateView): @@ -13,7 +12,6 @@ class OverviewView(LoginRequiredMixin, TemplateView): template_name = 'overview/index.html' def get_context_data(self, **kwargs): - kwargs['applications'] = self.request.user.applications.all() - if self.request.user.is_superuser: - kwargs['applications'] = Application.objects.all() + kwargs['applications'] = get_objects_for_user(self.request.user, + 'passbook_core.view_application') return super().get_context_data(**kwargs)