-
Notifications
You must be signed in to change notification settings - Fork 4
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
feat: Shareable resource #1104
Conversation
fc0ee33
to
25b9937
Compare
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")), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return f"{settings.API_ENDPOINT}/shared-data/download/{self.share_uuid}" | |
return f"{settings.API_ENDPOINT}/download/{self.share_uuid}" |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
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}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
download_url = f"{settings.API_ENDPOINT}/shared-data/download/{uuid}" | |
download_url = f"{settings.API_ENDPOINT}/download/{uuid}" |
8401669
to
109fb23
Compare
Description
Checklist
Related Issues