Skip to content
For developers

Roles and permissions

On this page

This page covers who may do what in the admin. You need it when the three built-in roles are not enough, or when some fields should be read-only for some people.

Editors change data, developers change structure, and roles are structure. You write them in cms.config.ts, in TypeScript, and the config is checked as it loads. Which role a person has is data: an administrator sets it in Settings → Team.

The built-in roles · Roles of your own · Per-field permissions · The media library · Row-level rules · A role that is removed · Changing someone's role · External sign-in · Worked example: a translator · What is enforced where

The built-in roles

Every site has these three, whatever the config says:

RoleCan
Administratoreverything, plus people (invite, change role, disable, remove), the audit log and privacy
Editorcreate, edit, publish and delete all content; edit site settings; every file in the media library
Authorcreate drafts; edit and delete only what they created; change only the files they uploaded

An author never publishes and never touches settings. An author also cannot change content that is live the moment it is saved.

Only the administrator manages people. This does not depend on a role's name or on what it is based on. No role you define can invite, remove or change anyone.

Roles of your own

A custom role extends a built-in one: from: 'editor' or from: 'author'. It narrows the parent one collection at a time, or for an author it widens it. It can never be, or extend, admin.

The shortest role:

TypeScript
export const roles = defineRoles({
  translator: { from: 'editor', entities: { post: ['read', 'update'] }, publish: false },
})

A fuller example. Export roles from cms.config.ts, above the entities that name the roles.

cms.config.ts
import { defineEntity, defineLocales, defineRoles, defineSingleton, f } from 'tinyzoo'

export const locales = defineLocales({ default: 'cs', locales: ['cs', 'en'] })

// Export it from cms.config.ts, above the entities that name the roles.
export const roles = defineRoles({
  translator: {
    from: 'editor',
    label: { cs: 'Překladatel', en: 'Translator' },   // shown in Team, the account menu and invitations
    description: { en: 'Translates posts and pages; drafts only.' },
    entities: { post: ['read', 'update'], page: ['read', 'update'] },
    publish: false,
    media: 'own',
  },
  // Looks after the people who write: no media library, no say over the site name.
  curator: {
    from: 'editor',
    entities: { author: ['read', 'create', 'update', 'delete'], post: ['read'] },
    media: 'none',
  },
})

export const Author = defineEntity('author', {
  label: 'Authors',
  titleField: 'name',
  fields: {
    name: f.text({ required: true }),
    // Editors and curators read the email, only editors change it; everyone else does not see it.
    email: f.text({ format: 'email' }).optional().access({ read: ['editor', roles.curator], edit: ['editor'] }),
  },
})

export const Post = defineEntity('post', {
  label: 'Posts',
  titleField: 'title',
  fields: {
    title: f.text({ required: true }).localized(),
    // Translators write the text but cannot change the code the site's template reads.
    template: f.text().optional().access({ edit: ['editor'] }),
  },
})

export const Page = defineEntity('page', { label: 'Pages', titleField: 'title', fields: { title: f.text({ required: true }) } })
export const Settings = defineSingleton('settings', { label: 'Settings', titleField: 'name', fields: { name: f.text({ required: true }).access({ edit: ['editor'] }) } })

Settings of a role

SettingMeaning
from'editor' (every entry of every collection) or 'author' (drafts, and only own entries). Required
label, descriptionThe role's name and one sentence. Each is one string or one per admin language. Without a description the admin describes the role from this definition (below)
entitiesWhat the role may do with a collection, by its name: read, create, update, delete. See the rules below
publishMay publish and unpublish, and change what is live. Default: what from has (editor yes, author no). See the rules below
mediaThe media library: 'all', 'own' or 'none' (below). Default: what from has

Rules for entities:

  • A collection you list gets exactly these operations. ['read'] reads, and [] does not see the collection at all.
  • A collection you leave out gets what from allows.
  • Anything but read needs read too.
  • A global has read and update only.

Rules for publish:

  • A role that may not publish writes drafts only. It cannot change an entry that is live, or write content that is live the moment it is saved (a global, redirects).
  • Publish is offered only to a role that may edit the entity's status field and its publish date, because a publish writes both. If you put a field rule on one of them, add the roles that should publish.

Publish rights are role-wide. publish is one switch for the whole site. That holds even when an entity publishes each language on its own. A role cannot be allowed to publish one language only.

