|
| 1 | +--- |
| 2 | +schema: |- |
| 3 | + /** |
| 4 | + * an entity that can be granted permissions |
| 5 | + */ |
| 6 | + definition user { |
| 7 | + /** |
| 8 | + * users can have one or more AI agents that act on their behalf |
| 9 | + */ |
| 10 | + relation agent: ai_agent |
| 11 | +
|
| 12 | + /** |
| 13 | + * the set of AI agents that may act on this user's behalf |
| 14 | + */ |
| 15 | + permission delegates = agent |
| 16 | + } |
| 17 | +
|
| 18 | + /** |
| 19 | + * an AI agent that can act on behalf of a user |
| 20 | + */ |
| 21 | + definition ai_agent {} |
| 22 | +
|
| 23 | + /** |
| 24 | + * a resource that we are trying to protect |
| 25 | + */ |
| 26 | + definition document { |
| 27 | + /** |
| 28 | + * users can be made writers of specific documents |
| 29 | + */ |
| 30 | + relation writer: user |
| 31 | +
|
| 32 | + /** |
| 33 | + * users can be made readers of specific documents |
| 34 | + */ |
| 35 | + relation reader: user |
| 36 | +
|
| 37 | + /** |
| 38 | + * if a user has the writer relationship to a specific document, they automatically get permission to edit it |
| 39 | + */ |
| 40 | + permission edit = writer |
| 41 | +
|
| 42 | + /** |
| 43 | + * a user can view a document if they are a reader (or can edit it). |
| 44 | + * an AI agent can view a document if it acts on behalf of a reader or a writer of that document. |
| 45 | + */ |
| 46 | + permission view = reader + edit + reader->delegates + writer->delegates |
| 47 | + } |
| 48 | +
|
| 49 | +relationships: |- |
| 50 | + document:firstdoc#writer@user:tom |
| 51 | + document:firstdoc#reader@user:fred |
| 52 | + user:tom#agent@ai_agent:assistant_tom |
| 53 | + user:fred#agent@ai_agent:assistant_fred |
| 54 | +
|
| 55 | +assertions: |
| 56 | + assertTrue: |
| 57 | + - "document:firstdoc#edit@user:tom" |
| 58 | + - "document:firstdoc#view@user:tom" |
| 59 | + - "document:firstdoc#view@user:fred" |
| 60 | + - "document:firstdoc#view@ai_agent:assistant_tom" |
| 61 | + - "document:firstdoc#view@ai_agent:assistant_fred" |
| 62 | + assertFalse: |
| 63 | + - "document:firstdoc#edit@user:fred" |
| 64 | + - "document:firstdoc#edit@ai_agent:assistant_tom" |
| 65 | + - "document:firstdoc#edit@ai_agent:assistant_fred" |
| 66 | + |
| 67 | +validation: |
| 68 | + document:firstdoc#view: |
| 69 | + - "[user:tom] is <document:firstdoc#writer>" |
| 70 | + - "[user:fred] is <document:firstdoc#reader>" |
| 71 | + - "[ai_agent:assistant_tom] is <user:tom#agent>" |
| 72 | + - "[ai_agent:assistant_fred] is <user:fred#agent>" |
0 commit comments