Skip to main content

API Policies

API Policies ensure that we provide specific access to resources for users. They are a way to implement Authorization.

Entity rulesโ€‹

Each entity has 5 rules where one or several access policies can be applied:

  • create: create a new item
  • read: see the detail and the list of items
  • update: update an existing item
  • delete: delete an existing item
  • signup: sign up as a new user (if entity is authenticable)

Access policiesโ€‹

The policies for each rule can be added to each entity description as shown below:

entities:
๐Ÿงพ Invoice:
properties:
- number
- { name: issueDate, type: date }
policies:
create:
- { access: restricted, allow: User }
update:
- access: admin
delete:
- access: forbidden

In this case, everyone can see the Invoice items, only logged-in Users can create new ones. Updating an Invoice is restricted to Admins only and no one can delete them (not even Admins).

info

If no policy is specified for a rule, it means that there are no restrictions for the related action.

PropDescriptionType
accessThe type of access: public, restricted, admin, forbiddenAccessType
allowOnly for restricted access: the entity (or entities) that have accessstring | string[]

Access typesโ€‹

There are 4 possible access types:

AccessDescriptionShort version (emoji)
publicEveryone has access๐ŸŒ
restrictedOnly logged-in users have access to it. If allow key specifies one or several entities, users logged in as other entities will not have access. Admins always have access to restricted rules๐Ÿ”’
adminOnly admins have access๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป
forbiddenNo one has access, not even admins๐Ÿšซ

Additional examplesโ€‹

entities:
๐Ÿ—‚๏ธ Project:
properties:
- name
policies:
read:
- { access: restricted, allow: [Contributor, Manager] } # Only some entities (and admins).
create:
- { access: restricted, allow: Manager } # Only managers (and admins).
update:
- access: ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป # Only admin.
delete:
- access: ๐Ÿšซ # Forbidden (no one).

๐Ÿ‘จโ€๐Ÿ’ผ Contributor:
authenticable: true
properties:
- name
policies:
signup:
- access: ๐Ÿšซ # Forbidden (no one).
create:
- { access: ๐Ÿ”’, allow: Manager } # Managers can create contributors.
update:
- { access: ๐Ÿ”’, allow: Manager }
delete:
- { access: ๐Ÿ”’, allow: Manager } # Managers can create contributors.