Skip to content

Commit

Permalink
chore: add modular models example (#22)
Browse files Browse the repository at this point in the history
* chore: add modular models example

* Update stores/modular/fga.mod

Co-authored-by: Raghd Hamzeh <[email protected]>

---------

Co-authored-by: Raghd Hamzeh <[email protected]>
  • Loading branch information
ewanharris and rhamzeh authored Mar 19, 2024
1 parent 03a392d commit e9afab0
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 0 deletions.
13 changes: 13 additions & 0 deletions stores/modular/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# OpenFGA Modular Model Sample Store

* **Title**: **Modular Model**

## Use-Case

This example showcases how to use modular models to separate your model across multiple files and how to use type extensions within those modules.

## Try It Out

1. Make sure you have the [FGA CLI](https://github.com/openfga/cli/?tab=readme-ov-file#installation)

2. In the `modular` directory, run `fga model test --tests store.fga.yaml`
12 changes: 12 additions & 0 deletions stores/modular/core.fga
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module core

type user

type organization
relations
define member: [user] or admin
define admin: [user]

type group
relations
define member: [user]
6 changes: 6 additions & 0 deletions stores/modular/fga.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
schema: '1.2'
contents:
- core.fga
- issue-tracker/projects.fga
- issue-tracker/tickets.fga
- wiki.fga
10 changes: 10 additions & 0 deletions stores/modular/issue-tracker/projects.fga
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module issue-tracker

extend type organization
relations
define can_create_project: admin

type project
relations
define organization: [organization]
define viewer: member from organization
6 changes: 6 additions & 0 deletions stores/modular/issue-tracker/tickets.fga
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module issue-tracker

type ticket
relations
define project: [project]
define owner: [user]
29 changes: 29 additions & 0 deletions stores/modular/store.fga.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: ModularDemo
model_file: ./fga.mod
tuples:
- user: user:anne
relation: admin
object: organization:openfga
- user: organization:openfga
relation: organization
object: space:openfga
- user: organization:openfga
relation: organization
object: project:openfga
tests:
- name: Members can view projects
check:
- user: user:anne
object: organization:openfga
assertions:
admin: true
member: true
can_create_space: true
- user: user:anne
object: space:openfga
assertions:
can_view_pages: true
- user: user:anne
object: project:openfga
assertions:
viewer: true
16 changes: 16 additions & 0 deletions stores/modular/wiki.fga
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module wiki

extend type organization
relations
define can_create_space: admin


type space
relations
define organization: [organization]
define can_view_pages: member from organization

type page
relations
define space: [space]
define owner: [user]

0 comments on commit e9afab0

Please sign in to comment.