model: |
  model
    schema 1.2

  type user

  type team
    relations
      define member: [user]

  type folder
    relations
      define viewer: [user, team#member]

  type document
    relations
      define parent: [folder]
      define viewer: [user] or viewer from parent
      define can_view: viewer

tuples:
  # -------------------------------------------------------------------------
  # Folder → document parent hierarchy
  # folder:N is the parent of document:N-M  (N folders, N docs each)
  # Total: 55 tuples  (1+2+3+...+10)
  # -------------------------------------------------------------------------

  # folder:1
  - user: folder:1
    relation: parent
    object: document:1-1

  # folder:2
  - user: folder:2
    relation: parent
    object: document:2-1
  - user: folder:2
    relation: parent
    object: document:2-2

  # folder:3
  - user: folder:3
    relation: parent
    object: document:3-1
  - user: folder:3
    relation: parent
    object: document:3-2
  - user: folder:3
    relation: parent
    object: document:3-3

  # folder:4
  - user: folder:4
    relation: parent
    object: document:4-1
  - user: folder:4
    relation: parent
    object: document:4-2
  - user: folder:4
    relation: parent
    object: document:4-3
  - user: folder:4
    relation: parent
    object: document:4-4

  # folder:5
  - user: folder:5
    relation: parent
    object: document:5-1
  - user: folder:5
    relation: parent
    object: document:5-2
  - user: folder:5
    relation: parent
    object: document:5-3
  - user: folder:5
    relation: parent
    object: document:5-4
  - user: folder:5
    relation: parent
    object: document:5-5

  # folder:6
  - user: folder:6
    relation: parent
    object: document:6-1
  - user: folder:6
    relation: parent
    object: document:6-2
  - user: folder:6
    relation: parent
    object: document:6-3
  - user: folder:6
    relation: parent
    object: document:6-4
  - user: folder:6
    relation: parent
    object: document:6-5
  - user: folder:6
    relation: parent
    object: document:6-6

  # folder:7
  - user: folder:7
    relation: parent
    object: document:7-1
  - user: folder:7
    relation: parent
    object: document:7-2
  - user: folder:7
    relation: parent
    object: document:7-3
  - user: folder:7
    relation: parent
    object: document:7-4
  - user: folder:7
    relation: parent
    object: document:7-5
  - user: folder:7
    relation: parent
    object: document:7-6
  - user: folder:7
    relation: parent
    object: document:7-7

  # folder:8
  - user: folder:8
    relation: parent
    object: document:8-1
  - user: folder:8
    relation: parent
    object: document:8-2
  - user: folder:8
    relation: parent
    object: document:8-3
  - user: folder:8
    relation: parent
    object: document:8-4
  - user: folder:8
    relation: parent
    object: document:8-5
  - user: folder:8
    relation: parent
    object: document:8-6
  - user: folder:8
    relation: parent
    object: document:8-7
  - user: folder:8
    relation: parent
    object: document:8-8

  # folder:9
  - user: folder:9
    relation: parent
    object: document:9-1
  - user: folder:9
    relation: parent
    object: document:9-2
  - user: folder:9
    relation: parent
    object: document:9-3
  - user: folder:9
    relation: parent
    object: document:9-4
  - user: folder:9
    relation: parent
    object: document:9-5
  - user: folder:9
    relation: parent
    object: document:9-6
  - user: folder:9
    relation: parent
    object: document:9-7
  - user: folder:9
    relation: parent
    object: document:9-8
  - user: folder:9
    relation: parent
    object: document:9-9

  # folder:10
  - user: folder:10
    relation: parent
    object: document:10-1
  - user: folder:10
    relation: parent
    object: document:10-2
  - user: folder:10
    relation: parent
    object: document:10-3
  - user: folder:10
    relation: parent
    object: document:10-4
  - user: folder:10
    relation: parent
    object: document:10-5
  - user: folder:10
    relation: parent
    object: document:10-6
  - user: folder:10
    relation: parent
    object: document:10-7
  - user: folder:10
    relation: parent
    object: document:10-8
  - user: folder:10
    relation: parent
    object: document:10-9
  - user: folder:10
    relation: parent
    object: document:10-10

  # -------------------------------------------------------------------------
  # Team → folder viewer grants
  # -------------------------------------------------------------------------
  - user: team:design#member
    relation: viewer
    object: folder:3

  - user: team:product#member
    relation: viewer
    object: folder:5

  - user: team:engineering#member
    relation: viewer
    object: folder:10

tests:
  - name: Team folder access propagates to documents
    check:
      # team:design#member is viewer of folder:3, so members can view its docs
      - user: team:design#member
        object: document:3-1
        assertions:
          can_view: true
      # team:design has no access to folder:5 (granted only to team:product)
      - user: team:design#member
        object: document:5-1
        assertions:
          can_view: false
