From 59d1fe4a9abafeeeeacbeb61bf34c6cdc12a503c Mon Sep 17 00:00:00 2001 From: Fazliddin Abdurahimov Date: Wed, 6 Aug 2025 09:47:41 +0500 Subject: [PATCH] fix: part of functionality has taken from ContractView to ContractRelationsViewSet --- README.MD | 2 +- .../serializers/contracts/contracts.py | 2 -- core/apps/contracts/urls.py | 2 +- core/apps/contracts/views/contracts.py | 20 ++++++++++++++----- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/README.MD b/README.MD index b6a4a07..aabe50e 100644 --- a/README.MD +++ b/README.MD @@ -95,7 +95,7 @@ PATCH /banks/ # admin # ok GET /contracts # admin # ok -POST /contracts # user # remake +POST /contracts # user # ok GET /contracts/ # admin # ok DELETE /contracts/ # admin # ok PATCH /contracts/ # admin # ok diff --git a/core/apps/contracts/serializers/contracts/contracts.py b/core/apps/contracts/serializers/contracts/contracts.py index 876059f..2abacaf 100644 --- a/core/apps/contracts/serializers/contracts/contracts.py +++ b/core/apps/contracts/serializers/contracts/contracts.py @@ -154,5 +154,3 @@ class CreateContractSerializer(BaseContractSerializer): attached_files.save() # type: ignore return contract - - diff --git a/core/apps/contracts/urls.py b/core/apps/contracts/urls.py index 372d7e7..cec9cf8 100644 --- a/core/apps/contracts/urls.py +++ b/core/apps/contracts/urls.py @@ -7,11 +7,11 @@ router = DefaultRouter() router.register(r"contract-attached-files", views.ContractAttachedFileView, "contract-attached-files") # type: ignore router.register(r"contracts", views.ContractView, "contracts") # type: ignore +router.register(r"contracts", views.ContractRelationsViewSet, "contract-relations") # type: ignore router.register(r"contract-file-contents", views.ContractFileContentView, "contract-file-contents") # type: ignore router.register(r"contract-owners", views.ContractOwnerView, "contract-owners") # type: ignore router.register(r"contract-owners", views.ContractOwnerFileViewSet, "contract-owner-files") # type: ignore - urlpatterns = [ # type: ignore path("", include(router.urls)), # type: ignore path( diff --git a/core/apps/contracts/views/contracts.py b/core/apps/contracts/views/contracts.py index 1b59015..3b26d0e 100644 --- a/core/apps/contracts/views/contracts.py +++ b/core/apps/contracts/views/contracts.py @@ -38,11 +38,9 @@ class ContractView(BaseViewSetMixin, ModelViewSet): action_permission_classes = { # type: ignore "list": [IsAdminUser], "retrieve": [IsAdminUser], - "create": [IsAuthenticated], + "create": [AllowAny], "update": [IsAdminUser], "destroy": [IsAdminUser], - "list_file": [AllowAny], - "list_owner": [AllowAny], } action_serializer_class = { # type: ignore "list": ListContractSerializer, @@ -50,8 +48,6 @@ class ContractView(BaseViewSetMixin, ModelViewSet): "create": CreateContractSerializer, "update": UpdateContractSerializer, "destroy": DestroyContractSerializer, - "list_file": ListContractAttachedFileSerializer, - "list_owner": RetrieveContractOwnerSerializer, } def create( @@ -63,6 +59,20 @@ class ContractView(BaseViewSetMixin, ModelViewSet): #! TODO: checkout if user has access to create new contract. return super().create(request, *args, **kwargs) # type: ignore + +class ContractRelationsViewSet(BaseViewSetMixin, ModelViewSet): + queryset = ContractModel.objects.all() + permission_classes = [AllowAny] + + action_permission_classes = { + "list_file": [AllowAny], + "list_owner": [AllowAny], + } + action_serializer_class = { # type: ignore + "list_file": ListContractAttachedFileSerializer, + "list_owner": RetrieveContractOwnerSerializer, + } + @extend_schema( summary="Get List Of Files", description="Get List Of Files"