Skip to content

Commit d5ad834

Browse files
committed
[FEATURE]: Custom Access Validation
1 parent dde5760 commit d5ad834

File tree

11 files changed

+685
-12
lines changed

11 files changed

+685
-12
lines changed

jac-cloud/jac_cloud/plugin/jaseci.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,10 +135,10 @@ def restrict(architype: Architype) -> None:
135135

136136
@staticmethod
137137
@hookimpl
138-
def check_access_level(to: Anchor) -> AccessLevel:
138+
def check_access_level(to: Anchor, no_custom: bool) -> AccessLevel:
139139
"""Access validation."""
140140
if not FastAPI.is_enabled():
141-
return JacFeatureImpl.check_access_level(to=to)
141+
return JacFeatureImpl.check_access_level(to=to, no_custom=no_custom)
142142

143143
if not to.persistent:
144144
return AccessLevel.WRITE
@@ -155,6 +155,12 @@ def check_access_level(to: Anchor) -> AccessLevel:
155155
if jroot == jctx.system_root or jroot.id == to.root or jroot == to:
156156
return AccessLevel.WRITE
157157

158+
if (
159+
not no_custom
160+
and (custom_level := to.architype.__jac_access__()) is not None
161+
):
162+
return AccessLevel.cast(custom_level)
163+
158164
access_level = AccessLevel.NO_ACCESS
159165

160166
# if target anchor have set access.all

jac-cloud/jac_cloud/tests/openapi_specs.yaml

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -530,6 +530,15 @@ components:
530530
- object_id
531531
title: update_custom_object_body_model
532532
type: object
533+
update_nested_node_access_body_model:
534+
properties:
535+
access:
536+
anyOf:
537+
- type: string
538+
- type: 'null'
539+
title: Access
540+
title: update_nested_node_access_body_model
541+
type: object
533542
securitySchemes:
534543
APIKeyHeader:
535544
in: header
@@ -4022,6 +4031,75 @@ paths:
40224031
summary: /update_nested_node/{node}
40234032
tags:
40244033
- walker
4034+
/walker/update_nested_node_access:
4035+
post:
4036+
operationId: api_root_walker_update_nested_node_access_post
4037+
requestBody:
4038+
content:
4039+
application/json:
4040+
schema:
4041+
$ref: '#/components/schemas/update_nested_node_access_body_model'
4042+
required: true
4043+
responses:
4044+
'200':
4045+
content:
4046+
application/json:
4047+
schema:
4048+
anyOf:
4049+
- $ref: '#/components/schemas/ContextResponse_NoneType_'
4050+
- {}
4051+
title: Response Api Root Walker Update Nested Node Access Post
4052+
description: Successful Response
4053+
'422':
4054+
content:
4055+
application/json:
4056+
schema:
4057+
$ref: '#/components/schemas/HTTPValidationError'
4058+
description: Validation Error
4059+
security:
4060+
- HTTPBearer: []
4061+
summary: /update_nested_node_access
4062+
tags:
4063+
- walker
4064+
/walker/update_nested_node_access/{node}:
4065+
post:
4066+
operationId: api_entry_walker_update_nested_node_access__node__post
4067+
parameters:
4068+
- in: path
4069+
name: node
4070+
required: true
4071+
schema:
4072+
anyOf:
4073+
- type: string
4074+
- type: 'null'
4075+
title: Node
4076+
requestBody:
4077+
content:
4078+
application/json:
4079+
schema:
4080+
$ref: '#/components/schemas/update_nested_node_access_body_model'
4081+
required: true
4082+
responses:
4083+
'200':
4084+
content:
4085+
application/json:
4086+
schema:
4087+
anyOf:
4088+
- $ref: '#/components/schemas/ContextResponse_NoneType_'
4089+
- {}
4090+
title: Response Api Entry Walker Update Nested Node Access Node Post
4091+
description: Successful Response
4092+
'422':
4093+
content:
4094+
application/json:
4095+
schema:
4096+
$ref: '#/components/schemas/HTTPValidationError'
4097+
description: Validation Error
4098+
security:
4099+
- HTTPBearer: []
4100+
summary: /update_nested_node_access/{node}
4101+
tags:
4102+
- walker
40254103
/walker/visit_nested_node:
40264104
post:
40274105
operationId: api_root_walker_visit_nested_node_post

jac-cloud/jac_cloud/tests/simple_graph.jac

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,11 @@ obj Parent:Child: {
7272
}
7373

7474
node Nested {
75-
has val: int, arr: list[int], json: dict[str, int], parent: Parent, enum_field: Enum;
75+
has val: int, arr: list[int], json: dict[str, int], parent: Parent, enum_field: Enum, access: str | None = None;
76+
77+
can __jac_access__ {
78+
return self.access;
79+
}
7680
}
7781

7882
walker create_graph {
@@ -205,6 +209,15 @@ walker update_nested_node {
205209
}
206210
}
207211

212+
walker update_nested_node_access {
213+
has access: str | None = None;
214+
215+
can enter_nested with Nested entry {
216+
here.access = self.access;
217+
return here;
218+
}
219+
}
220+
208221
walker detach_nested_node {
209222
can enter_root with `root entry {
210223
report here del--> [-->(`?Nested)];

0 commit comments

Comments
 (0)