|
25 | 25 | from rest_framework.decorators import action |
26 | 26 | from rest_framework.filters import OrderingFilter |
27 | 27 | from rest_framework.parsers import JSONParser |
28 | | -from rest_framework.permissions import IsAuthenticated, IsAuthenticatedOrReadOnly |
| 28 | +from rest_framework.permissions import ( |
| 29 | + IsAuthenticated, |
| 30 | + IsAuthenticatedOrReadOnly, |
| 31 | +) |
29 | 32 | from rest_framework.response import Response |
30 | 33 | from rest_framework.serializers import BooleanField |
31 | 34 | from rest_framework.views import APIView |
| 35 | +from services.google.models import GoogleAccount, GoogleGroup |
| 36 | +from services.google.tasks import ( |
| 37 | + create_google_account, |
| 38 | + create_google_group, |
| 39 | + suspend_google_account, |
| 40 | + update_google_account, |
| 41 | + update_google_group, |
| 42 | +) |
| 43 | +from services.keycloak.exceptions import KeycloakAccountNotFound |
| 44 | +from services.keycloak.interface import KeycloakService |
32 | 45 |
|
33 | 46 | from apps.commons.filters import UnaccentSearchFilter |
34 | 47 | from apps.commons.models import GroupData |
35 | 48 | from apps.commons.permissions import IsOwner, ReadOnly, WillBeOwner |
36 | | -from apps.commons.serializers import EmailAddressSerializer, RetrieveUpdateModelViewSet |
| 49 | +from apps.commons.serializers import ( |
| 50 | + EmailAddressSerializer, |
| 51 | + RetrieveUpdateModelViewSet, |
| 52 | +) |
37 | 53 | from apps.commons.utils import map_action_to_permission |
38 | 54 | from apps.commons.views import DetailOnlyViewsetMixin, MultipleIDViewsetMixin |
39 | 55 | from apps.files.models import Image |
40 | 56 | from apps.files.views import ImageStorageView |
41 | 57 | from apps.organizations.models import Organization |
42 | 58 | from apps.organizations.permissions import HasOrganizationPermission |
43 | | -from apps.projects.serializers import ProjectLightSerializer |
| 59 | +from apps.projects.serializers import LocationSerializer, ProjectLightSerializer |
44 | 60 | from apps.skills.models import Skill |
45 | | -from services.google.models import GoogleAccount, GoogleGroup |
46 | | -from services.google.tasks import ( |
47 | | - create_google_account, |
48 | | - create_google_group, |
49 | | - suspend_google_account, |
50 | | - update_google_account, |
51 | | - update_google_group, |
52 | | -) |
53 | | -from services.keycloak.exceptions import KeycloakAccountNotFound |
54 | | -from services.keycloak.interface import KeycloakService |
55 | 61 |
|
56 | 62 | from .exceptions import EmailTypeMissingError, PermissionNotFoundError |
57 | 63 | from .filters import PeopleGroupFilter, UserFilter |
@@ -839,6 +845,23 @@ def similars(self, request, *args, **kwargs): |
839 | 845 | ) |
840 | 846 | return self.get_paginated_response(data.data) |
841 | 847 |
|
| 848 | + @action( |
| 849 | + detail=True, |
| 850 | + methods=["GET"], |
| 851 | + url_path="locations", |
| 852 | + permission_classes=[ReadOnly], |
| 853 | + ) |
| 854 | + def locations(self, request, *args, **kwargs): |
| 855 | + group = self.get_object() |
| 856 | + modules_manager = group.get_related_module() |
| 857 | + modules = modules_manager(group, request.user) |
| 858 | + queryset = modules.locations() |
| 859 | + |
| 860 | + return Response( |
| 861 | + LocationSerializer(queryset, many=True, context={"request": request}).data, |
| 862 | + status=status.HTTP_200_OK, |
| 863 | + ) |
| 864 | + |
842 | 865 |
|
843 | 866 | @extend_schema( |
844 | 867 | parameters=[OpenApiParameter("people_group_id", str, OpenApiParameter.PATH)] |
|
0 commit comments