Skip to content

Commit

Permalink
fix: show projects that a user is added to
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamedelabbas1996 committed Jan 20, 2025
1 parent d7c827f commit 2778a59
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions ami/users/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ class CurrentUserSerializer(UserSerializer):
"""

email = serializers.EmailField(read_only=True)
projects = ProjectNestedSerializer(many=True, read_only=True)
projects = serializers.SerializerMethodField()

def get_projects(self, user):
# return only projects that the current user is involved in as an owner or a user
current_user = self.context["request"].user
if current_user == user:
projects = Project.objects.filter(Q(owner=user) | Q(users=user)).distinct()
return ProjectNestedSerializer(projects)
return ProjectNestedSerializer(projects, many=True, context={"request": self.context["request"]}).data
return []

class Meta(UserSerializer.Meta):
Expand Down

0 comments on commit 2778a59

Please sign in to comment.