Fix is_history_shared_with query + test multiple shares with same user

This commit is contained in:
davelopez
2021-09-17 10:18:37 +02:00
parent f97f5930a2
commit 0227f96cd2
2 changed files with 9 additions and 2 deletions
+2 -2
View File
@@ -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:
+7
View File
@@ -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)