# Entities

_WORK IN PROGRESS_

Kazana comes with a build in CMS for entities. A generic UI is accessible
at `/kazana/entities` to list and edit entities. By default, all entities
are accessible by signed in users, and can be managed by admins only. Entities
can be configured using the `entities` key in the
[Kazana manifest](../api/kazana-manifest.md#entities). Entities are stored
in the [entities database](data.md#entities).

## Access

_TO BE DONE_

## Hierarchies

An entity type can belong to another, for example a district can belong to
a region, and a region can belong to a zone. Entity hierarchies are defined
with the `belongsTo` property in the [entities option of the Kazana manifest](../api/kazana-manifest.md#entities).

If an entity belongs to another, it’s ID is prefixed with the parent entity’s id,
so for a district belonging to a region, the id could be

```
  id: 'zone:uuid123:region:abc4567:district:def8910'
```

That way all parent entity IDs are directly accessible, which is useful when
used as user roles. When a user gets assigned to the above entity, all roles
get added:

```
  roles: [
    'entity:zone:uuid123',
    'entity:zone:uuid123:region:abc4567',
    'entity:zone:uuid123:region:abc4567:district:def8910'
  ]
```

## Search

Search is possible using [CouchDB 2’s query feature](https://docs.cloudant.com/cloudant_query.html)
and the `?filter=` param, so for example `GET /kazana/entities/api/regions?filter`

Note that full text search is not supported, but can be implemented using a
plugin. See https://cloudant.com/blog/enable-full-text-search-in-apache-couchdb
for how to implement full text search in CouchDB.
