Browse Source

Include 'use_api' permission in the api.acl module

better_user
Maël Kervella 8 years ago
parent
commit
a5715d69b6
  1. 22
      api/acl.py
  2. 17
      api/initial_perm.py
  3. 1
      api/urls.py

22
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):

17
api/initial_perm.py

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

1
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)

Loading…
Cancel
Save