Skip to content

Commit 41bc12a

Browse files
committed
[ACCESS-CHANGE]: Prioritize sequence access level permission
1. roots access config of target node 2. roots access config of target node's root 3. public (all) access config of target node's root 4. public (all) access config of target node
1 parent 8ae56fd commit 41bc12a

File tree

3 files changed

+7
-11
lines changed

3 files changed

+7
-11
lines changed

jac-cloud/jac_cloud/plugin/jaseci.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ def allow_root(
361361
if (
362362
isinstance(anchor, BaseAnchor)
363363
and (ref_id := root_id.ref_id)
364-
and level != access.anchors.get(ref_id, AccessLevel.NO_ACCESS)
364+
and level != access.anchors.get(ref_id)
365365
):
366366
access.anchors[ref_id] = level
367367
anchor._set.update({f"access.roots.anchors.{ref_id}": level.name})
@@ -456,14 +456,12 @@ def check_access_level(to: Anchor) -> AccessLevel:
456456
if to_root.access.all > access_level:
457457
access_level = to_root.access.all
458458

459-
level = to_root.access.roots.check(jroot.ref_id)
460-
if level > AccessLevel.NO_ACCESS and access_level == AccessLevel.NO_ACCESS:
459+
if (level := to_root.access.roots.check(jroot.ref_id)) is not None:
461460
access_level = level
462461

463462
# if target anchor have set allowed roots
464463
# if current root is allowed to target anchor
465-
level = to_access.roots.check(jroot.ref_id)
466-
if level > AccessLevel.NO_ACCESS and access_level == AccessLevel.NO_ACCESS:
464+
if (level := to_access.roots.check(jroot.ref_id)) is not None:
467465
access_level = level
468466

469467
return access_level

jac/jaclang/plugin/default.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,12 @@ def check_access_level(to: Anchor) -> AccessLevel:
179179
if to_root.access.all > access_level:
180180
access_level = to_root.access.all
181181

182-
level = to_root.access.roots.check(str(jroot.id))
183-
if level > AccessLevel.NO_ACCESS and access_level == AccessLevel.NO_ACCESS:
182+
if (level := to_root.access.roots.check(str(jroot.id))) is not None:
184183
access_level = level
185184

186185
# if target anchor have set allowed roots
187186
# if current root is allowed to target anchor
188-
level = to_access.roots.check(str(jroot.id))
189-
if level > AccessLevel.NO_ACCESS and access_level == AccessLevel.NO_ACCESS:
187+
if (level := to_access.roots.check(str(jroot.id))) is not None:
190188
access_level = level
191189

192190
return access_level

jac/jaclang/runtimelib/architype.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,9 @@ class Access:
4444

4545
anchors: dict[str, AccessLevel] = field(default_factory=dict)
4646

47-
def check(self, anchor: str) -> AccessLevel:
47+
def check(self, anchor: str) -> AccessLevel | None:
4848
"""Validate access."""
49-
return self.anchors.get(anchor, AccessLevel.NO_ACCESS)
49+
return self.anchors.get(anchor)
5050

5151

5252
@dataclass

0 commit comments

Comments
 (0)