From 0812c4232a73785b8b6a68920b5c6d26f5f97d09 Mon Sep 17 00:00:00 2001 From: albertoleoncio Date: Tue, 2 Jul 2024 21:55:08 -0300 Subject: [PATCH 1/3] feat: Add validation for tag id in UsersByTagViewSet --- users/views.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/users/views.py b/users/views.py index 638f38b..31b255f 100644 --- a/users/views.py +++ b/users/views.py @@ -105,8 +105,12 @@ class UsersByTagViewSet(viewsets.ReadOnlyModelViewSet): serializer_class = ProfileSerializer def retrieve(self, request, *args, **kwargs): - tag_type = self.kwargs['tag_type'] - tag_id = self.kwargs['tag_id'] + tag_type = self.kwargs.get('tag_type') + tag_id = self.kwargs.get('tag_id') + + if tag_type and not tag_id: + response = {'message': 'Please provide a valid tag id.'} + return Response(response, status=status.HTTP_400_BAD_REQUEST) if tag_type == 'skill': known_users = Profile.objects.filter(skills_known=tag_id) @@ -136,5 +140,5 @@ def retrieve(self, request, *args, **kwargs): return Response(data) def list(self, request, *args, **kwargs): - response = {'message': 'Please provide a tag type and a tag id.'} + response = {'message': 'Please provide a tag type and a tag id. Options are: skill, language, territory, project, affiliation.'} return Response(response, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file From 297355e839c975e56518d4beb2e4e3dc29e7c523 Mon Sep 17 00:00:00 2001 From: albertoleoncio Date: Tue, 2 Jul 2024 21:56:17 -0300 Subject: [PATCH 2/3] refactor: Update router registration for list_affiliation in CapX/urls.py --- CapX/urls.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CapX/urls.py b/CapX/urls.py index 185dc5d..879de7c 100644 --- a/CapX/urls.py +++ b/CapX/urls.py @@ -42,7 +42,7 @@ # Alternative version of views, read-only and only returns the __str__ with the id as the key router.register('list_language', ListLanguageViewSet, basename='list_language') -router.register('list_organizations', ListOrganizationViewSet, basename='list_organizations') +router.register('list_affiliation', ListOrganizationViewSet, basename='list_affiliation') router.register('list_skills', ListSkillViewSet, basename='list_skills') router.register('list_territory', ListTerritoryViewSet, basename='list_territory') router.register('list_wikimedia_project', ListWikimediaProjectViewSet, basename='list_wikimedia_project') From ff10ec3a9837cf1d0de98b1204e232bb148f3fce Mon Sep 17 00:00:00 2001 From: albertoleoncio Date: Tue, 2 Jul 2024 21:57:03 -0300 Subject: [PATCH 3/3] feat: Update UsersByTagViewSet to include wikimedia_project tag type --- users/views.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/users/views.py b/users/views.py index 31b255f..233fe34 100644 --- a/users/views.py +++ b/users/views.py @@ -98,7 +98,7 @@ def list(self, request, *args, **kwargs): return Response(response, status=status.HTTP_400_BAD_REQUEST) -# Class to list users by "tags" (skills, languages, territories, projects, affiliation) with format /tags/// +# Class to list users by "tags" (skills, languages, territories, wikimedia_project, affiliation) with format /tags/// # Example: /tags/project/1/ class UsersByTagViewSet(viewsets.ReadOnlyModelViewSet): queryset = Profile.objects.all() @@ -127,7 +127,7 @@ def retrieve(self, request, *args, **kwargs): elif tag_type == 'territory': users = Profile.objects.filter(territory=tag_id) data = [{'id': user.id, 'display_name': user.display_name, 'username': user.user.username, 'profile_image': user.profile_image} for user in users] - elif tag_type == 'project': + elif tag_type == 'wikimedia_project': users = Profile.objects.filter(wikimedia_project=tag_id) data = [{'id': user.id, 'display_name': user.display_name, 'username': user.user.username, 'profile_image': user.profile_image} for user in users] elif tag_type == 'affiliation': @@ -140,5 +140,5 @@ def retrieve(self, request, *args, **kwargs): return Response(data) def list(self, request, *args, **kwargs): - response = {'message': 'Please provide a tag type and a tag id. Options are: skill, language, territory, project, affiliation.'} + response = {'message': 'Please provide a tag type and a tag id. Options are: skill, language, territory, wikimedia_project, affiliation.'} return Response(response, status=status.HTTP_400_BAD_REQUEST) \ No newline at end of file