From 446e1f734a73c25f56ac05c955dd8def9e2d69bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Z=C3=BCbeyde=20Civelek?= Date: Thu, 28 Nov 2024 10:59:29 +0100 Subject: [PATCH] Update '_access.update' to include existing values --- cds/modules/deposit/api.py | 8 +++++--- tests/unit/test_project_rest.py | 1 + 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/cds/modules/deposit/api.py b/cds/modules/deposit/api.py index ea7168ce9..4c19ec5c3 100644 --- a/cds/modules/deposit/api.py +++ b/cds/modules/deposit/api.py @@ -500,11 +500,13 @@ def create(cls, data, id_=None, **kwargs): kwargs.setdefault("bucket_location", "videos") data["$schema"] = current_jsonschemas.path_to_url(cls._schema) data.setdefault("videos", []) - data.setdefault("_access", {}) data.setdefault("_cds", {}) - # Add the current user to the ``_access.update`` list + data.setdefault("_access", {}) + access_update = data["_access"].setdefault("update", []) try: - data["_access"]["update"] = [current_user.email] + if current_user.email not in access_update: + # Add the current user to the ``_access.update`` list + access_update.append(current_user.email) except AttributeError: current_app.logger.warning( "No current user found, _access.update will stay empty." diff --git a/tests/unit/test_project_rest.py b/tests/unit/test_project_rest.py index 788a41faa..aa61d85cf 100644 --- a/tests/unit/test_project_rest.py +++ b/tests/unit/test_project_rest.py @@ -100,6 +100,7 @@ def assert_bucket_for_video(bucket_id, video): assert res.status_code == 201 project_dict = json.loads(res.data.decode("utf-8")) assert project_dict["metadata"]["videos"] == [] + assert User.query.get(users[0]).email in project_dict["metadata"]["_access"]["update"] assert project_dict["metadata"]["title"]["title"] == "my project" assert project_dict["links"]["bucket"].startswith("http://localhost/files/") assert all(