8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-11-26 22:52:26 +00:00

Include 'use_api' permission in the api.acl module

This commit is contained in:
Maël Kervella 2018-04-21 16:32:12 +00:00
parent 0be63ad58e
commit a5715d69b6
3 changed files with 22 additions and 18 deletions

View file

@ -24,7 +24,29 @@
Here are defined some functions to check acl on the application. Here are defined some functions to check acl on the application.
""" """
from django.conf import settings 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): def can_view(user):

View file

@ -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()

View file

@ -28,7 +28,6 @@ from django.conf.urls import url, include
from rest_framework.routers import DefaultRouter from rest_framework.routers import DefaultRouter
from . import views from . import views
from . import initial_perm
router = DefaultRouter() router = DefaultRouter()
router.register(r'users', views.UserViewSet) router.register(r'users', views.UserViewSet)