From 50171e6435e6082dad603cbffa46f8a875ce4e96 Mon Sep 17 00:00:00 2001 From: David Code Howard Date: Thu, 2 Nov 2023 15:05:48 -0400 Subject: [PATCH 1/3] test: Remove duplicate memberships in searching for projects Test that the projects query works --- .../tests/graphql/test_projects_query.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/terraso_backend/tests/graphql/test_projects_query.py b/terraso_backend/tests/graphql/test_projects_query.py index 5a5144703..2e9745484 100644 --- a/terraso_backend/tests/graphql/test_projects_query.py +++ b/terraso_backend/tests/graphql/test_projects_query.py @@ -14,7 +14,10 @@ # along with this program. If not, see https://www.gnu.org/licenses/. import pytest from graphene_django.utils.testing import graphql_query +from mixer.backend.django import mixer +from tests.utils import match_json +from apps.core.models import User from apps.project_management.models.projects import Project pytestmark = pytest.mark.django_db @@ -61,3 +64,14 @@ def test_query_by_non_member(client, project): assert "errors" not in payload assert len(payload["data"]["projects"]["edges"]) == 0 assert payload["data"]["projects"]["totalCount"] == 0 + + +def test_query_with_deleted_member(client, project): + user = mixer.blend(User) + project.add_manager(user) + project.remove_user(user) + project.add_viewer(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)) == 1 From 960947e82cb689a9a2418978f65bd9b51b0abc03 Mon Sep 17 00:00:00 2001 From: David Code Howard Date: Thu, 2 Nov 2023 15:07:54 -0400 Subject: [PATCH 2/3] fix: Remove deleted memberships for project for queryset --- .../apps/project_management/graphql/projects.py | 5 ++++- terraso_backend/tests/graphql/test_projects_query.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/terraso_backend/apps/project_management/graphql/projects.py b/terraso_backend/apps/project_management/graphql/projects.py index 7d458b198..d5c5b6616 100644 --- a/terraso_backend/apps/project_management/graphql/projects.py +++ b/terraso_backend/apps/project_management/graphql/projects.py @@ -157,7 +157,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): diff --git a/terraso_backend/tests/graphql/test_projects_query.py b/terraso_backend/tests/graphql/test_projects_query.py index 2e9745484..61370f37a 100644 --- a/terraso_backend/tests/graphql/test_projects_query.py +++ b/terraso_backend/tests/graphql/test_projects_query.py @@ -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) @@ -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 From d0b97541a25cde119815f4048c4c8a7a26502d2b Mon Sep 17 00:00:00 2001 From: ajabeckett <31599074+ajabeckett@users.noreply.github.com> Date: Thu, 2 Nov 2023 09:54:02 -0700 Subject: [PATCH 3/3] fix: add missing sitenote migration (#947) * fix: add missing sitenote migration * fix: linting * fix: add copyright * Update terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py --------- Co-authored-by: Paul Schreiber --- ...at_sitenote_deleted_by_cascade_and_more.py | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py diff --git a/terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py b/terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py new file mode 100644 index 000000000..f4a2a3bfc --- /dev/null +++ b/terraso_backend/apps/project_management/migrations/0025_sitenote_deleted_at_sitenote_deleted_by_cascade_and_more.py @@ -0,0 +1,47 @@ +# Copyright © 2023 Technology Matters +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as published +# by the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see https://www.gnu.org/licenses/. + +# Generated by Django 4.2.6 on 2023-10-30 16:03 + +import uuid + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("project_management", "0024_project_measurement_units"), + ] + + operations = [ + migrations.AddField( + model_name="sitenote", + name="deleted_at", + field=models.DateTimeField(db_index=True, editable=False, null=True), + ), + migrations.AddField( + model_name="sitenote", + name="deleted_by_cascade", + field=models.BooleanField(default=False, editable=False), + ), + migrations.RemoveField(model_name="sitenote", name="id"), + migrations.AddField( + model_name="sitenote", + name="id", + field=models.UUIDField( + default=uuid.uuid4, editable=False, primary_key=True, serialize=False + ), + ), + ]