Skip to content

Commit 4305d81

Browse files
committed
fix(permissions): allow update users to read metadata/files
1 parent a19b671 commit 4305d81

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

cds/modules/records/permissions.py

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -293,23 +293,28 @@ def is_owner(user, record):
293293
return user_id == deposit_creator
294294

295295

296+
def _get_access_groups(record, *actions):
297+
"""Return a deduplicated lowercased list of principals across given actions."""
298+
groups = set()
299+
for action in actions:
300+
for value in record.get("_access", {}).get(action, []):
301+
groups.add(lowercase_value(value))
302+
return groups
303+
304+
296305
def has_read_files_permission(user, record):
297306
"""Check if user has read access to the record's files."""
298-
# TODO: decide on files access rights
299-
# Same permissions as for record itself
300-
301307
# Allow everyone for public records
302308
if is_public(record, "read"):
303309
return True
304310

305311
if is_owner(user, record):
306312
return True
307313

308-
# Allow e-group members
314+
# Users with update permission can also read
309315
user_provides = get_user_provides()
310-
read_access_groups = [lowercase_value(value) for value in record["_access"]["read"]]
311-
312-
if not set(user_provides).isdisjoint(set(read_access_groups)):
316+
allowed = _get_access_groups(record, "read", "update")
317+
if not set(user_provides).isdisjoint(allowed):
313318
return True
314319

315320
return has_admin_permission(user, record)
@@ -324,11 +329,10 @@ def has_read_record_permission(user, record):
324329
if is_owner(user, record):
325330
return True
326331

327-
# Allow e-group members
332+
# Users with update permission can also read
328333
user_provides = get_user_provides()
329-
read_access_groups = [lowercase_value(value) for value in record["_access"]["read"]]
330-
331-
if not set(user_provides).isdisjoint(set(read_access_groups)):
334+
allowed = _get_access_groups(record, "read", "update")
335+
if not set(user_provides).isdisjoint(allowed):
332336
return True
333337

334338
return has_admin_permission()

0 commit comments

Comments
 (0)