mirror of
https://github.com/rommapp/romm.git
synced 2026-12-06 15:54:45 +01:00
Centralised permission checks for v2 — closes the constitution's
"never inline-check user.role in features" rule. Three pieces:
- src/stores/permissions.ts: Pinia store holding the user's
effective grants. Today populated by hydrateFromRole() against a
role-map; tomorrow populated by setGrants() from /permissions/me.
Lives in the canonical store directory but is v2-only consumed —
v1 keeps its inline checks until removal.
- src/v2/composables/useCan: ActionKey vocabulary, scope vocabulary
({global,platform,collection,rom}), role-map mirroring backend
guards, and useCan(action, scope?) returning ComputedRef<boolean>.
installPermissionsHydration() watches authStore.user and keeps
the store in sync; AppLayout calls it on mount.
- Migrations: UserMenu.vue's isAdmin computed and SettingsNav's
Server Stats visibility gate now go through useCan("app.admin").
No more `user.role === "admin"` inline checks in v2.
Backend debt remains: ActionKey enum in OpenAPI + /permissions/me
endpoint + permissions:changed socket event. Until those land, the
role-map.ts file must be reviewed against backend role guards by
hand. Drift means the UI will offer actions the server rejects, or
hide actions it would have permitted.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>