Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion irods/access.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
def __hash__(self):
return hash((self.access_name, iRODSPath(self.path), self.user_name, self.user_zone))

def copy(self, decanonicalize=False):
def copy(self, decanonicalize=False, ref_zone=''):

Check failure on line 105 in irods/access.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff D102

D102: Missing docstring in public method [pydocstyle:undocumented-public-method]
other = copy.deepcopy(self)
if decanonicalize:
replacement_string = {
Expand All @@ -112,6 +112,9 @@
"modify_object": "write",
}.get(self.access_name)
other.access_name = replacement_string if replacement_string is not None else self.access_name
if '' != ref_zone == other.user_zone:
other.user_zone = ''

return other

def __repr__(self):
Expand Down
4 changes: 4 additions & 0 deletions irods/exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,10 @@
code = -130000


class SYS_INTERNAL_ERR(SystemException):

Check failure on line 653 in irods/exception.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff D101

D101: Missing docstring in public class [pydocstyle:undocumented-public-class]

Check failure on line 653 in irods/exception.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff N801

N801: Class name `SYS_INTERNAL_ERR` should use CapWords convention [pep8-naming:invalid-class-name]
code = -154000


class SYS_BAD_INPUT(iRODSException):
code = -158000

Expand Down
30 changes: 29 additions & 1 deletion irods/manager/access_manager.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
from os.path import basename, dirname

from irods.manager import Manager
from irods.api_number import api_number
from irods.message import ModAclRequest, iRODSMessage
from irods.message import ModAclRequest, iRODSMessage, JSON_Message
from irods.data_object import iRODSDataObject, irods_dirname, irods_basename
from irods.collection import iRODSCollection
from irods.models import (
DataObject,
Collection,
User,
CollectionUser,
DataAccess,
CollectionAccess,
)
from irods.access import iRODSAccess
import irods.exception as ex

Check failure on line 17 in irods/manager/access_manager.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff F401

F401: `irods.exception` imported but unused [Pyflakes:unused-import]
from irods.column import In
from irods.user import iRODSUser

Expand All @@ -36,6 +37,33 @@


class AccessManager(Manager):

def _ACL_operation(self, op_input: iRODSAccess):

Check failure on line 41 in irods/manager/access_manager.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff N802

N802: Function name `_ACL_operation` should be lowercase [pep8-naming:invalid-function-name]
return {
"acl": op_input.access_name,
"entity_name": op_input.user_name,
**(
{} if not (z := op_input.user_zone)
else {"zone": z}
)
}

def _call_atomic_acl_api(self, logical_path : str, *operations, admin=False):

Check failure on line 51 in irods/manager/access_manager.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-format

Ruff format

Improper formatting
request_text = {"logical_path": logical_path}
request_text["admin_mode"] = admin
request_text["operations"] = [self._ACL_operation(op) for op in operations]

with self.sess.pool.get_connection() as conn:
request_msg = iRODSMessage(
"RODS_API_REQ",
JSON_Message(request_text, conn.server_version),
int_info=20005,
)
conn.send(request_msg)
response = conn.recv()
response_msg = response.get_json_encoded_struct()
logger.debug("in atomic ACL api, server responded with: %r", response_msg)

def get(self, target, report_raw_acls=True, **kw):

if report_raw_acls:
Expand Down
36 changes: 36 additions & 0 deletions irods/test/access_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,42 @@
self.sess,
)

def test_atomic_acls_505(self):
ses = self.sess
zone = user1 = user2 = group = None
try:
zone = ses.zones.create("twilight","remote")
user1 = ses.users.create("test_user_505", "rodsuser")
user2 = ses.users.create("rod_serling_505#twilight", "rodsuser")
group = ses.groups.create("test_group_505")
ses.acls._call_atomic_acl_api(

Check failure on line 508 in irods/test/access_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff SLF001

SLF001: Private member accessed: `_call_atomic_acl_api` [flake8-self:private-member-access]
self.coll_path,
a1:=iRODSAccess("write", "", user1.name, user1.zone),
a2:=iRODSAccess("read", "", user2.name, user2.zone),
a3:=iRODSAccess("read", "", group.name),
)

accesses = ses.acls.get(self.coll)

# For purposes of equality tests, assign the path name of interest into each ACL.
for p in (a1, a2, a3):
p.path = self.coll_path

# Assert that the ACLs we added are among those listed for the object in the catalog.
normalize = lambda access: access.copy(decanonicalize=True, ref_zone=ses.zone)

Check failure on line 522 in irods/test/access_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff E731

E731: Do not assign a `lambda` expression, use a `def` [pycodestyle:lambda-assignment]
self.assertLess(
set(normalize(_) for _ in (a1,a2,a3)),

Check failure on line 524 in irods/test/access_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff C401

C401: Unnecessary generator (rewrite as a set comprehension) [flake8-comprehensions:unnecessary-generator-set]
set(normalize(_) for _ in accesses)

Check failure on line 525 in irods/test/access_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-check

Ruff C401

C401: Unnecessary generator (rewrite as a set comprehension) [flake8-comprehensions:unnecessary-generator-set]
)

Check failure on line 526 in irods/test/access_test.py

View workflow job for this annotation

GitHub Actions / ruff-lint / ruff-format

Ruff format

Improper formatting
finally:
if user1:
user1.remove()
if user2:
user2.remove()
if group:
group.remove()
if zone:
zone.remove()

if __name__ == "__main__":
# let the tests find the parent irods lib
Expand Down
Loading