From 686a2d83d9c84fa4bfc26b4c4c32c7c9e760e496 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 30 Dec 2024 01:13:59 +0200 Subject: [PATCH 1/2] List team members when we get the team data --- docker-app/qfieldcloud/core/serializers.py | 11 ++++++++++- docker-app/qfieldcloud/core/tests/test_team.py | 3 +++ 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/docker-app/qfieldcloud/core/serializers.py b/docker-app/qfieldcloud/core/serializers.py index bf25e2f16..b7f688591 100644 --- a/docker-app/qfieldcloud/core/serializers.py +++ b/docker-app/qfieldcloud/core/serializers.py @@ -553,10 +553,11 @@ class LatestPackageSerializer(serializers.Serializer): class TeamSerializer(serializers.ModelSerializer): organization = serializers.StringRelatedField(source="team_organization") team = serializers.CharField(required=True, allow_blank=False, source="username") + members = serializers.SerializerMethodField() class Meta: model = Team - fields = ("team", "organization") + fields = ("team", "organization", "members") def to_representation(self, instance: Team) -> dict[str, Any]: representation = super().to_representation(instance) @@ -564,6 +565,14 @@ def to_representation(self, instance: Team) -> dict[str, Any]: return representation + def get_members(self, obj: Team) -> list[str]: + return [ + m["member__username"] + for m in TeamMember.objects.filter( + team=obj, + ).values("member__username") + ] + class TeamMemberSerializer(serializers.ModelSerializer): member = serializers.CharField() diff --git a/docker-app/qfieldcloud/core/tests/test_team.py b/docker-app/qfieldcloud/core/tests/test_team.py index 3f6d17fb0..413990980 100644 --- a/docker-app/qfieldcloud/core/tests/test_team.py +++ b/docker-app/qfieldcloud/core/tests/test_team.py @@ -306,10 +306,12 @@ def test_org_member_role_member_can_list_teams(self): { "team": self.t1.teamname, "organization": self.o1.username, + "members": [], }, { "team": self.t2.teamname, "organization": self.o1.username, + "members": [], }, ], ) @@ -329,6 +331,7 @@ def test_org_member_role_member_can_retrieve_team_details(self): { "team": self.t1.teamname, "organization": self.o1.username, + "members": [], }, ) From 5c8703fe03ecdcc24c927e1f2afa923ec92cc3e7 Mon Sep 17 00:00:00 2001 From: Ivan Ivanov Date: Mon, 30 Dec 2024 01:14:41 +0200 Subject: [PATCH 2/2] No need to retrieve or update a specific team member --- docker-app/qfieldcloud/core/urls.py | 4 ++-- docker-app/qfieldcloud/core/views/teams_views.py | 15 +-------------- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/docker-app/qfieldcloud/core/urls.py b/docker-app/qfieldcloud/core/urls.py index 381ea0063..1ae88a8fc 100644 --- a/docker-app/qfieldcloud/core/urls.py +++ b/docker-app/qfieldcloud/core/urls.py @@ -113,7 +113,7 @@ ), path( "organizations//teams//members//", - teams_views.GetUpdateDestroyTeamMemberView.as_view(), - name="team_member_retrieve_update_destroy", + teams_views.DestroyTeamMemberView.as_view(), + name="team_member_destroy", ), ] diff --git a/docker-app/qfieldcloud/core/views/teams_views.py b/docker-app/qfieldcloud/core/views/teams_views.py index 425bea120..4850730d8 100644 --- a/docker-app/qfieldcloud/core/views/teams_views.py +++ b/docker-app/qfieldcloud/core/views/teams_views.py @@ -178,7 +178,7 @@ def perform_create(self, serializer: TeamSerializer) -> None: get=extend_schema(description="Retrieve, update, or delete a team member"), delete=extend_schema(description="Delete a team member"), ) -class GetUpdateDestroyTeamMemberView(generics.RetrieveDestroyAPIView): +class DestroyTeamMemberView(generics.DestroyAPIView): """ View to handle adding and listing team members. --> organizations//team//members/" """ @@ -217,19 +217,6 @@ def get_full_team_name(self) -> str: return Team.format_team_name(organization_name, team_name) - def perform_update(self, serializer: TeamMemberSerializer) -> None: - """ - Update logic for the team member. - """ - team_member = self.get_object() - new_username = self.request.data.get("member") - - user_member = team_member.member - user_member.username = new_username - user_member.save() - - serializer.save() - @extend_schema_view( get=extend_schema(description="List all members of a team"),