Skip to content

Commit

Permalink
fix: Use user id to filter membership to work with anonymous users (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui authored Feb 22, 2024
1 parent b0627b3 commit a8b4240
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
2 changes: 1 addition & 1 deletion terraso_backend/apps/collaboration/models/memberships.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ def is_approved_member(self, user: User) -> bool:
return self.approved_members.filter(id=user.id).exists()

def is_member(self, user: User) -> bool:
return self.memberships.filter(user=user).exists()
return self.memberships.filter(user__id=user.id).exists()

def get_membership(self, user: User):
if not user:
Expand Down
39 changes: 39 additions & 0 deletions terraso_backend/tests/graphql/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,42 @@ def test_project_groups_not_included_in_query(client_query, project):
)
total_count = reponse.json()["data"]["groups"]["totalCount"]
assert total_count == 0


def test_groups_memberships_not_included_for_anonymous_user(client_query_no_token, groups_closed):
reponse = client_query_no_token(
"""
{groups {
totalCount
edges {
node {
slug
membershipList {
memberships {
edges {
node {
id
}
}
}
}
}
}
}}
"""
)
json_response = reponse.json()

assert "errors" not in json_response

total_count = json_response["data"]["groups"]["totalCount"]
assert total_count == 2

assert (
len(
json_response["data"]["groups"]["edges"][0]["node"]["membershipList"]["memberships"][
"edges"
]
)
== 0
)

0 comments on commit a8b4240

Please sign in to comment.