Modules
Team and roles
Members, seats, invitations and roles with a permission matrix and role editing.
pages/account/roles.vue
View in the demo
/account/roles has two tabs synced with ?tab=: members and roles. Roles come from useRoles() and checks from useCan(); the permission model is explained in Roles and permissions.
Files
File | Role |
|---|---|
pages/account/roles.vue | The page with both tabs. |
composables/useRoles.ts | Roles, system role names and role CRUD. |
mocks/roles.mock.ts | Roles and team members. |
config/team.config.ts | Views, inactivity and invitation windows, role icons, colours and templates. |
utils/team.ts | Member state, seats and permission toggles, unit tested. |
components/pages/account/ | AccountSeatsCard, AccountMemberRoleMenu, AccountRolesPanel, AccountPermissionMatrix, AccountMembersTable, AccountRoleFormPanel, AccountInvitePanel. |
Permissions
The page needs roles.view.
Configuration
TEAM_VIEWS
Member views: all, active, invited and inactive.
const TEAM_VIEWS: TeamView[]
TEAM_INACTIVE_DAYS
Days without signing in before a member is inactive.
const TEAM_INACTIVE_DAYS: 30
TEAM_INVITE_DAYS
Days before an invitation expires.
const TEAM_INVITE_DAYS: 7
ROLE_TEMPLATES
Templates a new role starts from.
const ROLE_TEMPLATES: readonly ["blank", "viewer", "editor", "admin"]
ROLE_ICONS
Icons a role can take.
const ROLE_ICONS: string[]
ROLE_COLORS
Colours a role can take.
const ROLE_COLORS: string[]
Rules
Pure functions in utils/, unit tested in tests/unit/. Statuses and segments are derived from the stored data, never stored themselves.
memberState()
Member state.
memberState(member: Pick<TeamMember, 'status' | 'lastActiveAt'>, now: Date): TeamMemberState
seatUsage()
Seat usage.
seatUsage(members: Pick<TeamMember, 'status'>[], seats: number): { active: number; invited: number; used: number; free: number; }Returns
activeinvitedusedfreetogglePermission()
Toggle a permission; View is implied.
togglePermission(permissions: Permission[], module: PermissionModule, action: PermissionAction): ("dashboard.view" | "dashboard.create" | "dashboard.update" | "dashboard.delete" | "orders.view" | "orders.create" | "orders.update" | "orders.delete" | "customers.view" | ... 22 …permissionSummary()
A readable summary.
permissionSummary(permissions: Permission[]): Record<"view" | "create" | "update" | "delete", number>
How it works
- Members show seat usage (
AccountSeatsCard, aBaseSegmentBarover the plan seats plus members without 2FA), views, an inline role menu (AccountMemberRoleMenu) and invitations with inviter and expiry. - Roles (
AccountRolesPanel) lists roles and shows the selected one’s read-onlyAccountPermissionMatrix. System roles cannot be edited, only duplicated; “View as this role” switches the demo role. - Editing is a
BaseForminsideBaseFormPanel: start from a template, pick icon and colour withBaseSwatchPicker, and set the grid with select-all per column and row. Any action of a module implies View. The footer’s#actions-startshows thepermissionSummary.