mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-10-24 12:13:33 +08:00
Fix is_history_shared_with query + test multiple shares with same user
This commit is contained in:
@@ -342,12 +342,12 @@ class HistoryManager(sharable.SharableModelManager, deletable.PurgableManagerMix
|
||||
return extra
|
||||
|
||||
def is_history_shared_with(self, history, user) -> bool:
|
||||
return self.session().query(self.user_share_model).filter(
|
||||
return bool(self.session().query(self.user_share_model).filter(
|
||||
and_(
|
||||
self.user_share_model.table.c.user_id == user.id,
|
||||
self.user_share_model.table.c.history_id == history.id,
|
||||
)
|
||||
).exists()
|
||||
).first())
|
||||
|
||||
|
||||
class HistoryExportView:
|
||||
|
||||
@@ -534,12 +534,19 @@ class SharingHistoryTestCase(ApiTestCase, BaseHistories, SharingApiTests):
|
||||
with self._different_user():
|
||||
target_user_id = self.dataset_populator.user_id()
|
||||
|
||||
# Ignore repeated users in the same request
|
||||
payload = {"user_ids": [target_user_id, target_user_id]}
|
||||
sharing_response = self._share_history_with_payload(history_id, payload)
|
||||
assert sharing_response["users_shared_with"]
|
||||
assert len(sharing_response["users_shared_with"]) == 1
|
||||
assert sharing_response["users_shared_with"][0]["id"] == target_user_id
|
||||
|
||||
# Do not share with the same user multiple times
|
||||
payload = {"user_ids": [target_user_id]}
|
||||
sharing_response = self._share_history_with_payload(history_id, payload)
|
||||
assert sharing_response["errors"]
|
||||
assert "already shared" in sharing_response["errors"][0]
|
||||
|
||||
def _share_history_with_payload(self, history_id, payload):
|
||||
sharing_response = self._put(f"histories/{history_id}/share_with", data=json.dumps(payload))
|
||||
self._assert_status_code_is(sharing_response, 200)
|
||||
|
||||
Reference in New Issue
Block a user