Skip to content

Commit 096fb0b

Browse files
lwesterhofstsnel
authored andcommitted
Remove legacy iiCopyACLsFromParent function
1 parent 17d8dc0 commit 096fb0b

File tree

6 files changed

+50
-81
lines changed

6 files changed

+50
-81
lines changed

iiVault.r

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,6 @@ iiGenericSecureCopy(*argv, *origin_path, *err) {
2222
}
2323
}
2424

25-
# \brief When inheritance is missing we need to copy ACL's when introducing new data in vault package.
26-
#
27-
# \param[in] path path of object that needs the permissions of parent
28-
# \param[in] recursiveFlag either "default" for no recursion or "recursive"
29-
#
30-
iiCopyACLsFromParent(*path, *recursiveFlag) {
31-
uuChopPath(*path, *parent, *child);
32-
33-
foreach(*row in SELECT COLL_ACCESS_NAME, COLL_ACCESS_USER_ID WHERE COLL_NAME = *parent) {
34-
*accessName = *row.COLL_ACCESS_NAME;
35-
*userId = *row.COLL_ACCESS_USER_ID;
36-
*userFound = false;
37-
38-
foreach(*user in SELECT USER_NAME WHERE USER_ID = *userId) {
39-
*userName = *user.USER_NAME;
40-
*userFound = true;
41-
}
42-
43-
if (*userFound) {
44-
if (*accessName == "own") {
45-
writeString("serverLog", "iiCopyACLsFromParent: granting own to <*userName> on <*path> with recursiveFlag <*recursiveFlag>");
46-
msiSetACL(*recursiveFlag, "own", *userName, *path);
47-
} else if (*accessName == "read_object") {
48-
writeString("serverLog", "iiCopyACLsFromParent: granting read to <*userName> on <*path> with recursiveFlag <*recursiveFlag>");
49-
msiSetACL(*recursiveFlag, "read", *userName, *path);
50-
} else if (*accessName == "modify_object") {
51-
writeString("serverLog", "iiCopyACLsFromParent: granting write to <*userName> on <*path> with recursiveFlag <*recursiveFlag>");
52-
msiSetACL(*recursiveFlag, "write", *userName, *path);
53-
}
54-
}
55-
}
56-
}
57-
5825
# \brief Perform a vault ingest as rodsadmin.
5926
#
6027
iiAdminVaultIngest() {

meta.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""JSON metadata handling."""
22
from __future__ import annotations
33

4-
__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
4+
__copyright__ = 'Copyright (c) 2019-2026, Utrecht University'
55
__license__ = 'GPLv3, see LICENSE'
66

77
import json
@@ -537,7 +537,7 @@ def set_result(msg_short, msg_long):
537537
current_json_data = json.loads(json.dumps(current_json))
538538

539539
try:
540-
callback.iiCopyACLsFromParent(dest, 'default')
540+
vault.copy_acls_from_parent(ctx, dest, "default")
541541
except Exception:
542542
set_result('FailedToSetACLs', 'Failed to set vault permissions on <{}>'.format(dest))
543543
return

schema_transformation.py

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import provenance
2424
import schema
2525
import schema_transformations
26+
import vault
2627
from util import *
2728

2829

@@ -45,7 +46,7 @@ def execute_transformation(ctx: rule.Context, metadata_path: str, transform: Cal
4546
new_path = '{}/yoda-metadata[{}].json'.format(coll, str(int(time.time())))
4647
# print('TRANSFORMING in vault <{}> -> <{}>'.format(metadata_path, new_path))
4748
jsonutil.write(ctx, new_path, metadata)
48-
copy_acls_from_parent(ctx, new_path, "default")
49+
vault.copy_acls_from_parent(ctx, new_path, "default")
4950
provenance.log_action(ctx, "system", coll, "updated metadata schema")
5051
log.write(ctx, "Transformed %s" % (new_path))
5152
else:
@@ -163,44 +164,6 @@ def rule_get_transformation_info(ctx: rule.Context, json_path: str) -> Tuple[str
163164
return output
164165

165166

166-
def copy_acls_from_parent(ctx: rule.Context, path: str, recursive_flag: str) -> None:
167-
"""
168-
When inheritance is missing we need to copy ACLs when introducing new data in vault package.
169-
170-
:param ctx: Combined type of a ctx and rei struct
171-
:param path: Path of object that needs the permissions of parent
172-
:param recursive_flag: Either "default" for no recursion or "recursive"
173-
"""
174-
parent = os.path.dirname(path)
175-
176-
iter = genquery.row_iterator(
177-
"COLL_ACCESS_NAME, COLL_ACCESS_USER_ID",
178-
"COLL_NAME = '" + parent + "'",
179-
genquery.AS_LIST, ctx
180-
)
181-
182-
for row in iter:
183-
access_name = row[0]
184-
user_id = int(row[1])
185-
186-
user_name = user.name_from_id(ctx, user_id)
187-
188-
# iRODS keeps ACLs for deleted users in the iCAT database (https://github.com/irods/irods/issues/7778),
189-
# so we need to skip ACLs referring to users that no longer exist.
190-
if user_name == "":
191-
continue
192-
193-
if access_name == "own":
194-
log.write(ctx, "iiCopyACLsFromParent: granting own to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
195-
msi.set_acl(ctx, recursive_flag, "own", user_name, path)
196-
elif access_name == "read_object":
197-
log.write(ctx, "iiCopyACLsFromParent: granting read to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
198-
msi.set_acl(ctx, recursive_flag, "read", user_name, path)
199-
elif access_name == "modify_object":
200-
log.write(ctx, "iiCopyACLsFromParent: granting write to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
201-
msi.set_acl(ctx, recursive_flag, "write", user_name, path)
202-
203-
204167
@rule.make(inputs=[0, 1, 2, 3], outputs=[])
205168
def rule_batch_transform_vault_metadata(ctx: rule.Context, coll_id_s: str, batch_s: str, pause_s: str, delay_s: str) -> None:
206169
"""
@@ -328,7 +291,7 @@ def rule_batch_vault_metadata_correct_orcid_format(ctx: rule.Context, coll_id_s:
328291
new_path = '{}/yoda-metadata[{}].json'.format(coll, str(int(time.time())))
329292
log.write(ctx, 'TRANSFORMING in vault <{}> -> <{}>'.format(metadata_path, new_path))
330293
jsonutil.write(ctx, new_path, result['metadata'])
331-
copy_acls_from_parent(ctx, new_path, "default")
294+
vault.copy_acls_from_parent(ctx, new_path, "default")
332295
provenance.log_action(ctx, "system", coll, "updated person identifier metadata")
333296
log.write(ctx, "Transformed ORCIDs for: %s" % (new_path))
334297
elif result['data_changed']:

util/bagit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Functions to copy packages to the vault and manage permissions of vault packages."""
22
from __future__ import annotations
33

4-
__copyright__ = 'Copyright (c) 2023-2025, Utrecht University'
4+
__copyright__ = 'Copyright (c) 2023-2026, Utrecht University'
55
__license__ = 'GPLv3, see LICENSE'
66

77
import itertools
@@ -14,6 +14,7 @@
1414
import log
1515
import msi
1616
import rule
17+
import vault
1718

1819

1920
def manifest(ctx: rule.Context, coll: str) -> str:
@@ -73,7 +74,7 @@ def create(ctx: rule.Context, archive: str, coll: str, resource: str) -> None:
7374

7475
if ret.get("code", -1) < 0:
7576
raise Exception("Archive creation failed: {}".format(ret))
76-
ctx.iiCopyACLsFromParent(archive, "default")
77+
vault.copy_acls_from_parent(ctx, archive, "default")
7778

7879

7980
def extract(ctx: rule.Context, archive: str, coll: str, resource: str = '0') -> None:

vault.py

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Functions to copy packages to the vault and manage permissions of vault packages."""
22
from __future__ import annotations
33

4-
__copyright__ = 'Copyright (c) 2019-2025, Utrecht University'
4+
__copyright__ = 'Copyright (c) 2019-2026, Utrecht University'
55
__license__ = 'GPLv3, see LICENSE'
66

77
import json
@@ -501,7 +501,7 @@ def vault_write_license(ctx: rule.Context, vault_pkg_coll: str) -> None:
501501

502502
# Fix ACLs.
503503
try:
504-
ctx.iiCopyACLsFromParent(license_file, 'default')
504+
copy_acls_from_parent(ctx, license_file, "default")
505505
except Exception:
506506
log.write(ctx, "rule_vault_write_license: Failed to set vault permissions on <{}>".format(license_file))
507507
else:
@@ -1202,6 +1202,43 @@ def set_vault_permissions(ctx: rule.Context, coll: str, target: str) -> bool:
12021202
return True
12031203

12041204

1205+
def copy_acls_from_parent(ctx: rule.Context, path: str, recursive_flag: str) -> None:
1206+
"""
1207+
When inheritance is missing we need to copy ACLs when introducing new data in vault package.
1208+
1209+
:param ctx: Combined type of a ctx and rei struct
1210+
:param path: Path of object that needs the permissions of parent
1211+
:param recursive_flag: Either "default" for no recursion or "recursive"
1212+
"""
1213+
parent = os.path.dirname(path)
1214+
1215+
iter = genquery.row_iterator(
1216+
"COLL_ACCESS_NAME, COLL_ACCESS_USER_ID",
1217+
"COLL_NAME = '" + parent + "'",
1218+
genquery.AS_LIST, ctx
1219+
)
1220+
1221+
for row in iter:
1222+
access_name = row[0]
1223+
user_id = int(row[1])
1224+
user_name = user.name_from_id(ctx, user_id)
1225+
1226+
# iRODS keeps ACLs for deleted users in the iCAT database (https://github.com/irods/irods/issues/7778),
1227+
# so we need to skip ACLs referring to users that no longer exist.
1228+
if user_name == "":
1229+
continue
1230+
1231+
if access_name == "own":
1232+
log.write(ctx, "copy_acls_from_parent: granting own to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
1233+
msi.set_acl(ctx, recursive_flag, "own", user_name, path)
1234+
elif access_name == "read_object":
1235+
log.write(ctx, "copy_acls_from_parent: granting read to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
1236+
msi.set_acl(ctx, recursive_flag, "read", user_name, path)
1237+
elif access_name == "modify_object":
1238+
log.write(ctx, "copy_acls_from_parent: granting write to <" + user_name + "> on <" + path + "> with recursiveFlag <" + recursive_flag + ">")
1239+
msi.set_acl(ctx, recursive_flag, "write", user_name, path)
1240+
1241+
12051242
def reader_needs_access(ctx: rule.Context, group_name: str, coll: str) -> bool:
12061243
"""Return if research group has access to this group but readers do not"""
12071244
iter = genquery.row_iterator(

vault_archive.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Functions to archive vault data packages."""
22
from __future__ import annotations
33

4-
__copyright__ = 'Copyright (c) 2023-2025, Utrecht University'
4+
__copyright__ = 'Copyright (c) 2023-2026, Utrecht University'
55
__license__ = 'GPLv3, see LICENSE'
66

77
import json
@@ -16,6 +16,7 @@
1616
import meta
1717
import notifications
1818
import provenance
19+
import vault
1920
from util import *
2021

2122
__all__ = ['api_vault_archive',
@@ -242,7 +243,7 @@ def vault_extract_archive(ctx: rule.Context, coll: str) -> str:
242243

243244
extract_archive(ctx, coll)
244245
collection.rename(ctx, coll + "/archive/data", coll + "/original")
245-
ctx.iiCopyACLsFromParent(coll + "/original", "recursive")
246+
vault.copy_acls_from_parent(ctx, coll + "/original", "recursive")
246247
collection.remove(ctx, coll + "/archive", force=True)
247248
data_object.remove(ctx, coll + "/archive.tar", force=True)
248249

0 commit comments

Comments
 (0)