Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify the teams endpoints removing unnecessary GET endpoints #1098

Merged
merged 2 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
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
11 changes: 10 additions & 1 deletion docker-app/qfieldcloud/core/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,17 +553,26 @@ 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)
representation["team"] = instance.teamname

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()
Expand Down
3 changes: 3 additions & 0 deletions docker-app/qfieldcloud/core/tests/test_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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": [],
},
],
)
Expand All @@ -329,6 +331,7 @@ def test_org_member_role_member_can_retrieve_team_details(self):
{
"team": self.t1.teamname,
"organization": self.o1.username,
"members": [],
},
)

Expand Down
4 changes: 2 additions & 2 deletions docker-app/qfieldcloud/core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
),
path(
"organizations/<str:organization_name>/teams/<str:team_name>/members/<str:member_username>/",
teams_views.GetUpdateDestroyTeamMemberView.as_view(),
name="team_member_retrieve_update_destroy",
teams_views.DestroyTeamMemberView.as_view(),
name="team_member_destroy",
),
]
15 changes: 1 addition & 14 deletions docker-app/qfieldcloud/core/views/teams_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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/<str:organization_name>/team/<str:team_name>/members/"
"""
Expand Down Expand Up @@ -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"),
Expand Down
Loading