API version: 0.3.0

---

# Access to nodes and relations

## Access to nodes

Nodes can be directly owned, as `OWNS`-relations can directly point to them:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"data","type":"Data","data":{"name":"Data"}},
  {"id":"owns","type":"OWNS","start":"user","end":"data"}
]
```

## Access to relations

Relations can not be directly owned, as relations can not point to other relations - the underlying storage is a regular graph, not a hypergraph.

Instead, a relation is "owned", when the user owns the relation's start and end nodes.\
In the following example, the user has `OWNS`-access to both the start and end nodes, and therefore he also has
`OWNS`-access to the `RELATION`:

```json graph-example
[
  {"id":"user","type":"User","data":{"name":"User"}},
  {"id":"start","type":"Data","data":{"name":"Start"}},
  {"id":"end","type":"Data","data":{"name":"End"}},
  {"id":"relation","type":"RELATION","start":"start","end":"end"},
  {"id":"owns1","type":"OWNS","start":"user","end":"start"},
  {"id":"owns2","type":"OWNS","start":"user","end":"end"}
]
```

Which access a relation requires depends on the operation. Both nodes are checked separately, and `OWNS` always counts
as the required access:

| Operation                            | Start node requires | End node requires |
| ------------------------------------ | ------------------- | ----------------- |
| Read the relation (`GET`)            | read access         | read access       |
| Create a relation (`POST /`)         | create access       | read access       |
| Update the relation (`PATCH`, `PUT`) | update access       | read access       |
| Delete the relation (`DELETE`)       | delete access       | read access       |

Changing or removing a relation only changes the start node's outgoing relations, which is why the end node only has to
be readable, the same as when the relation is created. `HAS_x_ACCESS` never implies read access: a user who only has
`HAS_UPDATE_ACCESS` to the end node can not update the relation.

Elements which a user can see, but may not change or delete, are answered with `403 Forbidden`, as they exist for the
user. Users can see a node if they can read it, and a relation if they can read both of its nodes. Elements which a user
can not see do not exist for them, and are answered with `404 Not Found`. This is the case for nodes, pointer relations
and grant relations alike, and for creating elements as well: a request to create a relation or a node under a node
which the user can read, but lacks the required access to, is answered with `403`; if the node can not be read, or if
the end node of a new relation can not be read, with `404`.

Deleting a node only requires delete access to the node itself. Relations attached to the node are removed together with
it, regardless of the user's access to them.

The access paths for both the start and end nodes do not have to share any elements. They can, but they are not required to.

---

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

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

Previous: [Access model](/reference/access-model.md)

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