Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Shareable resource #1104

Merged
merged 20 commits into from
Feb 19, 2024
Merged

feat: Shareable resource #1104

merged 20 commits into from
Feb 19, 2024

Conversation

josebui
Copy link
Contributor

@josebui josebui commented Jan 16, 2024

Description

  • Shareable resource file for Landscapes and groups

Checklist

  • Corresponding issue has been opened
  • New tests added

Related Issues

@josebui josebui self-assigned this Jan 16, 2024
@josebui josebui force-pushed the feat/shareable-resource branch 2 times, most recently from fc0ee33 to 25b9937 Compare February 7, 2024 20:47
@josebui josebui marked this pull request as ready for review February 7, 2024 20:59
Comment on lines 32 to 38
SHARE_ACCESS_ALL = "all"
SHARE_ACCESS_TARGET_MEMBERS = "target_members"
DEFAULT_SHARE_ACCESS = SHARE_ACCESS_TARGET_MEMBERS

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
SHARE_ACCESS_ALL = "all"
SHARE_ACCESS_TARGET_MEMBERS = "target_members"
DEFAULT_SHARE_ACCESS = SHARE_ACCESS_TARGET_MEMBERS
SHARE_ACCESS_TYPES = (
(SHARE_ACCESS_ALL, _("Anyone with the link")),
(SHARE_ACCESS_TARGET_MEMBERS, _("Only target members")),
SHARE_ACCESS_ALL = "all"
SHARE_ACCESS_MEMBERS = "target_members"
DEFAULT_SHARE_ACCESS = SHARE_ACCESS_MEMBERS
SHARE_ACCESS_TYPES = (
(SHARE_ACCESS_ALL, _("Anyone with the link")),
(SHARE_ACCESS_MEMBERS, _("Only members")),

@classmethod
def get_share_access_from_text(cls, share_access):
if not share_access:
return cls.SHARE_ACCESS_TARGET_MEMBERS
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return cls.SHARE_ACCESS_TARGET_MEMBERS
return cls.SHARE_ACCESS_MEMBERS


share_access_all = Q(share_access=SharedResource.SHARE_ACCESS_ALL)
share_access_members = Q(
Q(share_access=SharedResource.SHARE_ACCESS_TARGET_MEMBERS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Q(share_access=SharedResource.SHARE_ACCESS_TARGET_MEMBERS)
Q(share_access=SharedResource.SHARE_ACCESS_MEMBERS)

if shared_resource.share_access == SharedResource.SHARE_ACCESS_ALL:
return True

if shared_resource.share_access == SharedResource.SHARE_ACCESS_TARGET_MEMBERS:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if shared_resource.share_access == SharedResource.SHARE_ACCESS_TARGET_MEMBERS:
if shared_resource.share_access == SharedResource.SHARE_ACCESS_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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
get_url_mock, logged_client, shared_resource_data_entry_shared_target_members_user_1
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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

@@ -51,3 +62,90 @@ def resolve_source(self, info, **kwargs):

def resolve_target(self, info, **kwargs):
return self.target

def resolve_download_url(self, info, **kwargs):
return f"{settings.API_ENDPOINT}/shared-data/download/{self.share_uuid}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return f"{settings.API_ENDPOINT}/shared-data/download/{self.share_uuid}"
return f"{settings.API_ENDPOINT}/download/{self.share_uuid}"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@paulschreiber This is the API endpoint, the urls are organized by app, so we can't avoid the shared-data without losing that structure


for data_entry in data_entries:
assert data_entry.name in entries_result
uuid = data_entry.shared_resources.all()[0].share_uuid
download_url = f"{settings.API_ENDPOINT}/shared-data/download/{uuid}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue: a helper like resolve_download_url every time you generate URLs of this form.


for data_entry in data_entries:
assert data_entry.name in entries_result
uuid = data_entry.shared_resources.all()[0].share_uuid
download_url = f"{settings.API_ENDPOINT}/shared-data/download/{uuid}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
download_url = f"{settings.API_ENDPOINT}/shared-data/download/{uuid}"
download_url = f"{settings.API_ENDPOINT}/download/{uuid}"

@josebui josebui force-pushed the feat/shareable-resource branch from 8401669 to 109fb23 Compare February 15, 2024 22:15
@josebui josebui merged commit e0f0896 into main Feb 19, 2024
7 checks passed
@josebui josebui deleted the feat/shareable-resource branch February 19, 2024 14:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants