From a5715d69b6858c4414053e49855f3db3ba79c2c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Sat, 21 Apr 2018 16:32:12 +0000 Subject: [PATCH] Include 'use_api' permission in the api.acl module --- api/acl.py | 22 ++++++++++++++++++++++ api/initial_perm.py | 17 ----------------- api/urls.py | 1 - 3 files changed, 22 insertions(+), 18 deletions(-) delete mode 100644 api/initial_perm.py diff --git a/api/acl.py b/api/acl.py index da0c9a29..0c7faae7 100644 --- a/api/acl.py +++ b/api/acl.py @@ -24,7 +24,29 @@ Here are defined some functions to check acl on the application. """ + from django.conf import settings +from django.contrib.contenttypes.models import ContentType +from django.contrib.auth.models import Permission + + +# Creates the 'use_api' permission if not created +# The 'use_api' is a fake permission in the sense +# it is not associated with an existing model and +# this ensure the permission is created every tun +api_content_type, created = ContentType.objects.get_or_create( + app_label=settings.API_CONTENT_TYPE_APP_LABEL, + model=settings.API_CONTENT_TYPE_MODEL +) +if created: + api_content_type.save() +api_permission, created = Permission.objects.get_or_create( + name=settings.API_PERMISSION_NAME, + content_type=api_content_type, + codename=settings.API_PERMISSION_CODENAME +) +if created: + api_permission.save() def can_view(user): diff --git a/api/initial_perm.py b/api/initial_perm.py deleted file mode 100644 index f4482fd9..00000000 --- a/api/initial_perm.py +++ /dev/null @@ -1,17 +0,0 @@ -from django.contrib.contenttypes.models import ContentType -from django.contrib.auth.models import Permission -from django.conf import settings - -api_content_type, created = ContentType.objects.get_or_create( - app_label=settings.API_CONTENT_TYPE_APP_LABEL, - model=settings.API_CONTENT_TYPE_MODEL -) -if created: - api_content_type.save() -api_permission, created = Permission.objects.get_or_create( - name=settings.API_PERMISSION_NAME, - content_type=api_content_type, - codename=settings.API_PERMISSION_CODENAME -) -if created: - api_permission.save() diff --git a/api/urls.py b/api/urls.py index 90672b47..662dd8c4 100644 --- a/api/urls.py +++ b/api/urls.py @@ -28,7 +28,6 @@ from django.conf.urls import url, include from rest_framework.routers import DefaultRouter from . import views -from . import initial_perm router = DefaultRouter() router.register(r'users', views.UserViewSet)