# Managers and their reports

> Let managers see the people who report to them, at any depth you choose.

Source: https://docs.ligament.ai/guides/access/hierarchies/

Give managers access to the people below them, without listing anyone by name. You declare a field such as **Manager** on Person as a hierarchy, then write grants like “people below me in the reporting line”. When someone changes manager, the access follows on the next request.

Two steps: declare the hierarchy, then use it in a permission set.

## Declare a hierarchy

A hierarchy is a reference field that points at the same entity: Person › Manager, or Department › Parent department.

1.  Open **Settings › Access › Hierarchies** and click **Declare hierarchy**.
2.  Fill in the declaration (table below) and click **Plan**, then **Apply**.
3.  Ligament checks the existing data straight after the apply. If it finds no loops and no chain deeper than the maximum, the hierarchy becomes **Active**. Otherwise it stays **Blocked**, grants nothing through it, and the page shows the report. Fix the data, then recheck.

| Setting | What it does |
| --- | --- |
| Key | For example `hr.reporting`. Can’t change later. |
| Entity, field | The entity and its self-reference, for example Person and `manager`. |
| Label | The name people see, for example “Reporting line”. |
| Kind | `primary` for the main line. `secondary` for a dotted line, which counts one level only unless you make it transitive. |
| Max depth | 1 to 64 levels (default 32). A change that would make a chain deeper is refused. |
| When a node is removed | `refuse`: deleting a person who still has reports fails. `reparent_to_parent`: their reports move up to their manager. |
| A member’s node | How Ligament finds “me” in the hierarchy: `user` means the record whose `user` field is the signed-in person. A two-step path such as `holder.user` also works, for positions held by people. |

Northwind Group’s reporting line:

```json
{
  "key": "hr.reporting",
  "entity": "person",
  "field": "manager",
  "label": "Reporting line",
  "kind": "primary",
  "maxDepth": 8,
  "onRemove": "reparent_to_parent",
  "principalVia": "user"
}
```

\[Screenshot: Settings › Access › Hierarchies › Reporting line: active, Person · Manager, max depth 8, 18 nodes, 0 cycles\]

Once a hierarchy is declared, Ligament refuses changes that would break it. Setting Vic Viewer’s manager to someone who reports to Vic gives:

```json
{ "error": "hierarchy_cycle: setting manager would make a loop (Vic Viewer → Hannah Becker → Tomás Ortega → Vic Viewer)", "code": "hierarchy_cycle" }
```

and making Vic their own manager gives `hierarchy_cycle: Vic Viewer can't be their own manager`.

## Grant access down the line

In a permission set grant, compare a field with one of these tokens, using the `in` operator:

| Token | Matches |
| --- | --- |
| `@me.descendants` | everyone below me |
| `@me.descendants_or_self` | everyone below me, and me |
| `@me.ancestors` | everyone above me: my manager, their manager, and so on |

Add `depth` to limit how many levels count. On Person, `{{id}} in @me.descendants`:

| `depth` | Who matches |
| --- | --- |
| none | all my reports, at every level |
| `{ "max": 1 }` | my direct reports only |
| `{ "min": 2 }` | reports of my reports, and further down |

Add `"via": "<hierarchy key>"` when the entity has more than one hierarchy and you need to say which one. The `within` operator takes record ids instead and matches everything under them, for example everyone in a department and its sub-departments.

In the condition builder, pick **Record**, **is one of**, **My hierarchy** and **below me**, then fill in the levels.

### Example: Northwind’s team leads

The Facilities team in Northwind Group looks like this:

```text
Vic Viewer (Facilities team lead)
├── Tomás Ortega (Facilities coordinator)
│   └── Hannah Becker (Facilities assistant)
└── Ravi Menon (Workplace technician)
```

The permission set `people.my_team` grants read and update on Person where `{{id}} in @me.descendants`, and the role Team lead holds it. Vic’s seat is viewer, which can only read people, but with Team lead Vic can update Tomás, Hannah and Ravi, and nobody else. Explaining Vic’s access gives:

```text
allow: true   reason: granted
rows: id is below you in Reporting line: 3 today
set people.my_team (role "team_lead", direct): allow update where id in @me.descendants
visible because Hannah Becker → Tomás Ortega → Vic Viewer (you) (hr.reporting, 2 levels)
```

To limit team leads to their direct reports, add `"depth": { "max": 1 }`. The plan for that change shows Vic’s update access going from 3 people to 2, because Hannah reports to Tomás, not to Vic. See [Reviewing access changes](https://docs.ligament.ai/guides/access/reviewing-access-changes/index.md).

### Other entities

A grant on another entity can walk the same hierarchy through a field that references a person. For example, on an entity with an `employee` field that points at Person, `{{employee}} in @me.descendants` matches the records of everyone below me.

## What people see

-   The [Why panel](https://docs.ligament.ai/guides/access/why-can-i-see-this/index.md) on a record shows the path that gave access, such as “Visible because Hannah Becker → Tomás Ortega → you (Reporting line, 2 levels)”.
-   When an admin uses [View as](https://docs.ligament.ai/guides/access/view-as/index.md) for a manager, the banner says how big their reporting line is: “reporting line of 3 people”.
-   A manager going on leave can hand their line to someone else for a while: see [Delegations](https://docs.ligament.ai/guides/access/time-bound-access/index.md#delegations).

## Through the API

`GET /api/access/hierarchies` lists the declared hierarchies with their status and data report. Declarations are documents at `hierarchy/<key>`, planned and applied like roles and sets. If a hierarchy is blocked, fix the data and recheck it with `POST /api/access/hierarchies/<key>` and `{"action":"recheck"}`. All endpoints: [Access](https://docs.ligament.ai/reference/rest-api/index.md#access).
