Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 21 additions & 14 deletions core/orgs/views.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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

Expand All @@ -115,7 +122,7 @@ def get_permissions(self):
return [HasPrivateAccess(), ]

return [CanViewConceptDictionary(), ]


class OrganizationOverviewView(OrganizationBaseView, RetrieveAPIView, UpdateAPIView):
serializer_class = OrganizationOverviewSerializer
Expand All @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -252,8 +259,7 @@ def get_queryset(self):

class OrganizationSourceListView(OrganizationResourceAbstractListView, SourceListView):
pass



class OrganizationCollectionListView(OrganizationResourceAbstractListView, CollectionListView):
pass

Expand Down Expand Up @@ -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)
Expand Down