Skip to content

Commit

Permalink
Update '_access.update' to include existing values
Browse files Browse the repository at this point in the history
  • Loading branch information
zubeydecivelek committed Nov 28, 2024
1 parent 0b25957 commit 446e1f7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
8 changes: 5 additions & 3 deletions cds/modules/deposit/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down
1 change: 1 addition & 0 deletions tests/unit/test_project_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 446e1f7

Please sign in to comment.