Skip to content

Commit

Permalink
fix: Remove deleted memberships for project for queryset
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Nov 2, 2023
1 parent 0f5ecb7 commit 15407c0
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion terraso_backend/apps/project_management/graphql/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,10 @@ def resolve_seen(self, info):
def get_queryset(cls, queryset, info):
# limit queries to membership lists of projects to which the user belongs
user_pk = getattr(info.context.user, "pk", None)
return queryset.filter(membership_list__memberships__user_id=user_pk)
return queryset.filter(
membership_list__memberships__user_id=user_pk,
membership_list__memberships__deleted_at__isnull=True,
)


class ProjectPrivacy(graphene.Enum):
Expand Down
12 changes: 11 additions & 1 deletion terraso_backend/tests/graphql/test_projects_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def test_query_by_non_member(client, project):
assert payload["data"]["projects"]["totalCount"] == 0


def test_query_with_deleted_member(client, project):
def test_project_query_with_deleted_member(client, project):
user = mixer.blend(User)
project.add_manager(user)
project.remove_user(user)
Expand All @@ -75,3 +75,13 @@ def test_query_with_deleted_member(client, project):
payload = graphql_query(PROJECT_QUERY, client=client).json()
assert "errors" not in payload
assert len(match_json("data.projects.edges[*]", payload)) == 1


def test_project_query_with_deleted_member_not_in_project(client, project):
user = mixer.blend(User)
project.add_manager(user)
project.remove_user(user)
client.force_login(user)
payload = graphql_query(PROJECT_QUERY, client=client).json()
assert "errors" not in payload
assert len(match_json("data.projects.edges[*]", payload)) == 0

0 comments on commit 15407c0

Please sign in to comment.