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)