diff --git a/core/orgs/views.py b/core/orgs/views.py index bd9ee371..be5fe1aa 100644 --- a/core/orgs/views.py +++ b/core/orgs/views.py @@ -1,5 +1,6 @@ from django.db.models import Count from django.http import Http404 +from drf_yasg import openapi from drf_yasg.utils import swagger_auto_schema from pydash import get from rest_framework import mixins, status, generics @@ -30,10 +31,8 @@ TRUTHY = get_truthy_values() - -class OrganizationListView(BaseAPIView, - ListWithHeadersMixin, - mixins.CreateModelMixin): +class OrganizationListView(BaseAPIView, ListWithHeadersMixin, mixins.CreateModelMixin): + model = Organization queryset = Organization.objects.filter(is_active=True) es_fields = Organization.es_fields @@ -76,7 +75,16 @@ def get_serializer_class(self): return OrganizationListSerializer - @swagger_auto_schema(manual_parameters=[org_no_members_param]) + @swagger_auto_schema( + manual_parameters=[ + openapi.Parameter(NO_MEMBERS, openapi.IN_QUERY, description="Filter organizations with no members", type=openapi.TYPE_BOOLEAN), + openapi.Parameter('UPDATED_SINCE_PARAM', openapi.IN_QUERY, description="Filter by update date", type=openapi.TYPE_STRING, format=openapi.FORMAT_DATETIME), + openapi.Parameter(UPDATED_BY_USERNAME_PARAM, openapi.IN_QUERY, description="Filter Orgs by the update by user", type=openapi.TYPE_STRING), + openapi.Parameter('verbose', openapi.IN_QUERY, description="Include verbose details", type=openapi.TYPE_BOOLEAN, default=False), + ], + + responses={status.HTTP_200_OK: OrganizationListSerializer(many=True)} + ) def get(self, request, *args, **kwargs): return self.list(request, *args, **kwargs) @@ -106,7 +114,6 @@ class OrganizationBaseView(BaseAPIView, RetrieveAPIView, DestroyAPIView): model = Organization queryset = Organization.objects.filter(is_active=True) - class OrganizationLogoView(OrganizationBaseView, BaseLogoView): serializer_class = OrganizationDetailSerializer @@ -115,7 +122,7 @@ def get_permissions(self): return [HasPrivateAccess(), ] return [CanViewConceptDictionary(), ] - + class OrganizationOverviewView(OrganizationBaseView, RetrieveAPIView, UpdateAPIView): serializer_class = OrganizationOverviewSerializer @@ -128,7 +135,7 @@ def get_permissions(self): def get_queryset(self): return super().get_queryset().filter(mnemonic=self.kwargs['org']) - + class OrganizationDetailView(OrganizationBaseView, mixins.UpdateModelMixin, mixins.CreateModelMixin, TaskMixin): def get_permissions(self): @@ -170,14 +177,14 @@ def destroy(self, request, *args, **kwargs): return result return Response(status=status.HTTP_204_NO_CONTENT) - + class OrganizationClientConfigsView(ResourceClientConfigsView): lookup_field = 'org' model = Organization queryset = Organization.objects.filter(is_active=True) permission_classes = (CanViewConceptDictionary, ) - + class OrganizationMemberView(generics.GenericAPIView): userprofile = None @@ -225,6 +232,7 @@ def put(self, request, **kwargs): # pylint: disable=unused-argument return Response(status=status.HTTP_204_NO_CONTENT) + def delete(self, request, **kwargs): # pylint: disable=unused-argument if not request.user.is_staff and not self.user_in_org: return Response(status=status.HTTP_403_FORBIDDEN) @@ -235,8 +243,7 @@ def delete(self, request, **kwargs): # pylint: disable=unused-argument self.userprofile.save() return Response(status=status.HTTP_204_NO_CONTENT) - - + class OrganizationResourceAbstractListView: def get_queryset(self): username = self.kwargs.get('user', None) @@ -252,8 +259,7 @@ def get_queryset(self): class OrganizationSourceListView(OrganizationResourceAbstractListView, SourceListView): pass - - + class OrganizationCollectionListView(OrganizationResourceAbstractListView, CollectionListView): pass @@ -286,6 +292,7 @@ def retrieve(self, request, *args, **kwargs): return Response({'detail': NOT_FOUND}, status=status.HTTP_404_NOT_FOUND) + def update(self, request, **kwargs): # pylint: disable=arguments-differ key = kwargs.get('extra') value = request.data.get(key)