Skip to content

Commit

Permalink
fix: Renamed target_members to members
Browse files Browse the repository at this point in the history
  • Loading branch information
josebui committed Feb 15, 2024
1 parent aa74c4a commit 109fb23
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright © 2024 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/.

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("core", "0050_sharedresource_remove_none"),
]

operations = [
migrations.RunSQL(
sql="UPDATE core_sharedresource SET share_access ='members' WHERE share_access='target_members';"
),
]
10 changes: 5 additions & 5 deletions terraso_backend/apps/core/models/shared_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class SharedResource(BaseModel):
"""

SHARE_ACCESS_ALL = "all"
SHARE_ACCESS_TARGET_MEMBERS = "target_members"
DEFAULT_SHARE_ACCESS = SHARE_ACCESS_TARGET_MEMBERS
SHARE_ACCESS_MEMBERS = "members"
DEFAULT_SHARE_ACCESS = SHARE_ACCESS_MEMBERS

SHARE_ACCESS_TYPES = (
(SHARE_ACCESS_ALL, _("Anyone with the link")),
(SHARE_ACCESS_TARGET_MEMBERS, _("Only target members")),
(SHARE_ACCESS_MEMBERS, _("Only members")),
)

source = GenericForeignKey("source_content_type", "source_object_id")
Expand Down Expand Up @@ -68,8 +68,8 @@ class Meta:
@classmethod
def get_share_access_from_text(cls, share_access):
if not share_access:
return cls.SHARE_ACCESS_TARGET_MEMBERS
return cls.SHARE_ACCESS_MEMBERS
lowered = share_access.lower()
if lowered == cls.SHARE_ACCESS_ALL:
return cls.SHARE_ACCESS_ALL
return cls.SHARE_ACCESS_TARGET_MEMBERS
return cls.SHARE_ACCESS_MEMBERS
2 changes: 1 addition & 1 deletion terraso_backend/apps/graphql/schema/shared_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def resolve_shared_resource(root, info, share_uuid=None):

share_access_all = Q(share_access=SharedResource.SHARE_ACCESS_ALL)
share_access_members = Q(
Q(share_access=SharedResource.SHARE_ACCESS_TARGET_MEMBERS)
Q(share_access=SharedResource.SHARE_ACCESS_MEMBERS)
& Q(Q(target_object_id__in=user_groups_ids) | Q(target_object_id__in=user_landscape_ids))
)

Expand Down
2 changes: 1 addition & 1 deletion terraso_backend/apps/shared_data/permission_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def allowed_to_download_data_entry_file(user, shared_resource):
if shared_resource.share_access == SharedResource.SHARE_ACCESS_ALL:
return True

if shared_resource.share_access == SharedResource.SHARE_ACCESS_TARGET_MEMBERS:
if shared_resource.share_access == SharedResource.SHARE_ACCESS_MEMBERS:
return is_target_member(user, target)


Expand Down
4 changes: 2 additions & 2 deletions terraso_backend/tests/graphql/test_shared_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def test_shared_resource_access_members(client_query, data_entries, users):
users[0].email, group_collaboration_roles.ROLE_MEMBER, CollaborationMembership.APPROVED
)

shared_resource.share_access = SharedResource.SHARE_ACCESS_TARGET_MEMBERS
shared_resource.share_access = SharedResource.SHARE_ACCESS_MEMBERS
shared_resource.save()

response = client_query(
Expand All @@ -83,7 +83,7 @@ def test_shared_resource_access_members_fail(client_query, data_entries, users):

shared_resource.target.membership_list.memberships.all().delete()

shared_resource.share_access = SharedResource.SHARE_ACCESS_TARGET_MEMBERS
shared_resource.share_access = SharedResource.SHARE_ACCESS_MEMBERS
shared_resource.save()

response = client_query(
Expand Down
8 changes: 4 additions & 4 deletions terraso_backend/tests/shared_data/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,15 @@ def shared_resource_data_entry_shared_all(users):


@pytest.fixture
def shared_resource_data_entry_shared_target_members(users):
def shared_resource_data_entry_shared_members(users):
creator = users[0]
creator_group = mixer.blend(Group)
creator_group.membership_list.save_membership(
creator.email, group_collaboration_roles.ROLE_MEMBER, CollaborationMembership.APPROVED
)
return mixer.blend(
SharedResource,
share_access=SharedResource.SHARE_ACCESS_TARGET_MEMBERS,
share_access=SharedResource.SHARE_ACCESS_MEMBERS,
share_uuid=uuid.uuid4(),
target=creator_group,
source=mixer.blend(
Expand All @@ -156,15 +156,15 @@ def shared_resource_data_entry_shared_target_members(users):


@pytest.fixture
def shared_resource_data_entry_shared_target_members_user_1(users):
def shared_resource_data_entry_shared_members_user_1(users):
creator = users[1]
creator_group = mixer.blend(Group)
creator_group.membership_list.save_membership(
creator.email, group_collaboration_roles.ROLE_MEMBER, CollaborationMembership.APPROVED
)
return mixer.blend(
SharedResource,
share_access=SharedResource.SHARE_ACCESS_TARGET_MEMBERS,
share_access=SharedResource.SHARE_ACCESS_MEMBERS,
share_uuid=uuid.uuid4(),
target=creator_group,
source=mixer.blend(
Expand Down
14 changes: 6 additions & 8 deletions terraso_backend/tests/shared_data/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,14 @@ def test_download_data_entry_file_shared_all(


@mock.patch("apps.shared_data.models.data_entries.data_entry_file_storage.url")
def test_download_data_entry_file_shared_target_members(
get_url_mock, logged_client, shared_resource_data_entry_shared_target_members
def test_download_data_entry_file_shared_members(
get_url_mock, logged_client, shared_resource_data_entry_shared_members
):
redirect_url = "https://example.org/s3_file.json"
get_url_mock.return_value = redirect_url
url = reverse(
"shared_data:download",
kwargs={
"shared_resource_uuid": shared_resource_data_entry_shared_target_members.share_uuid
},
kwargs={"shared_resource_uuid": shared_resource_data_entry_shared_members.share_uuid},
)
response = logged_client.get(url)

Expand All @@ -202,12 +200,12 @@ def test_download_data_entry_file_shared_target_members(


@mock.patch("apps.shared_data.models.data_entries.data_entry_file_storage.url")
def test_download_data_entry_file_shared_target_members_fail(
get_url_mock, logged_client, shared_resource_data_entry_shared_target_members_user_1
def test_download_data_entry_file_shared_members_fail(
get_url_mock, logged_client, shared_resource_data_entry_shared_members_user_1
):
redirect_url = "https://example.org/s3_file.json"
get_url_mock.return_value = redirect_url
share_uuid = shared_resource_data_entry_shared_target_members_user_1.share_uuid
share_uuid = shared_resource_data_entry_shared_members_user_1.share_uuid
url = reverse(
"shared_data:download",
kwargs={"shared_resource_uuid": share_uuid},
Expand Down

0 comments on commit 109fb23

Please sign in to comment.