Teams
Teams holds the teams crew work in: the bars of a festival operation, a first aid team of the platform. Each team
has a kind, and the kind's ladder holds the roles its members can have. Your app defines its kinds and ladders, such
as a bar ladder of volunteer, bartender, lead and coordinator. Staff add members by hand, or
add mapping rules so that everyone with a global role or a plan holds a team role on their own: a global supervisor
is a lead in every bar of an operation.
It is the source of team roles for the team grant kind of Auth's record audiences and the volunteering
modules, such as Crew. For permissions that code checks, use
Authorization instead.
The package is @frigear-nu/teams. It owns owner references, and registers the team grant kind of
record audiences.
What you get
- Admin area (opt-in, with Admin): a team list at
/admin/teams, filterable by owner, and a team page at/admin/teams/:idwith its members, mapping rules, the projects it works on and the ladder of its kind; a project list at/admin/projectsand a project page at/admin/projects/:id. The sidebar entries needs Menu. With Widget, a Teams tab on the operation page of Operations (@frigear-nu/operations). - Public pages (on by default): a list and a page per team for each public section (
/teamsand/teams/:slug), and/projectsand/projects/:slug, for teams and projects staff made public. Each kind picks its section. Members choose themselves whether they are shown there. See Public pages. - Server routes (on by default): your own teams and roles, the public team reads, a team's page and members, and a staff API for teams, members, mapping rules and ladders.
- Server helpers (auto-imported):
resolveTeamRoles,teamMembersandisTeamLeadfor other modules. - Hooks:
teams:member:added,teams:member:removed,teams:member:role-changed, and the provider hooksteams:roles:resolveandteams:members:candidates. - OAuth claim: a
teamsclaim in id tokens and userinfo, with OAuth Server. - Emails. None built in. Send one from
teams:member:added.
@nuxthub/core, and @nuxt/ui for the pages.
Optional:Admin for the admin pages, Widget for the tab on
the operation page, Menu for the sidebar entry,
Subscriptions for plan rules, OAuth Server for
the claim, and Authorization so mapped members can be listed.Quick setup
Install Teams
pnpm add @frigear-nu/teams @nuxthub/core
Add it to nuxt.config.ts
List Admin (or Widget and Menu) before Teams, so the tab and the menu entry register.
export default defineNuxtConfig({
modules: ['@nuxthub/core', '@frigear-nu/admin', '@frigear-nu/teams'],
teams: {
settings: {
pages: { admin: true, adminTeam: true },
},
},
})
Generate the migration
pnpm db:generate
Decide who manages teams
teams:manage, nobody can manage teams. The admin role holds it when your app defines it; grant it to your own
roles by name (authorization.roles.<role>.grant: ['teams:manage', 'teams:pii']).supervisor is lead" for every team of the operation. A user with the global role supervisor now
sees the bar with the role lead and source: 'mapped' at GET /api/teams/me, without being added.Options
Options go under the teams key.
| Option | Type | Default | Purpose |
|---|---|---|---|
ladders | Record<kind, { label?, description?, section?, roles, leadFrom? }> | the generic default ladder (member, lead) | Your app's ladders by team kind, stored on the first request. Your app's ladders sit next to the shipped ones; a kind of the same name replaces the shipped one. Seed only: see Ladders. |
imageUpload | boolean | false | An image upload in the staff team and project forms, stored in NuxtHub Blob (turns Blob on) and shown on the public pages. |
maxImageBytes | number | 2 MB | The largest image upload. |
seed | { enabled?, teams?, projects? } | off, none | Teams and projects to create when their slug is free. See Seed teams and projects. |
settings.pages.public | string | boolean | true | The public pages: a list at /<section> and a team page at /<section>/:slug for every section, and /projects and /projects/:slug. A string puts them under that prefix ('/crew' gives /crew/teams and /crew/projects); false turns them off. |
settings.pages.admin | string | boolean | off | The staff team list. true is /admin/teams. |
settings.pages.adminTeam | string | boolean | off | The staff team page. true is /admin/teams/:id. |
settings.pages.adminProjects | string | boolean | off | The staff project list. true is /admin/projects. |
settings.pages.adminProject | string | boolean | off | The staff project page. true is /admin/projects/:id. |
settings.operationsTab | boolean | true | Add the Teams tab to the admin.operations tab area. |
ladders label and description (Translated, optional) name the kind in the kind selects of the admin and on
the public pages; without a label the key is shown title-cased (first-aid is "First aid"). They are read from the
option every time, not stored, so changing them applies to a stored ladder too. So is section, the kind's public
section. Roles are { key, label }, lowest first. Keys are lower case (a-z, 0-9, -, _). leadFrom is
the lowest role that leads a team of that kind. An invalid ladder fails the build. A kind is stored on the first boot
that sees it; changing its option later does not overwrite the stored row, so edit a stored ladder in admin.
export default defineNuxtConfig({
teams: {
ladders: {
bar: {
label: { en: 'Bar', da: 'Bar' },
description: { en: 'Serves at the bars of an operation.', da: 'Står i barerne til en operation.' },
roles: [
{ key: 'volunteer', label: { en: 'Volunteer', da: 'Frivillig' } },
{ key: 'bartender', label: { en: 'Bartender', da: 'Bartender' } },
{ key: 'lead', label: { en: 'Lead', da: 'Leder' } },
{ key: 'coordinator', label: { en: 'Coordinator', da: 'Koordinator' } },
],
leadFrom: 'lead',
},
firstaid: {
roles: [{ key: 'helper', label: { en: 'Helper', da: 'Hjælper' } }, { key: 'medic', label: 'Medic' }],
leadFrom: 'medic',
},
},
},
})
Permissions
Teams registers these permissions with Authorization.
| Name | Flags | Held by default | What it allows |
|---|---|---|---|
teams:read | implicit | every signed-in user | Read the teams you belong to, your role and who else is on them. |
teams:lead | implicit | every signed-in user | Lead the teams where you hold a lead role. Other modules check it on a team. |
teams:manage | admin | Create teams, manage members, mapping rules and ladders. | |
teams:pii | sensitive | admin | See the email addresses of team members. |
- Scope: a token may use the named scope
teamsorteams:readitself. Either reads your teams and their members, never the staff routes.teams:piiis usable as a scope too. - Why
teams:pii: a member list shows names and avatars to everyone on the team. Emails are other people's contact details, so they sit behind a separate grant. It ends in:pii, so it is sensitive:teams:*and*never cover it, and it is only held when granted by name. - Policy on
teams:read: a team is readable by the people who hold a role on it, explicit or mapped, and by callers withteams:manage. Anyone else gets403. - Policy on
teams:lead: the caller holds a role on the record's team at or above the ladder'sleadFrom(leadand up on the bar ladder above), explicit or mapped. The record is a team, or any record with ateamId.
// In another module's policy, for a record with a teamId:
definePolicy('shifts:lead', async ({ event, user, record }) => record ? isTeamLead(event, user.id, record.teamId) : undefined)
isTeamLead and teamGrantOf load the caller's team roles once per request and answer later checks from that, so a
policy that calls them
stays off the database after the first
check. A list of the caller's teams filters in its query instead.
Server
Everything under /api is in the Routes section. This section covers what other modules build on.
Role ladder
A person climbs a ladder of team roles on a team. Staff above it hold global roles.
volunteer → bartender → lead → coordinator team roles, per team (Teams)
admin, and your app's own global roles global roles (Authorization)
- Team roles are held per team. A person can be a lead at one bar and a volunteer at another. Teams stores explicit memberships and resolves mapped ones when they are read.
- Ladders are per team kind, lowest first, with keys in lower case. The module ships one generic
defaultladder (member,lead); your app defines its own kinds, such as the bar ladder above or first aid, with theladdersoption. - A grant can reach a whole kind. A
teamgrant names one team or every team of a kind; the kind's ladder decides who is at or above itsminRole(see Grants). - Global roles stay in Authorization. They grant staff permissions, and
mapping rules turn them into team roles: a global
supervisoris alead.
Team roles
resolveTeamRoles(event, userId, { type: 'operation', id: operationId }) // TeamRoleGrant[] on that owner
A grant is { ownerType, ownerId, teamId, kind, role, source }, and source is explicit or mapped. ownerId is
null for a platform-owned team, as in an OwnerRef. Modules that only need to know who may see a record never
call resolveTeamRoles: they store a team grant and let Auth evaluate it (see
Grants), so they do not import teams.
- Explicit memberships are the rows of
team_memberswhosestatusisnullor'active'. They come first. See Membership status. - Mapping rules give the other teams a mapped grant. A
rolerule matches a global role of the user, closed overinherit, from Auth'sgetEffectiveRoles, unless the user also holds one of the rule'sexceptroles. Aplanrule matches an active subscription. Listeners ofteams:roles:resolveadd more. In the rule form staff pick the role with Authorization'sRoleSelectand the plan with Subscriptions'PlanSelectwhen those modules are installed, and type the key otherwise. - Explicit beats mapped on the same team, whatever the rule. Any explicit row counts, whatever its
status: apendingorinactivemember gets no mapped role on that team either. - Between mapped rules on one team, the highest
prioritywins, then the higher role on the ladder. - A rule whose
teamRoleis not on a team's ladder skips that team.
Mapped grants are never stored. Every request reads the rules and the user's roles again, and caches the result for
the rest of that request. teams:roles:resolve fires only when there are rules in play: a source with no rule rows
gives no grants.
Errors fail closed. A teams:roles:resolve listener that throws loses the grants it pushed (and so do the
listeners after it); the explicit memberships and teams' own role rules still count. A plan that cannot be checked is
not held. A team grant admits nobody, and the OAuth claim is left out, when resolution fails; the claim is also left
out when a teams:roles:resolve listener throws, rather than issued without that listener's teams. Each failure is
logged.
Membership status
status on a membership belongs to the module that uses it: crew sets it next to its own crew status. Teams reads
one thing from it: a row grants its role only when status is null or 'active'. Any other value, such as
'pending' or 'inactive', keeps the person listed on the team for staff and leads, with the status, without a
grant: they cannot read the team, do not lead it, and no team grant admits them. The row also overrides mapping, so a
mapping rule gives them no role on that team. The members list shows such rows, and every row's status, only to callers
with teams:manage or a lead role on the team; other members see only the rows that grant. isTeamLead(event, userId, teamId) and teamMembers(event, teamId, { mapped }) use the same
cache.
Mapping rules
A rule belongs to an owner, like a team: ownerType and ownerId, with ownerId: null for the platform.
| Field | Value |
|---|---|
teamId | One team of the owner, or null for every team of the owner. |
match | { role: 'supervisor' } or { plan: 'yearly' }, exactly one of the two; anything else is 400. A role match may add except: global roles whose holders it leaves out. |
teamRole | A role key of the team's ladder. For every team, a key of at least one ladder. |
priority | An integer, 0 by default. Higher wins. |
A role rule matches the roles that inherit its role too, so a rule for supervisor also maps every admin when admin
inherits supervisor. except leaves them out, inheritance included: { role: 'supervisor', except: ['manager'] }
matches supervisors but not managers or the roles above them. The rule's own role cannot be in except.
role rules work out of the box. plan rules need Subscriptions: Teams answers
them from a server plugin it registers only then, with hasActiveSubscription. Plans are identified by their plan key.
Ladders
Each team kind has one ladder in team_role_ladders. The module option's ladders, and the default one the module
ships, are stored on the first request when their kind has no row yet. They are never overwritten, so admins may edit them.
Until a kind is stored, the option's ladder applies.
ladders option only seeds. Once a kind is stored, the stored row wins, edited or not: adding a role to that kind
in nuxt.config, or changing its leadFrom, changes nothing. Edit a stored ladder in the admin (the team page, or
PUT /api/admin/teams/ladders/:kind). A kind that is new in the option is still stored on the first request after the
next start.A ladder cannot drop a role that an explicit member of a team of that kind holds, that a rule for one such team maps
to, or that a rule for every team of an owner maps to when that owner has a team of the kind: 409 with the code
team_role_in_use and the roles in data.roles.
Members
teamMembers(event, teamId, { mapped?, pii? }) lists the explicit members, highest role first. With mapped: true it
also lists the people a rule gives a role on the team. Mapped members are not rows, so Teams finds the candidates and
checks each one:
- the holders of a role the team's rules name, or of a role that inherits one, from Auth's
listRoleHolders. Authorization provides them; without it (or another role provider withholders) nobody is listed this way; - users with an entitled subscription (
activeortrialing, not ended) to a plan the rules name, when Subscriptions is installed; - the user ids that
teams:members:candidateslisteners add.
A role that comes only from defaultRoles, an auto role or an authorization:roles listener cannot be enumerated,
so those people are not listed, although they do hold the role. At most 1000 candidates are checked, in bulk: Teams
loads the candidates and their assigned roles at once (Auth's loadAuthUsers and primeAssignedRoles, through the role
provider's assignedRolesOf), checks role rules in memory and plan rules with one Subscriptions query, so the
number of statements does not grow with the candidates (each lookup is chunked for D1). Rules of other kinds go to the
teams:roles:resolve listeners once per candidate (see Hooks). That is why
mapped members are on demand only: ?include=mapped on the API (staff with teams:manage and the team's leads,
403 for anyone else), and a switch on the team page that starts off. A candidate source that fails is logged and
adds nobody.
Grants
Teams registers the team kind of Auth's record audiences:
| Kind | Keys | Admits | members |
|---|---|---|---|
team | teamId, minRole | Signed-in users holding minRole, or a role above it on the ladder of the team's kind, on that team. Explicit and mapped roles count; a membership whose status gives no grant does not. | The team's members at or above minRole, mapped ones included (see teamMembers). |
team | teamKind, minRole | The same on any team of that kind, whoever owns it: every bar of every operation. | The members at or above minRole of every team of the kind. |
[
{ "kind": "team", "teamId": "tem_123", "minRole": "lead" },
{ "kind": "team", "teamKind": "bar", "minRole": "bartender" }
]
A grant has either teamId or teamKind, never both. The ladders stay inside Teams: a grant names a team or a kind
and a role key, and Teams compares them on the kind's ladder (roleAtLeast(keys, held, min) from
@frigear-nu/teams/utils). A role that is not on the ladder admits nobody. A grant naming a team that does not exist,
a kind without a ladder, or a role off the ladder, is refused when it is stored. In <GrantsEditor> the field picks
one team or a team kind, then a role of its ladder. The team list searches on the server (the name, in any language),
so every team can be picked, and shows each team's owner (the operation's name, or Platform) under its name, since
teams of several operations often share one. teamGrantSchema, isTeamKindGrant and the TeamGrant,
TeamIdGrant and TeamKindGrant types are exported from @frigear-nu/teams/utils.
Owners
Teams owns owner references: the ownerType / ownerId columns and their type, OwnerRef ({ type, id }) and
OwnerType. Other modules that store an owner (help-center categories, mailboxes) import the type from @frigear-nu/teams; there
is no global list of owner types. resolveTeamsOwner(event, owner) answers an owner's label and whether it exists,
through the teams:owner:resolve hook:
| Owner type | Answered by |
|---|---|
platform | Nobody: it has no id (ownerId: null). |
team | Teams: the team's name, and whether it exists. |
operation | Teams, from the operations table, when Operations is installed. |
| Anything else | Your app, from a teams:owner:resolve listener. |
A team is created for an owner. The platform has no id (ownerType: 'platform', ownerId: null). Any other owner
must exist according to teams:owner:resolve. An unknown id, or an owner type nobody answers, is 400. The owner and
the kind of a team are fixed once it exists.
Owners are found by name through the teams:owner:search hook, which Teams answers for team and operation (the
same tables as above). searchTeamsOwners(event, type, q, limit) runs it and answers { results, searchable }. To make
your own owner type searchable, set searchable and push at most limit results whose name contains q (an empty
q lists the first ones), ordered by name:
export default defineNitroPlugin((nitro) => {
nitro.hooks.hook('teams:owner:search', async (ctx) => {
if (ctx.type !== 'venue') return
ctx.searchable = true
ctx.results.push(...(await findVenues(ctx.q, ctx.limit)).map(venue => ({ id: venue.id, label: venue.name })))
})
})
OAuth claim
With OAuth Server installed, an application granted teams or teams:read gets a
teams claim in the id token and from userinfo:
{ "teams": [{ "id": "tem_...", "ownerType": "operation", "ownerId": "opr_...", "kind": "bar", "role": "lead", "source": "mapped" }] }
Access tokens never carry it, and an existing teams claim is never replaced. The same application reads the members
of those teams with GET /api/teams/:id/members and a bearer token.
Public pages
A team is public when staff turn on Show on the public pages and it has a URL name (slug); anything else is a
404 on the public routes, the same as an unknown slug. Every team has optional startsAt and endsAt, shown on the
public page when set. Projects have public pages of their own: see Projects.
The public reads have no authorize: anonymous callers are welcome, so each answer is an allowlist. The list has the
slug, name, kind and its label (kindLabel), description, image and dates. The team page adds contactEmail, form,
members and projects:
formis{ slug, name }of the formformRefnames (a form id, or a slug) when Forms is installed and that form is published; otherwisenull. Without Forms nothing is looked up. The page's Apply button links to the form page (forms.settings.pages.form). Store the id: a slug can be renamed.memberslists only the members who chose to be shown (showPublicly) and whose membership grants (statusnulloractive): their name, their avatar (none when they opted out of photos) and their role's label. No ids and no emails.projectsare the public projects the team works on (slug,name,imageand the link'snote); see Projects. A project that is not public, or has no slug, is left out.
Visibility. A member is hidden until they turn on Show me on the public page on their dashboard item
(PUT /api/teams/me/:teamId/visibility, explicit memberships only). Staff can set it too, from the member slideover
on the admin team page (showPublicly on PATCH /api/admin/teams/:id/members/:userId). Each change records who set it
and when (showPubliclySetBy, showPubliclySetAt); the member DTO says whether it was the member themselves
(showPubliclySetBy.self), and the admin member table shows "Their own choice" or "Set by
Image. With imageUpload, the staff form uploads a PNG, JPEG or WebP (at most maxImageBytes, 4096 pixels each
way) to PUT /api/admin/teams/:id/image. It is served publicly by GET /api/teams/images/:teamId/:file, cached for a
year (each upload has a new name). Replacing, removing or deleting the team deletes the old file.
Form picker. The staff form shows the FormSelectField component of Forms (on value-key="id") when Forms is
installed and registers it, and a plain text input for the form id otherwise. Its search runs on Forms' admin list, so
it needs forms:manage.
Sections
Every kind is listed in one public section. A ladder's section names it: { path, label, itemLabel? }, with
label the plural ("Festivals") and itemLabel the singular ("Festival"), both Translated. A kind without one, or a
kind that only exists as a stored ladder, is in the default teams section (Teams / Hold, singular Team / Hold). Two
kinds may share a section; the first kind's labels name it.
export default defineNuxtConfig({
teams: {
ladders: {
festival: {
section: { path: 'festivals', label: { en: 'Festivals', da: 'Festivaler' }, itemLabel: { en: 'Festival', da: 'Festival' } },
roles: [{ key: 'crew', label: 'Crew' }],
},
},
},
})
- URLs. The module registers one list page (
/<path>) and one team page (/<path>/:slug) per section it knows at build time, from theladdersoption and the shipped ladders. A list shows only the teams whose kind is in its section. - Paths are lowercase letters, numbers and dashes, and may not be
api,admin,account,dashboard,auth,oauth,login,logout,register,forms,operations,me,public,images,new,editorprojects(the project pages). A bad path fails the build. - Redirects. Slugs are unique across every section. A team asked for under another section's path
(
/teams/gardenfor a festival) answers301to its own section (/festivals/garden). - Links. The public DTOs and
GET /api/teams/mecarrysection(the path). Build links withuseTeamLinks().publicTeam(section, slug)andpublicList(section), never a hard-coded/teams. - Wording. The pages use the section's labels: the heading, "Festival members", "Apply to the festival", the empty state and the back link. The admin list always says "Teams".
Projects
A project (FGR, a film, a festival build) is something several teams work on, led by its project leads. It is not a
kind of team: it has a table of its own (projects), its own small list of leads and members (project_members,
role lead or member) and the teams working on it (project_teams). The volunteers belong to those teams.
- Fields. Like a team's public fields: an owner (platform or operation, as on teams), a Translated
nameanddescription,slug,public,image,contactEmail,formRef,startsAt,endsAtandsort. The staff list filters by owner and by status from the dates (upcoming,active: started or undated and not ended,ended). - Teams on a project are managed on the project page ("Teams on this project"), each with an optional Translated
note(what the team does there) and asort. A team is linked once per project (409 conflict); an unknown team is a400. The team page lists its projects read-only. - Access. Everything takes
teams:manage. A project lead gets no extra rights: the role is who leads the project and is shown on its page. - Public pages.
/projectslists the public projects (public, with a URL name);/projects/:slugshows the image, description, dates, the public teams on it with their note, the leads and members who chose to be shown, Apply and Contact. The answers are allowlists like the team ones: no ids, no emails. A member shows themselves withPUT /api/teams/me/:projectId/visibility(the project id in place of a team id); staff set it withshowPubliclyon the member. - Page.
contentis the body of the public project page: Markdown with MDC components, Translated (one text, or one per language). The admin project page shows a preview in a Page section; Edit page (or Write page) opensContentEditorin a wide modal, full screen on phones, with a tab per language and Save page / Cancel (closing with unsaved changes asks first). It offers the components the app registers inappConfig.frigearUi.contentComponents./projects/:slugrenders it in the visitor's language with<MDC>(Nuxt Content or@nuxtjs/mdc, from your app) in aproseblock, or as plain Markdown without MDC.descriptionstays the short summary for the lists and the page's meta description. At most 100,000 characters per language; empty texts are dropped, and nothing left clears it. - Images are stored like team images (
teams/<projectId>/in Blob) and served byGET /api/projects/images/:projectId/:file. WithimageUpload, the page editor uploads images too (toolbar,/menu, paste and drop; PNG, JPEG or WebP up tomaxImageBytes) toPOST /api/admin/projects/:id/content-images, stored ascontent-<random>.<ext>next to the project's image and served publicly by the same route, so a page shows them before the project is public too (the names are random). They are deleted with the project; an image taken out of the page stays stored until then. - Deleting a project deletes its leads, members and team links; deleting a team deletes its project links. The other side stays.
Seed teams and projects
seed.teams lists teams to create on the first request when no team has their slug: slug, name, and optionally
kind (default default, it needs a ladder in the option), ownerType (default platform) and ownerId,
description, public, contactEmail, formRef, startsAt and endsAt (ISO). seed.projects takes the same
fields without kind, for projects. An existing slug is skipped and never updated, so staff edits are safe. It only
runs with seed.enabled, which you can turn on at runtime with NUXT_TEAMS_SEED_ENABLED=true. The module ships none.
export default defineNuxtConfig({
teams: {
seed: {
teams: [{ slug: 'welcome-crew', name: { en: 'Welcome crew', da: 'Velkomstcrew' }, public: true }],
projects: [{ slug: 'summer-build', name: { en: 'Summer build', da: 'Sommeropbygning' }, public: true }],
},
},
})
Dashboard item
With Dashboard installed, Teams adds teams.mine to crew.home and the
hub's dashboard (permission teams:read, order 60, two columns wide): the teams the person is on with their role (the ladder's label, translated), from
GET /api/teams/me; a role a mapping rule gives
them is marked "By role". On a team with a public page, an explicit member gets the switch Show me on the public
page under it, and the team's name links to the page. Texts are under teams.dashboard.
App
Pages
| Page | Path | For |
|---|---|---|
| Public list | /teams, one per section | Everybody. Cards with the image, name, kind and description of each public team of the section. Off with settings.pages.public: false. |
| Public team page | /teams/:slug, ... | Everybody. A team asked for under another section moves (301) to its own. Image, description, dates, the members who chose to be shown, the public projects it works on, Apply (a published form) and Contact (the contact address). |
| Public project list | /projects | Everybody. Cards with the image, name, dates and description of each public project. Off with settings.pages.public: false. |
| Public project page | /projects/:slug | Everybody. Image, description, dates, the page body, the public teams on it, the leads and members who chose to be shown, Apply and Contact. |
| Team list | /admin/teams | Staff with teams:manage. Search, an owner filter (?ownerType=&ownerId=), a kind filter (?kind=) and sortable columns. |
| Team page | /admin/teams/:id | Staff with teams:manage. Key facts, members, mapping rules, the projects it works on (read-only), and the kind's ladder. |
| Project list | /admin/projects | Staff with teams:manage. Search, an owner filter, a status filter (?status=upcoming|active|ended) and sortable columns. Sidebar entry Projects. |
| Project page | /admin/projects/:id | Staff with teams:manage. Key facts, the page body (Page), the teams on the project (add, edit note, take off) and its leads and members. |
The team slideover has the public page fields: the URL name (suggested from the name until you edit it), the public
switch, the image (with imageUpload), the contact address, the dates and the form. The member table has a Public
page column: shown or hidden, and who set it. The row menu offers Edit member (the role, and whether they are shown)
and Remove member. For a mapped member it offers Assign role, which
adds them explicitly. Add member opens a slideover with the UserPicker of Users
on GET /api/admin/teams/users: it searches people by name, and by email with teams:pii. Staff who hold
users:create can create the person from the picker, and the new user is selected. Rules and the ladder are edited in
slideovers too.
Tab on the operation page
Teams adds a Teams tab to the admin.operations tab area of Widget, with the prop
ownerType: 'operation'. It reads the operation's id from the tab context and never imports Operations. It lists
the operation's teams and adds new ones for it. Rendered without an operation, it shows an empty state and queries
nothing. Turn it off with settings.operationsTab: false.
Owner picker
OwnerSelect is a global component for forms that store an owner (ownerType / ownerId), in Teams and in other
modules. It searches owners of type by name as you type, through GET /api/admin/teams/owners (staff with
teams:manage), and binds the owner's id. An edit form shows the current owner's name. When nobody answers
teams:owner:search for the type, or the route refuses or fails, it falls back to a text input for the id.
<OwnerSelect v-model="state.ownerId" :type="state.ownerType" />
| Prop | Type | What it does |
|---|---|---|
v-model | string | null | The owner's id. |
type | string | The owner type (team, operation, or your own). Searched again when it changes. |
disabled | boolean | Disables the select. |
placeholder | string | Replaces the placeholder. |
Composables
| Composable | What it does |
|---|---|
useTeamActions() | create, edit, remove and menu(team), with toasts and confirmations. |
useTeamMemberActions(team, ladders) | add, changeRole, remove and menu(member). |
useTeamMappingActions(context) | create, edit, remove and menu(rule). |
useProjectActions() | create, edit, remove and menu(project), with toasts and confirmations. |
useProjectMemberActions(project) | add, edit (the role and the public visibility), remove and menu(member) for its leads and members. |
useProjectTeamActions(project, exclude?) | add (a team and a note), edit (the note), remove and menu(link) for the teams on project. |
useTeamLinks() | Locale-aware links to the admin pages (adminTeam(id), adminProjects(), adminProject(id)) and the public pages (publicList(section?), publicTeam(section, slug), publicProjects(), publicProject(slug)). |
useTeamSection() | On a public page: its section and the labels (label, item and lower-case forms). |
useTeamsTranslate() | tr(value) for Translated texts, and tr.kindLabel(ladders, kind), tr.kindDescription(ladders, kind) and tr.kindItems(ladders) for kind labels and selects. |
Hooks
Your app answers these Nitro hooks from a server plugin (server/plugins/*.ts).
| Hook | When | Payload |
|---|---|---|
teams:member:added | When an explicit membership starts granting: added with status null or active, or its status became one of those. | { event, team, member } |
teams:member:removed | When an explicit membership stops granting: removed while it granted, or its status left null / active. | { event, team, member } |
teams:member:role-changed | When the role of a membership that grants changed. | { event, team, member, from, to } |
teams:roles:resolve | While resolving a user's mapped grants. Push grants into grants. | { event, user, owner, globalRoles, rules, teams, ladders, grants } |
teams:members:candidates | While listing mapped members. Add user ids to userIds. | { event, team, rules, userIds } |
teams:owner:resolve | While an owner is checked or labelled. Set label and exists for your own owner types. | { event, owner, label, exists } |
teams:owner:search | While owners are found by name (the owner picker). Set searchable and push at most limit results for your own owner types. | { event, type, q, limit, results, searchable } |
teamis the staff DTO andmemberthe member DTO with the email, whatever the caller may see.teams:roles:resolve.ownerisnull: one resolution covers every owner.eventisundefinedwhile the OAuth claim is built.rulesare the rules in play,teamsthe teams they cover. Give a pushed grant thepriorityof the rule it stands for;mappedGrantsFor(teams, rules, ladders)from@frigear-nu/teams/utilsbuilds them. While mapped members are listed, the hook runs once per candidate withteamsholding that one team, itsowner, and only the rules Teams cannot answer in bulk (notrolerules, norplanrules when Subscriptions is installed). Keep such a listener free of per-call queries: load what it needs in bulk inteams:members:candidates.- The member hooks follow the grant, not the row. A pending row fires nothing when it is added, deleted or given
another role;
addedfires when its status becomesactive(with the role it has then), andremovedwhen an active membership becomesinactive. Crew fires its own hooks on the same transitions, so both agree on when a person starts and stops working on a team. Mapped grants fire no hooks. - Deleting a team fires no
teams:member:removedfor the memberships that go with it.
Routes
Typed path builders are exported as teamsApi from @frigear-nu/teams/api.
| Route | Who | What it does |
|---|---|---|
GET /api/teams/me | teams:read | Your grants on every owner, explicit first, each with source, the team's name and the role's ladder label roleLabel. |
PUT /api/teams/me/:teamId/visibility | teams:read + policy | { showPublicly }: show or hide yourself on the team's public page, or a project's (a prj_ id). Explicit members only (404 otherwise). Recorded as set by you. |
GET /api/teams/public | Anyone | The public teams (public, with a slug), each with its section. ?section=festivals keeps one section. |
GET /api/teams/public/:slug | Anyone | One public team with its contact address, published form, shown members, and the public projects it works on. 404 for anything not public. |
GET /api/projects/public | Anyone | The public projects (public, with a slug). |
GET /api/projects/public/:slug | Anyone | One public project with its contact address, published form, shown leads and members (role) and public teams (with section, kindLabel and note). 404 for anything not public. |
GET /api/projects/images/:projectId/:file | Anyone | An uploaded project image or page body image. Only with imageUpload. |
GET /api/teams/images/:teamId/:file | Anyone | An uploaded image. Only with imageUpload. |
GET /api/teams/:id | teams:read + policy | One team. |
GET /api/teams/:id/members | teams:read + policy | Names and avatars; email only with teams:pii. Staff and leads see every row with its status; other members only the rows that grant. ?include=mapped (staff and leads) adds mapped members. |
GET /api/admin/teams | teams:manage | Paginated list with ownerType, ownerId, kind, q (name in every language) and sort. |
POST /api/admin/teams | teams:manage | Create a team: ownerType, ownerId, kind, name, description, parentId, capacity, sort, slug, public, contactEmail, formRef, startsAt, endsAt. 409 conflict for a slug in use; 400 for a malformed or reserved slug (me, public, images, ...). |
GET /api/admin/teams/:id | teams:manage | One team, with ownerLabel and memberCount. |
PATCH /api/admin/teams/:id | teams:manage | Edit any field but the owner and the kind. |
PUT /api/admin/teams/:id/image | teams:manage | Upload the image (multipart file). Only with imageUpload. |
DELETE /api/admin/teams/:id/image | teams:manage | Remove the image. Only with imageUpload. |
DELETE /api/admin/teams/:id | teams:manage | Delete a team; its members, its own rules and its project links go with it (foreign key cascades). |
POST /api/admin/teams/:id/members | teams:manage | Add { userId, role, status? }. 400 for a role off the ladder, 409 for a member already. |
PATCH /api/admin/teams/:id/members/:userId | teams:manage | Change role, status and showPublicly (recorded as set by you). |
DELETE /api/admin/teams/:id/members/:userId | teams:manage | Remove an explicit member. |
GET /api/admin/teams/:id/projects | teams:manage | The projects the team works on, public or not (read-only; links are managed on the project). |
GET /api/admin/projects | teams:manage | Paginated list with ownerType, ownerId, status (upcoming, active, ended), q and sort (sort, createdAt, startsAt). Each with ownerLabel, memberCount and teamCount. |
POST /api/admin/projects | teams:manage | Create a project: ownerType, ownerId, name, description, content, sort, slug, public, contactEmail, formRef, startsAt, endsAt. 409 conflict for a slug in use. |
GET /api/admin/projects/:id | teams:manage | One project. |
PATCH /api/admin/projects/:id | teams:manage | Edit any field but the owner. |
DELETE /api/admin/projects/:id | teams:manage | Delete a project with its leads, members and team links. |
PUT /api/admin/projects/:id/image | teams:manage | Upload the image (multipart file). Only with imageUpload. |
DELETE /api/admin/projects/:id/image | teams:manage | Remove the image. Only with imageUpload. |
POST /api/admin/projects/:id/content-images | teams:manage | Upload an image for the page body (multipart file); 201 with { file, url }. 415 for anything but a PNG, JPEG or WebP, 413 above maxImageBytes. Only with imageUpload. |
GET /api/admin/projects/:id/members | teams:manage | Leads first, then members; email only with teams:pii. |
POST /api/admin/projects/:id/members | teams:manage | Add { userId, role: 'lead' | 'member' }. 400 for an unknown user, 409 when on the project already. |
PATCH /api/admin/projects/:id/members/:memberId | teams:manage | Change role and showPublicly (recorded as set by you). |
DELETE /api/admin/projects/:id/members/:memberId | teams:manage | Remove a lead or member. |
GET /api/admin/projects/:id/teams | teams:manage | The teams on the project, public or not. Each link has note, sort, project and team (id, name, kind, slug, public, section). |
POST /api/admin/projects/:id/teams | teams:manage | Link { teamId, note?, sort? }. 400 for an unknown team, 409 conflict when linked already. |
PATCH /api/admin/projects/:id/teams/:linkId | teams:manage | Change note and sort. 404 for a link of another project. |
DELETE /api/admin/projects/:id/teams/:linkId | teams:manage | Take the team off the project; both stay. |
GET /api/admin/teams/mappings | teams:manage | Rules, by ownerType and ownerId, or those covering teamId. |
POST /api/admin/teams/mappings | teams:manage | Add a rule. |
PATCH /api/admin/teams/mappings/:id | teams:manage | Edit teamId, match, teamRole, priority. |
DELETE /api/admin/teams/mappings/:id | teams:manage | Delete a rule. |
GET /api/admin/teams/ladders | teams:manage | Every ladder, with source: 'stored' | 'default'. |
GET /api/admin/teams/ladders/:kind | teams:manage | One ladder. |
PUT /api/admin/teams/ladders/:kind | teams:manage | Replace { roles, leadFrom }. 409 team_role_in_use. |
GET /api/admin/teams/users | teams:manage | ?q= finds people to add by name; with teams:pii also by email, and the answer has the emails. |
GET /api/admin/teams/owners | teams:manage | ?type=&q= finds owners of a type by name (at most 20; no q lists the first ones); ?type=&id= labels one owner. { items: { id, label }[], searchable }, searchable: false when nobody answers teams:owner:search for the type. |
Adding and removing members is staff only. Leads hold teams:lead, which other modules check, but they do not manage
their team's members.
status on a membership is set by the module that uses it, such as crew; see Membership status.
Database
Tables the module adds. Generate and commit a migration after installing.
| Table | Holds |
|---|---|
teams | tem_ id, ownerType, ownerId (null for the platform), parentId, kind, Translated name and description, searchText (the name folded for search), capacity, sort, and for the public page a unique slug, public, image (the uploaded file's name), contactEmail, formRef, startsAt, endsAt. |
team_members | tmm_ id, teamId (cascade), userId, role, status, addedBy, and showPublicly, showPubliclySetBy, showPubliclySetAt. One row per team and user. Crew adds columns and their indexes through its extension file. |
team_role_ladders | kind, ordered roles ([{ key, label }]) and leadFrom. |
team_role_mappings | trm_ id, owner, teamId (cascade, null for every team), match, teamRole, priority. |
projects | prj_ id, owner, Translated name, description and content (the page body), searchText, a unique slug, public, image, contactEmail, formRef, startsAt, endsAt, sort. |
project_members | prm_ id, projectId (cascade), userId, role (lead or member), addedBy, and showPublicly, showPubliclySetBy, showPubliclySetAt. One row per project and user. |
project_teams | ptm_ id, projectId (cascade), teamId (cascade), Translated note, sort. One row per pair. |
User ids have no foreign key: the users table belongs to Users. Whoever deletes a user removes their memberships.
Translations
Override any string in your app's i18n/locales/<code>.json. The module registers da and en files under
teams.*. See overriding module strings.
Key groups: menu.*, permissions.*, scopes.*, public.* (the public pages), dashboard.* and admin.* (with admin.tabs.*, admin.ownerTypes.* and
admin.sources.*). Ladder role labels are data: edit them on the ladder.
Next steps
- Crew – applications and invites that put people on teams.
- Record audiences – the grant lists the
teamkind belongs to.