API version: 0.3.0

---

# Conditional access

## Conditional access

The following optional properties can be set on `HAS_X_ACCESS`:

- `onLabel`: Limits access to a specific type of nodes.
- `onParentLabel`: Limits access to children of a specific type of nodes, i.e. to elements which are owned (`OWNS`) directly by a node with this label. The label of the element itself does not matter, use `onLabel` for it.
- `onCreatedByUser`: Requires that the element was created by the current user, i.e. the element's `createdBy` property equals the id of the user.
- `onState`: Limits access to elements which currently have a given workflow state.

`HAS_SEARCH_ACCESS` and `HAS_GOVERN_ACCESS` can not carry these properties. Who may find an element is calculated in
advance and stored in the search index, which is only updated when ownership, group membership or search access
relations change, so conditions would silently go stale. Access which is handed out has to hold for the whole element,
so a conditional `HAS_GOVERN_ACCESS` could never be used. Requests which set a condition on one of them are refused with
`400`.

### Limiting access by workflow state

You can model workflows by creating your own `State` nodes and connecting an element to its current state with a
`HAS_STATE` relation. Setting `onState` on a `HAS_X_ACCESS` relation to the `id` of a `State` node then restricts that
access grant to elements which have that state set somewhere along their `OWNS`-chain:

```json graph-example
[
  {"id":"admin","type":"User","data":{"name":"Admin"}},
  {"id":"anonymous","type":"User","data":{"name":"Anonymous"}},
  {"id":"blog","type":"Data","data":{"name":"Blog"}},
  {"id":"post1","type":"Data","data":{"name":"Post 1"}},
  {"id":"post2","type":"Data","data":{"name":"Post 2"}},
  {"id":"state","type":"State","data":{"name":"Active"}},
  {"id":"ownsBlog","type":"OWNS","start":"admin","end":"blog"},
  {"id":"ownsPost1","type":"OWNS","start":"blog","end":"post1"},
  {"id":"ownsPost2","type":"OWNS","start":"blog","end":"post2"},
  {"id":"hasState","type":"HAS_STATE","start":"post1","end":"state"},
  {"id":"readAccess","type":"HAS_READ_ACCESS","start":"anonymous","end":"blog","data":{"name":"onState: Active (id)"}}
]
```

Here the anonymous user only ends up with read access to Post 1, since it is the only element with the `Active` state set -
Post 2 and the Blog node itself are not covered by the grant.

The check walks the `OWNS`-chain upward from the element being accessed to look for a matching `HAS_STATE` relation,
so it is repeated for every element the grant would otherwise cover. Prefer setting the state as close as possible to
the elements it should actually restrict, rather than on a distant ancestor, to keep this cheap.

---

Home: [Ember Nexus API docs](/index.md)

Full site map: [llms.txt](/llms.txt)

Previous: [Handing out access](/reference/access-model/handing-out-access.md)

Next: [Transfer of ownership](/reference/access-model/transfer-of-ownership.md)
