12 KiB
VitFit V2 — Roles & Permissions
Role Hierarchy
SystemAdmin ← Platform operator (you). Cross-org visibility. Not a gym user.
│
Organization
├── Owner ← Gym owner/manager. Manages coaches and clients. Sees everything in their org.
├── Coach ← Trainer. Manages workouts and their own clients. Cannot manage other coaches.
└── Client ← Athlete/member. Views own workouts and schedule only.
Roles are scoped to an organization. A user belongs to exactly one organization. SystemAdmin is the only cross-organization role.
Role Definitions
SystemAdmin
- Platform-level administrator (the person who sells and deploys VitFit)
- There is exactly one SystemAdmin per deployment (could be multiple accounts, all flagged as SystemAdmin)
- Can access any organization's data for support purposes
- Manages the Organization record itself (creates, suspends, configures feature flags)
- Does NOT manage day-to-day gym operations — that is the Owner's job
- Has a dedicated
/sysadminpanel separate from the normal app UI - Actions are always audit-logged
Owner
- The gym owner or head administrator who purchased the license
- Can do everything a Coach can do, plus:
- Manage all user accounts in their organization (create, deactivate, change roles)
- View all coaches' clients and workouts
- Configure organization branding
- View audit logs for their organization
- Set up billing/license info (if applicable)
- Grant Coach accounts
- Manage the client roster
- Cannot elevate their own account to SystemAdmin
Coach
- A trainer or staff member
- Can manage workouts, timers, CrossFit workouts, the video library
- Can be assigned clients (by Owner or by self-assignment if the org allows it)
- Can view and manage their own clients' profiles and programming
- Cannot see other coaches' clients (unless they are also an Owner)
- Cannot manage other user accounts
- Cannot view audit logs
- Cannot change organization branding
Client
- An athlete or gym member
- Read-only access to their own data
- Can view workouts assigned to them by their coach
- Can view their own calendar / upcoming sessions
- Cannot upload videos, create workouts, or manage any content
- Cannot see other clients' data
- Cannot see coach-only content (full video library, timer configs, etc.)
- Can update their own profile (name, password, preferences)
- Does NOT have access to the group display features (TV display, timers) — those are coach-facing
Permission Matrix
Legend: ✅ Full access | 🔶 Own/assigned only | ❌ No access | 👑 SystemAdmin only
Organization Management
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create organization | 👑 | ❌ | ❌ | ❌ |
| Edit organization name/settings | 👑 | ✅ | ❌ | ❌ |
| View organization details | 👑 | ✅ | 🔶 (name/logo only) | 🔶 (name/logo only) |
| Enable/disable feature flags | 👑 | ❌ | ❌ | ❌ |
| Suspend/deactivate organization | 👑 | ❌ | ❌ | ❌ |
User Management
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create Coach account | 👑 | ✅ | ❌ | ❌ |
| Create Client account | 👑 | ✅ | ✅ (if org allows) | ❌ |
| View all users in org | 👑 | ✅ | ❌ | ❌ |
| View own profile | ✅ | ✅ | ✅ | ✅ |
| Edit own profile / password | ✅ | ✅ | ✅ | ✅ |
| Change any user's role | 👑 | ✅ | ❌ | ❌ |
| Reset any user's password | 👑 | ✅ | ❌ | ❌ |
| Deactivate a user | 👑 | ✅ | ❌ | ❌ |
| Assign coach to client | 👑 | ✅ | 🔶 (self-assign if allowed) | ❌ |
| View assigned clients | — | ✅ (all) | 🔶 (own clients) | ❌ |
| Revoke device tokens | 👑 | ✅ | 🔶 (own devices) | 🔶 (own devices) |
Branding
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| View branding settings | 👑 | ✅ | ❌ | ❌ |
| Edit logo, colors, name | 👑 | ✅ | ❌ | ❌ |
Video Library
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Upload video | 👑 | ✅ | ✅ | ❌ |
| View all videos | 👑 | ✅ | ✅ | ❌ |
| View videos assigned to them | — | — | — | ✅ (via workouts) |
| Delete video | 👑 | ✅ | ✅ | ❌ |
| Manage categories | 👑 | ✅ | ✅ | ❌ |
Workouts (Group / TV Display)
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create group workout | 👑 | ✅ | ✅ | ❌ |
| Edit group workout | 👑 | ✅ | ✅ | ❌ |
| Delete group workout | 👑 | ✅ | ✅ | ❌ |
| Launch workout to TV display | 👑 | ✅ | ✅ | ❌ |
| View group workouts | 👑 | ✅ | ✅ | ❌ |
Client Workouts (1-on-1)
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create workout for a client | 👑 | ✅ | 🔶 (own clients) | ❌ |
| Edit client workout | 👑 | ✅ | 🔶 (own clients) | ❌ |
| Delete client workout | 👑 | ✅ | 🔶 (own clients) | ❌ |
| View own assigned workouts | — | — | — | ✅ |
| View all client workouts in org | 👑 | ✅ | ❌ | ❌ |
Timers
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create / edit / delete timer | 👑 | ✅ | ✅ | ❌ |
| Launch timer to TV display | 👑 | ✅ | ✅ | ❌ |
| View timer list | 👑 | ✅ | ✅ | ❌ |
CrossFit Workouts
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create CrossFit workout | 👑 | ✅ | ✅ | ❌ |
| Delete CrossFit workout | 👑 | ✅ | ❌ | ❌ |
| View CrossFit workouts | 👑 | ✅ | ✅ | ❌ |
Calendar / Scheduling
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| Create session/appointment | 👑 | ✅ | 🔶 (own calendar) | ❌ |
| Edit session | 👑 | ✅ | 🔶 (own sessions) | ❌ |
| Cancel session | 👑 | ✅ | 🔶 (own sessions) | 🔶 (request cancellation) |
| View own calendar | — | ✅ | ✅ | ✅ |
| View all coaches' calendars | 👑 | ✅ | ❌ | ❌ |
| View assigned coach's calendar | — | — | — | 🔶 (coach's availability only) |
Audit Logs
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| View org audit log | 👑 | ✅ | ❌ | ❌ |
| View cross-org audit log | 👑 | ❌ | ❌ | ❌ |
| Export audit log | 👑 | ✅ | ❌ | ❌ |
Storage
| Action | SystemAdmin | Owner | Coach | Client |
|---|---|---|---|---|
| View storage usage | 👑 | ✅ | ❌ | ❌ |
UI Navigation by Role
SystemAdmin UI
/sysadmin— separate section- Organizations list + detail
- Cross-org user lookup
- Feature flag management
- Full audit log (all orgs)
- Server health / storage
Owner UI
Full app + additional Owner tabs in settings:
- User management (create coaches + clients, manage roles)
- Branding settings
- Audit log (own org)
- Client roster
- All coaches' calendars (read)
- Storage monitoring
Coach UI
Standard app (matches V1 functionality):
- Group workouts, timers, CrossFit, video library
- My Clients section: list of assigned clients, their programming, their calendar
- Own calendar management
Client UI
Minimal, client-only:
- My Workouts — workouts assigned by coach
- My Schedule — upcoming sessions
- My Profile — update name/password
- No nav items for group workouts, video library, or admin functions
Role Enforcement
Backend
Every route that touches org-specific data must:
- Verify JWT (authenticateToken)
- Verify role is sufficient (authenticateRole(['Owner', 'Coach']))
- Verify the resource being accessed belongs to
req.user.organizationId
Rule 3 is the critical one — it prevents a Coach at Gym A from accessing Gym B's data even if they somehow get a valid token.
Pattern:
// Every data-access query includes the org filter
const workout = await Workout.findOne({
where: {
id: req.params.id,
organizationId: req.user.organizationId // ALWAYS required
}
});
if (!workout) return res.sendStatus(404); // 404 not 403 — don't reveal existence
Frontend
Frontend hides UI elements based on role (stored in the decoded JWT payload). But hiding is cosmetic — all real enforcement is server-side. Frontend role checks are only for UX, never for security.
Permission Edge Cases
These specific scenarios must be explicitly handled in code — they are not covered by the general permission matrix.
Last Owner Protection
An organization must always have at least one active Owner.
- Attempting to deactivate the last Owner: Blocked. Returns
LAST_OWNER_PROTECTEDerror. - Attempting to demote the last Owner to Coach or Client: Blocked. Returns
LAST_OWNER_PROTECTEDerror. - This check applies regardless of who is making the request — even SystemAdmin cannot remove the last Owner without first creating a replacement.
- Implementation: before any role change or deactivation of an Owner, count active Owners in the org. If count is 1 and the target is that Owner, reject.
Owners Cannot Change Their Own Role
An Owner cannot demote themselves. They must have another Owner or SystemAdmin do it. This prevents accidental self-lockout.
Coaches and Cross-Coach Content
Coaches can edit and delete content they created (workouts, timers, CrossFit workouts). For content created by another Coach in the same org:
- Edit: Not allowed. Returns 403.
- Delete: Not allowed. Returns 403.
- Exception: Owners can edit and delete any content in their org regardless of who created it.
- The
createdByUserIdcolumn on content tables enables this check.
Coaches can view all group workouts/timers/CrossFit workouts in their org — visibility is org-wide, but modification rights are creator-only (or Owner).
Coach Self-Assignment of Clients
Whether a Coach can self-assign a client (without Owner action) is an org-level setting:
Organizations.settings (JSON):
{ "allowCoachSelfAssign": true } // default: false
When false, only Owners (and SystemAdmins) can create CoachClientLinks. When true, a Coach can assign themselves to an unassigned Client.
A Coach can never assign a client to another Coach — that is always an Owner action.
Client Reassignment
When a Client moves from one Coach to another:
- The old CoachClientLink is deactivated (
isActive = false) — not deleted - A new CoachClientLink is created
- Historical ClientWorkouts retain their original
coachId— they are not re-attributed - The Client can still view their full historical workout list regardless of coach changes
- The new Coach can only see ClientWorkouts they created, plus all CalendarSessions going forward — not the previous Coach's private notes
This is logged as coach.client.unassign + coach.client.assign in the audit log.
Deactivated Users
- Deactivated users cannot log in (401 on auth attempt)
- Their audit log entries, created workouts, and client history are preserved
- If a deactivated Coach had active clients, those clients become "unassigned" — they still exist and can be reassigned by an Owner
- Deactivated users do not appear in user lists for regular roles (Owner sees them with a "Deactivated" filter)
Mapping V1 Roles → V2 Roles
| V1 Role | V2 Role | Notes |
|---|---|---|
| Admin | Owner | The person managing the gym instance |
| Coach | Coach | Staff/trainer |
| (none) | Client | New in V2 |
| (none) | SystemAdmin | New — platform operator only |
The existing V1 "Admin" user maps to "Owner" in V2. No data is lost. The migration script sets their role to Owner and assigns them to the seeded Organization.