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 authored and zzacharo committed Nov 28, 2024
1 parent 0b25957 commit 90a8237
Show file tree
Hide file tree
Showing 2 changed files with 10 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
5 changes: 5 additions & 0 deletions tests/unit/test_project_rest.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,9 @@ def assert_bucket_for_video(bucket_id, video):
video_schema = (
"https://cds.cern.ch/schemas/" "deposits/records/videos/video/video-v1.0.0.json"
)

project_deposit_metadata.setdefault("_access", {}).setdefault("update", [])
project_deposit_metadata["_access"]["update"].append("[email protected]")

with api_app.test_client() as client:
login_user(User.query.get(users[0]))
Expand All @@ -100,6 +103,8 @@ 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 "[email protected]" 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 90a8237

Please sign in to comment.