What "extends" means

  • A role based on author keeps "own entries only". It changes and deletes only what it created, on every collection it can write. A grant on a global has no owner to ask, so it applies to the one row.
  • A role left out of an entity's list gets what its parent has. A translator based on editor that does not list tag can read tags. List tag: [] to take them away, or tag: ['read'] to say so. Form messages are an editor's to read, so a role based on editor reads them unless you narrow it.
  • The entity's own access rule still applies on top of all this (row-level rules).

Checks when the config loads

The config is refused, with the collection or the field in the message, for:

  • a role named like a built-in
  • a role that extends admin
  • a collection the site does not have
  • an operation a global cannot have
  • update without read

How the admin shows a role

Settings → Team names each role in the invitation and in "Change role" with one sentence. That is your description. When you wrote none, the admin makes a sentence from the definition, in the admin's language. It says what the role changes, what it only reads, whether it publishes, and its files. For the translator above without its description:

Edits Posts and Pages. Only reads Authors, Tags and 2 more. Cannot publish: drafts only. Changes only the files they uploaded.

The sentence is worked out from the same rules the server applies: the role, then each entity's own access rule. So it also covers what a role reaches through what it inherits. A role based on editor that does not list a collection edits it. A role that may not publish only reads content that is live the moment it is saved (a global, the redirects).

What can each role do? on the Team page shows every role side by side, built-in ones included. For each it shows what it changes, what it only reads, whether it publishes, its files, and how many people have it.

Per-field permissions

Each field can say who reads it and who edits it, by role:

TypeScript
body:  f.richtext().access({ edit: ['editor', roles.translator] }),   // the others see it, read-only
cost:  f.number().access({ read: ['editor'], edit: ['editor'] }),     // the others do not see it at all
  • A list names the roles that may. A role missing from it does not see the field (read) or sees it read-only (edit).
  • A rule left out means everyone who may read (or write) the collection.
  • Administrators always may.
  • Editing needs reading. A role in edit must be able to read, and the config is refused when it names one that cannot.
  • Name your own roles by their reference (roles.translator), so a typo is a compile error. Name the built-ins as plain strings ('editor').
  • A role is named exactly. A custom role that extends editor does not get a field because 'editor' is listed. This is on purpose: a new role starts with nothing a field is closed to.
  • A rule is for a field of a collection or global, not for one inside a block, a list or a group. Put it on the group, list or blocks field itself.

A read-only field looks locked in the admin, with a grey fill and a lock in the field. It says who can change it, by the roles' labels: "Only Editor and Administrator can change this." Name the roles you want people to ask.

Some fields cannot be hidden (read), because every screen of the admin shows them:

  • the title
  • the publish state and date
  • the address (content.slug and what content.path uses)
  • the place in a tree
  • the list's order field

They can be made read-only.

What the server does

The server enforces the rules on everything the admin does. The form only follows.

Reading. A field a role may not read is left out of the answer, and out of everything that could show it:

WhereWhat
a list, one entry, the answer to a save, a globalthe field (and its relation or file attachments) is not in the row
the list's search, its sort and its filtersnever by a field the person may not read
the CSV exportno column
history (the list, a version, what changed)the field is not in the snapshots or in "what changed"
the admin search (⌘K)an entry is not found through text in a field the person may not read, and no excerpt shows it
where a file or an entry is used, what links to an entry, the refusal to delete something that is usedan entry that holds it only in a field the person may not read is counted, not named
the admin's schema (/api/cms/_graph)the field is not in it, nor in the list columns, tabs and sections; one that is read-only is marked readOnly: true (a CmsAdminField), and a custom field renderer receives it as its readOnly prop
a draft preview through the content API (?preview, signed in)the page without those fields

Writing. A request that names a field the person may not edit is refused with 403 and { code: 'field_forbidden', fields: [...] }. Nothing in it is saved.

  • It is refused even when the value is the one the field has now. A client leaves out the fields it may not change (the admin does), instead of having a value dropped without a word.
  • This covers creating, saving, a translation, the position a drag writes (arranging a list, moving a page), and removing a translation (which removes every translated field of it).

