|
2 | 2 |
|
3 | 3 | from irods.manager import Manager |
4 | 4 | from irods.api_number import api_number |
5 | | -from irods.message import ModAclRequest, iRODSMessage |
| 5 | +from irods.message import ModAclRequest, iRODSMessage, JSON_Message |
6 | 6 | from irods.data_object import iRODSDataObject, irods_dirname, irods_basename |
7 | 7 | from irods.collection import iRODSCollection |
8 | 8 | from irods.models import ( |
|
14 | 14 | CollectionAccess, |
15 | 15 | ) |
16 | 16 | from irods.access import iRODSAccess |
| 17 | +import irods.exception as ex |
17 | 18 | from irods.column import In |
18 | 19 | from irods.user import iRODSUser |
19 | 20 |
|
@@ -48,6 +49,36 @@ def users_by_ids(session, ids=()): |
48 | 49 |
|
49 | 50 | class AccessManager(Manager): |
50 | 51 |
|
| 52 | + def _ACL_operation(self, op_input: iRODSAccess): |
| 53 | + access = op_input.access_name |
| 54 | + entity = op_input.user_name |
| 55 | + zone = op_input.user_zone |
| 56 | + try: |
| 57 | + if self.sess.users.get(entity, zone).type == "rodsgroup": |
| 58 | + zone = "" |
| 59 | + except ex.UserDoesNotExist: |
| 60 | + return {} |
| 61 | + return { |
| 62 | + **{"acl": access, "entity_name": entity}, |
| 63 | + **({} if not zone else {"zone":zone}) |
| 64 | + } |
| 65 | + |
| 66 | + def _call_atomic_acl_api(self, logical_path : str, *operations, admin=False): |
| 67 | + request_text = {"logical_path": logical_path} |
| 68 | + request_text["admin_mode"] = admin |
| 69 | + request_text["operations"] = [self._ACL_operation(op) for op in operations] |
| 70 | + |
| 71 | + with self.sess.pool.get_connection() as conn: |
| 72 | + request_msg = iRODSMessage( |
| 73 | + "RODS_API_REQ", |
| 74 | + JSON_Message(request_text, conn.server_version), |
| 75 | + int_info=20005, |
| 76 | + ) |
| 77 | + conn.send(request_msg) |
| 78 | + response = conn.recv() |
| 79 | + response_msg = response.get_json_encoded_struct() |
| 80 | + logger.debug("in atomic ACL api, server responded with: %r", response_msg) |
| 81 | + |
51 | 82 | def get(self, target, report_raw_acls=True, **kw): |
52 | 83 |
|
53 | 84 | if report_raw_acls: |
|
0 commit comments