Skip to content

Commit

Permalink
✨ [[maykinmedia/archiefbeheercomponent#340] Add endpoint for creating…
Browse files Browse the repository at this point in the history
… the destruction list
  • Loading branch information
SilviaAmAm committed May 2, 2024
1 parent 8c87918 commit db3cf1a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 3 deletions.
19 changes: 16 additions & 3 deletions backend/src/openarchiefbeheer/api/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,16 @@
SpectacularJSONAPIView,
SpectacularRedocView,
)
from rest_framework import routers

from openarchiefbeheer.accounts.api.views import ReviewersView
from openarchiefbeheer.destruction.api.viewsets import DestructionListViewSet

app_name = "api"

router = routers.DefaultRouter(trailing_slash=False)
router.register(r"destruction-lists", DestructionListViewSet)


urlpatterns = [
# API documentation
Expand Down Expand Up @@ -40,8 +45,16 @@
),
# Actual endpoints
path(
"v1/zaken/",
include("openarchiefbeheer.api.zaken.urls", namespace="zaken"),
"v1/",
include(
[
path(
"zaken/",
include("openarchiefbeheer.api.zaken.urls", namespace="zaken"),
),
path("reviewers/", ReviewersView.as_view(), name="reviewers"),
path("", include(router.urls)),
]
),
),
path("v1/reviewers/", ReviewersView.as_view(), name="reviewers"),
]
10 changes: 10 additions & 0 deletions backend/src/openarchiefbeheer/destruction/api/permissions.py
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
24 changes: 24 additions & 0 deletions backend/src/openarchiefbeheer/destruction/api/viewsets.py
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)

0 comments on commit db3cf1a

Please sign in to comment.