An omitted field is never overwritten:

  • Saving an entry changes the fields it names.
  • Saving a global replaces it, but leaves a field the person may not edit as it is, with no default put in its place.
  • Creating an entry is the one place a default applies to such a field (a new post starts as a draft).
  • A required field with no default that the person may not write makes creating refuse with a normal validation error. The person cannot make that kind of entry.

Shared editing. A rich-text field with an .access() rule is not edited together with others. The shared document is one for everyone who has the entry open, so it would show the field to people who may not read it. Such a field is edited alone and saved the usual way. A shared document made before a field got a rule is started afresh the next time it is opened.

The public content API is not touched. It follows content.hidden and content.published. To keep a field from visitors, hide it there, whatever the admin's rules say.

The media library

media says what a role may do with the library:

BrowseUploadChange details, deleteWhere it is used
'all'every fileyesevery fileyes
'own'every fileyesonly the files they uploadedyes
'none'nononono

'none' closes the library and its page in the admin: nothing to list, upload, change or delete. Pictures already on an entry stay as they are, shown with it. They are not cleaned up on that person's behalf.

Whoever may not change every file ('own', 'none') can only clean up the files they uploaded themselves.

Row-level rules

An entity's access adds rules about which entries, on top of the role. Each rule is a function of the signed-in person and the table.

The person has role (the name stored for them) and base, the built-in role they are or extend. Test base to treat a custom role like its parent:

TypeScript
access: {
  read: ({ user, table }) => (user.base === 'author' ? not(ilike(table.title, 'Interní%')) : true),
},

A rule on user.role === 'author' does not see a custom role built on author. user.base === 'author' does.

A role that is removed

Take a role out of cms.config.ts and the people who had it keep their accounts but lose all access. It fails closed, and nothing is guessed:

  • They sign in, and the admin shows "Your role no longer exists" with their account page and sign-out. Every other request is refused with 403 and { code: 'role-removed' }. The content API does not show them drafts either.
  • Settings → Team marks each of them, and an administrator gives them another role.
  • tinyzoo status warns, with how many people hold the missing role, before anyone finds out by being locked out.

Define the role again and they have it back, exactly as they were. The name stored with a person is all that connects them.

Roles are not stored anywhere else. cms_users.role is a text column, so adding or removing a role needs no migration.

Changing someone's role

An administrator changes a role in Settings → Team (Change role, with the same sentence per role as the invitation). The change signs the person out on every device:

  • Their sessions end.
  • An open realtime or shared-editing connection is closed.
  • They sign in again with the new role.

Unsaved changes in an editor they had open are lost, so tell them first.

Nobody can change their own role, and the last active administrator cannot be moved to another role. The audit log records the change (user.role, from and to).

External sign-in

With cms.auth.mode: 'external' your app signs people in and sets their role. The names it uses map onto the same definitions: the built-ins, and the roles from defineRoles.

  • On a site that defines roles, every name must be known. A name the site does not define has no access, like a removed role.
  • On a site that defines none, a name the CMS does not know keeps the behaviour it had before 0.6. It reaches every collection, limited only by the entities' own access rules. It may publish. It is never an administrator. Add defineRoles to get the stricter behaviour.

Worked example: a translator

A site in Czech and English. Editors write posts in Czech and publish them. A translator writes the English versions, and an editor decides when they go live. The translator must not change what all languages share (the category), nor touch anything else on the site.

cms.config.ts
import { defineEntity, defineLocales, defineRoles, eq, f } from 'tinyzoo'

export const locales = defineLocales({ default: 'cs', locales: ['cs', 'en'] })

export const roles = defineRoles({
  translator: {
    from: 'editor',
    label: { cs: 'Překladatel', en: 'Translator' },
    description: { cs: 'Překládá články; jen koncepty.', en: 'Translates posts; drafts only.' },
    // Every collection is listed: one left out would get what an editor has.
    entities: { post: ['read', 'update'], tag: ['read'] },
    publish: false,
    media: 'none',
  },
})

export const Tag = defineEntity('tag', {
  label: { cs: 'Štítky', en: 'Tags' },
  titleField: 'name',
  fields: { name: f.text({ required: true }).localized() },
})

