-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
…endpoint LTD-5083: Add endpoint to allow update of quantity value fields only
- Loading branch information
Showing
5 changed files
with
154 additions
and
1 deletion.
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
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
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
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,9 @@ | ||
from rest_framework import permissions | ||
|
||
from api.staticdata.statuses.enums import CaseStatusEnum | ||
|
||
|
||
class IsApplicationEditable(permissions.BasePermission): | ||
def has_permission(self, request, view): | ||
application = view.application | ||
return application.status.status in CaseStatusEnum.major_editable_statuses() |
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,36 @@ | ||
from django.http import Http404 | ||
from rest_framework.generics import UpdateAPIView | ||
|
||
from api.core.authentication import ExporterAuthentication | ||
from api.core.permissions import IsExporterInOrganisation | ||
from api.applications.serializers.good import GoodOnApplicationQuantityValueSerializer | ||
from api.applications.models import BaseApplication, GoodOnApplication | ||
from api.exporter.applications.permissions import IsApplicationEditable | ||
|
||
|
||
class BaseExporterApplication: | ||
authentication_classes = (ExporterAuthentication,) | ||
permission_classes = (IsExporterInOrganisation,) | ||
|
||
def setup(self, request, *args, **kwargs): | ||
super().setup(request, *args, **kwargs) | ||
|
||
try: | ||
self.application = BaseApplication.objects.get(pk=self.kwargs["pk"]) | ||
except BaseApplication.DoesNotExist: | ||
raise Http404() | ||
|
||
def get_organisation(self): | ||
return self.application.organisation | ||
|
||
|
||
class ApplicationQuantityValueUpdateView(BaseExporterApplication, UpdateAPIView): | ||
permission_classes = ( | ||
IsExporterInOrganisation, | ||
IsApplicationEditable, | ||
) | ||
lookup_url_kwarg = "good_on_application_pk" | ||
serializer_class = GoodOnApplicationQuantityValueSerializer | ||
|
||
def get_queryset(self): | ||
return GoodOnApplication.objects.filter(application_id=self.kwargs["pk"]) |