-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ [[maykinmedia/archiefbeheercomponent#340] Add endpoint for creating…
… the destruction list
- Loading branch information
1 parent
8c87918
commit db3cf1a
Showing
3 changed files
with
50 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
backend/src/openarchiefbeheer/destruction/api/permissions.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
from django.utils.translation import gettext_lazy as _ | ||
|
||
from rest_framework import permissions | ||
|
||
|
||
class CanStartDestructionPermission(permissions.BasePermission): | ||
message = _("You are not allowed to create a destruction list.") | ||
|
||
def has_permission(self, request, view): | ||
return request.user.role.can_start_destruction |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from django.db import transaction | ||
|
||
from rest_framework import mixins, viewsets | ||
from rest_framework.permissions import IsAuthenticated | ||
|
||
from ..models import DestructionList | ||
from .permissions import CanStartDestructionPermission | ||
from .serializers import DestructionListSerializer | ||
|
||
|
||
class DestructionListViewSet(mixins.CreateModelMixin, viewsets.GenericViewSet): | ||
serializer_class = DestructionListSerializer | ||
queryset = DestructionList.objects.all() | ||
|
||
def get_permissions(self): | ||
if self.action == "create": | ||
permission_classes = [IsAuthenticated & CanStartDestructionPermission] | ||
else: | ||
permission_classes = [IsAuthenticated] | ||
return [permission() for permission in permission_classes] | ||
|
||
@transaction.atomic | ||
def create(self, request, *args, **kwargs): | ||
return super().create(request, *args, **kwargs) |