export const Post = defineEntity('post', {
  label: { cs: 'Články', en: 'Posts' },
  titleField: 'title',
  fields: {
    title: f.text({ required: true }).localized(),
    slug: f.slug({ from: 'title', unique: true }).localized(),
    body: f.richtext().localized(),
    // Shared by every language. Editors choose it; the translator sees it locked.
    category: f.select({ options: ['news', 'event'] as const, default: 'news' }).access({ edit: ['editor'] }),
    status: f.select({ options: ['draft', 'published'] as const, default: 'draft' }),
    publishedAt: f.datetime().optional(),
  },
  publish: {
    field: 'status', publishedValue: 'published', draftValue: 'draft',
    dateField: 'publishedAt',
    perLocale: true,   // each language has its own state; the default language gates them
  },
  content: { public: true, published: (t) => eq(t.status, 'published'), slug: 'slug', path: '/blog/:slug' },
})

perLocale adds three columns to post_locales. Then:

  1. Run pnpm db:generate and read the migration.
  2. Run pnpm db:migrate.
  3. Give the person the role in Settings → Team.

What the translator sees

Under their name, Translator. In a post's English version:

  • Every field not translated yet shows the Czech text greyed inside it. One line at the top says so (Empty fields show the Czech text in grey until you translate them). Each field offers Use it as a start, which copies the Czech text in.
  • The body offers Show the original beside it: Czech on the left, the translation on the right, on a wide screen.
  • The category has a grey fill and a lock, and under it Only Editor and Administrator can change this.
  • The top bar shows one of three states, with Save translation and no Publish:
    • English · Being translated, for an English version that has never been on the website (the tooltip: Visitors see the Czech version until an editor publishes this one.)
    • English · Draft, once an editor took it off
    • English · Waiting for Czech
  • The media library is not in the sidebar, and pictures already on a post still show.

What the editor sees

  • The list's Languages column shows EN with a mark. The tooltip says it in words.
    • A dot: it is on the website.
    • A ring: a draft.
    • A clock: scheduled.
    • An hourglass: published but waiting for Czech.
    • A languages mark: being translated.
  • The home page's drafts and the search say English · Being translated too.
  • In the English version, Publish… opens Publish the English version. For one being translated it says Until now visitors see the Czech version here. The other languages stay as they are. It lists the fields still in Czech.
  • While Czech is a draft, it also says Czech is still a draft: the English goes on the website together with Czech.
  • Settings → Team → What can each role do? shows the translator's row: Changes Posts, Only reads Tags, Publishes No, drafts only, Files None.

Two things to know before you set this up

A role cannot be limited to one language. entities and .access() hold for an entry in every language. The translator above can also change the Czech text of a post while it is a draft. A live Czech version they cannot change, because a role that may not publish never changes what is live.

Translating a post that is already live just works.

  • The translator opens its English version and saves. The English is being translated: a draft that has never been on the website.
  • Visitors on /en keep reading the Czech text unchanged: the item, the lists, the search, the sitemap and links to it. No webhook says anything changed.
  • The translator saves as often as needed, and may remove it again.
  • An editor reads it in the preview and publishes it. From then on English is live on its own, so it is the editors' to change or take off.
  • A post that is still a draft is simpler: the English follows the draft and goes live with Czech.

What stays locked for the translator is what visitors see:

  • an English version that is live (published, or a translation that follows a live Czech version)
  • publishing, scheduling and unpublishing
  • removing an English version an editor took off, because that would put the Czech text back on /en

Without perLocale none of this exists. Every language of a live post is live, and a role with publish: false can only translate drafts.

The editors' guide says the same for the people doing it: Překlady and Role a oprávnění.

What is enforced where

Entity (read / create / update / delete)publishmediaA field (read / edit)
lists, entries, globals, options of a picker✓read ✓
create, save, global save, translations, arranging, moving✓✓edit ✓
history, export, search, links, "used by"✓read ✓
the realtime feeds and the home page✓titles and states only, never a field
shared editing (socket)✓ (write or read)✓fields with a rule are not shared
the media library and where a file is used✓ (public details of a live file)✓read ✓
people, privacy, auditadministrator only
the MCP server (an access token)✓, and only what the token was given✓, if the token may publish✓, if the token may change filesread ✓ / edit ✓

Every request re-reads the account. Changing someone's role, removing the role from the config or disabling them takes effect on their next request. It also ends an open realtime or shared-editing connection.

Didn’t find what you need?

Write to us. We’re happy to help, and we’ll add it to the guide.

Get in touch

This page’s source on GitHub