Skip to content

Commit f0b8d57

Browse files
committed
chore(docs): include conditions in README
1 parent 74d351a commit f0b8d57

1 file changed

Lines changed: 78 additions & 14 deletions

File tree

README.md

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,10 @@ Create a new authorization model.
320320
321321
```python
322322
body = WriteAuthorizationModelRequest(
323-
schema_version = "1.1",
323+
schema_version="1.1",
324324
type_definitions=[
325325
TypeDefinition(
326-
type="user",
326+
type="user"
327327
),
328328
TypeDefinition(
329329
type="document",
@@ -342,9 +342,41 @@ body = WriteAuthorizationModelRequest(
342342
],
343343
),
344344
),
345+
),
346+
metadata=Metadata(
347+
relations=dict(
348+
writer=RelationMetadata(
349+
directly_related_user_types=[
350+
RelationReference(type="user"),
351+
RelationReference(type="user", condition="ViewCountLessThan200"),
352+
]
353+
),
354+
viewer=RelationMetadata(
355+
directly_related_user_types=[
356+
RelationReference(type="user"),
357+
]
358+
)
359+
)
345360
)
346-
),
361+
)
347362
],
363+
conditions=dict(
364+
ViewCountLessThan200=Condition(
365+
name="ViewCountLessThan200",
366+
expression="ViewCount < 200",
367+
parameters=dict(
368+
ViewCount=ConditionParamTypeRef(
369+
type_name="TYPE_NAME_INT"
370+
),
371+
Type=ConditionParamTypeRef(
372+
type_name="TYPE_NAME_STRING"
373+
),
374+
Name=ConditionParamTypeRef(
375+
type_name="TYPE_NAME_STRING"
376+
),
377+
)
378+
)
379+
)
348380
)
349381

350382
response = await fga_client.write_authorization_model(body)
@@ -364,7 +396,10 @@ options = {
364396
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
365397
}
366398

367-
response = await fga_client.read_authorization_model(id)
399+
response = await fga_client.read_authorization_model({
400+
# You can rely on the model id set in the configuration or override it for this specific request
401+
"authorization_model_id": "01GXSA8YR785C4FYS3C0RTG7B1"
402+
})
368403
# response.authorization_model = AuthorizationModel(id='01GXSA8YR785C4FYS3C0RTG7B1', schema_version = '1.1', type_definitions=type_definitions[...])
369404
```
370405

@@ -394,7 +429,7 @@ options = {
394429
"page_size": "25",
395430
"continuation_token": "eyJwayI6IkxBVEVTVF9OU0NPTkZJR19hdXRoMHN0b3JlIiwic2siOiIxem1qbXF3MWZLZExTcUoyN01MdTdqTjh0cWgifQ=="
396431
}
397-
body = ClientReadChangesRequest("document")
432+
body = ClientReadChangesRequest(type='document')
398433

399434
response = await fga_client.read_changes(body, options)
400435
# response.continuation_token = ...
@@ -409,7 +444,7 @@ Reads the relationship tuples stored in the database. It does not evaluate nor e
409444

410445
```python
411446
# Find if a relationship tuple stating that a certain user is a viewer of certain document
412-
body = TupleKey(
447+
body = ReadRequestTupleKey(
413448
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
414449
relation="viewer",
415450
object="document:roadmap",
@@ -421,7 +456,7 @@ response = await fga_client.read(body)
421456

422457
```python
423458
# Find all relationship tuples where a certain user has a relationship as any relation to a certain document
424-
body = TupleKey(
459+
body = ReadRequestTupleKey(
425460
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
426461
object="document:roadmap",
427462
)
@@ -433,7 +468,7 @@ response = await fga_client.read(body)
433468

434469
```python
435470
# Find all relationship tuples where a certain user is a viewer of any document
436-
body = TupleKey(
471+
body = ReadRequestTupleKey(
437472
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
438473
relation="viewer",
439474
object="document:",
@@ -445,7 +480,7 @@ response = await fga_client.read(body)
445480

446481
```python
447482
# Find all relationship tuples where any user has a relationship as any relation with a particular document
448-
body = TupleKey(
483+
body = ReadRequestTupleKey(
449484
object="document:roadmap",
450485
)
451486

@@ -455,7 +490,7 @@ response = await fga_client.read(body)
455490

456491
```python
457492
# Read all stored relationship tuples
458-
body = TupleKey()
493+
body = ReadRequestTupleKey()
459494

460495
response = await api_instance.read(body)
461496
# response = ReadResponse({"tuples": [Tuple({"key": TupleKey({"user":"...","relation":"...","object":"..."}), "timestamp": datetime.fromisoformat("...") })]})
@@ -482,6 +517,13 @@ body = ClientWriteRequest(
482517
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
483518
relation="viewer",
484519
object="document:roadmap",
520+
condition=RelationshipCondition(
521+
name='ViewCountLessThan200',
522+
context=dict(
523+
Name='Roadmap',
524+
Type='Document',
525+
),
526+
),
485527
),
486528
ClientTuple(
487529
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
@@ -523,6 +565,13 @@ body = ClientWriteRequest(
523565
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
524566
relation="viewer",
525567
object="document:roadmap",
568+
condition=RelationshipCondition(
569+
name='ViewCountLessThan200',
570+
context=dict(
571+
Name='Roadmap',
572+
Type='Document',
573+
),
574+
),
526575
),
527576
ClientTuple(
528577
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
@@ -559,6 +608,9 @@ body = ClientCheckRequest(
559608
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
560609
relation="writer",
561610
object="document:roadmap",
611+
context=dict(
612+
ViewCount=100
613+
),
562614
)
563615

564616
response = await fga_client.check(body, options)
@@ -586,7 +638,10 @@ body = [ClientCheckRequest(
586638
relation="editor",
587639
object="document:roadmap",
588640
),
589-
]
641+
],
642+
context=dict(
643+
ViewCount=100
644+
),
590645
), ClientCheckRequest(
591646
user="user:81684243-9356-4421-8fbf-a4f8d36aa31b",
592647
relation="admin",
@@ -619,7 +674,10 @@ response = await fga_client.batch_check(body, options)
619674
# user: "user:81684243-9356-4421-8fbf-a4f8d36aa31b",
620675
# relation: "editor",
621676
# object: "document:roadmap"
622-
# }]
677+
# }],
678+
# context=dict(
679+
# ViewCount=100
680+
# ),
623681
# }
624682
# }, {
625683
# allowed: false,
@@ -693,7 +751,10 @@ body = ClientListObjectsRequest(
693751
relation="writer",
694752
object="document:budget",
695753
),
696-
]
754+
],
755+
context=dict(
756+
ViewCount=100
757+
)
697758
)
698759

699760
response = await fga_client.list_objects(body)
@@ -719,7 +780,10 @@ body = ClientListRelationsRequest(
719780
relation="writer",
720781
object="document:budget",
721782
),
722-
]
783+
],
784+
context=dict(
785+
ViewCount=100
786+
)
723787
)
724788
var response = await fga_client.list_relations(body, options);
725789

0 commit comments

Comments
 (0)