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

[21.09] Fix private history publishing #13056

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions lib/galaxy/managers/histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,21 @@ def is_history_shared_with(self, history, user) -> bool:
)
).first())

def make_members_public(self, trans, item):
""" Make the non-purged datasets in history public.
Performs permissions check.
"""
for hda in item.activatable_datasets:
dataset = hda.dataset
if not trans.app.security_agent.dataset_is_public(dataset):
if trans.app.security_agent.can_manage_dataset(trans.user.all_roles(), dataset):
try:
trans.app.security_agent.make_dataset_public(hda.dataset)
except Exception:
log.warning(f"Unable to make dataset with id: {dataset.id} public")
else:
log.warning(f"User without permissions tried to make dataset with id: {dataset.id} public")


class HistoryExportView:

Expand Down
16 changes: 16 additions & 0 deletions lib/galaxy/managers/sharable.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,14 @@ def get_sharing_extra_information(
to provide the extra information, otherwise, it will be None by default."""
return None

def make_members_public(self, trans, item):
""" Make potential elements of this item public.

This method must be overridden in managers that need to change permissions of internal elements
contained associated with the given item.
"""
pass

def update_current_sharing_with_users(self, item, new_users_shared_with: Set[User], flush=True):
"""Updates the currently list of users this item is shared with by adding new
users and removing missing ones."""
Expand Down Expand Up @@ -672,7 +680,11 @@ def sharing(self, trans, id: EncodedDatabaseIdField) -> SharingStatus:
return self._get_sharing_status(trans, item)

def enable_link_access(self, trans, id: EncodedDatabaseIdField) -> SharingStatus:
"""Makes this item accessible by link.
If this item contains other elements they will be publicly accessible too.
"""
item = self._get_item_by_id(trans, id)
self.manager.make_members_public(trans, item)
self.manager.make_importable(item)
return self._get_sharing_status(trans, item)

Expand All @@ -682,7 +694,11 @@ def disable_link_access(self, trans, id: EncodedDatabaseIdField) -> SharingStatu
return self._get_sharing_status(trans, item)

def publish(self, trans, id: EncodedDatabaseIdField) -> SharingStatus:
"""Makes this item publicly accessible.
If this item contains other elements they will be publicly accessible too.
"""
item = self._get_item_by_id(trans, id)
self.manager.make_members_public(trans, item)
self.manager.publish(item)
return self._get_sharing_status(trans, item)

Expand Down
22 changes: 22 additions & 0 deletions lib/galaxy_test/api/test_histories.py
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,28 @@ def test_sharing_with_duplicated_users(self):
assert len(sharing_response["users_shared_with"]) == 1
assert sharing_response["users_shared_with"][0]["id"] == target_user_id

def test_sharing_private_history_makes_datasets_public(self):
history_id = self.dataset_populator.new_history()
hda = self.dataset_populator.new_dataset(history_id)
hda_id = hda["id"]

self.dataset_populator.make_private(history_id, hda_id)

# Other users cannot access the dataset
with self._different_user():
show_response = self._get(f"datasets/{hda_id}")
self._assert_status_code_is(show_response, 400)

sharing_response = self._set_resource_sharing(history_id, "publish")
assert sharing_response["published"] is True

# Other users can access the dataset after publishing
with self._different_user():
show_response = self._get(f"datasets/{hda_id}")
self._assert_status_code_is(show_response, 200)
hda = show_response.json()
assert hda["id"] == hda_id

def _share_history_with_payload(self, history_id, payload):
sharing_response = self._put(f"histories/{history_id}/share_with_users", data=payload, json=True)
self._assert_status_code_is(sharing_response, 200)
Expand Down