mirror of
https://github.com/duckietm/Nitro-V3.git
synced 2026-06-19 23:16:21 +00:00
feat(hooks): permission-driven gating via useHasPermission
Replace the rank-level family (useHasRankLevel + STAFF_LEVELS constants + useIsRank) with a permission-driven family that reads straight from the deployment's `permission_definitions` table — no more hardcoded SecurityLevel/rank-id thresholds on the client. A new rank in permission_ranks or a re-shuffling of permission_definitions rank columns now propagates through the UI automatically. Renderer-side wire shipped in companion commit feat/react19-event-bus@159c5eb (UserPermissionsMapParser + Event, SessionDataManager.getPermissionsSnapshot + USER_PERMISSIONS_UPDATED). New public API in `useSessionSnapshots.ts`: - useUserPermissions(): ReadonlyMap<string, number> — full map - useHasPermission(key): boolean — > 0 ⇒ true - usePermissionValue(key): number — raw 1/2 or 0 - useIsAmbassador() now aliases useHasPermission('acc_ambassador') - useUserRank() kept for PRESENTATIONAL use only (badge, prefix, prefix color) — documented as such in JSDoc; gating must use useHasPermission. Dropped: - src/api/nitro/session/RankLevels.ts (STAFF_LEVELS constants) - useHasRankLevel / useIsRank exports (rank-based gating) 11 consumer migrations, each mapped to the right `permission_definitions.permission_key`: - ToolbarView (mod-only chat-input button) → acc_supporttool - ChooserWidgetView (room-object id column) → acc_supporttool - CatalogClassicView (admin toggles) → acc_catalogfurni - CatalogModernView (admin toggles) → acc_catalogfurni - FurniEditorView (panel access) → acc_catalogfurni - CalendarView (force-open day) → acc_calendar_force - InfoStandWidgetFurniView (mod buildtools btn) → acc_anyroomowner - AvatarInfoWidgetPetView (canPickUp) → acc_anyroomowner - FurnitureMannequinView (controller mode) → acc_anyroomowner - YouTubePlayerView (isMyRoom) → acc_anyroomowner - NavigatorRoomInfoView 'settings' → acc_anyroomowner - NavigatorRoomInfoView 'staff_pick' → acc_staff_pick Test refresh: - useUserRank still tested for the presentational shape. - useHasPermission: true for non-zero, false for absent/zero. - usePermissionValue: raw 1 / 2 / 0 (default). - useUserPermissions: full map exposure. - Runtime promote test: mutate the permissions map + dispatch USER_PERMISSIONS_UPDATED, assert useHasPermission flips false→true. Locks in the new reactive contract. Mock unchanged (the test sets getPermissionsSnapshot via vi.mocked). Verification: yarn typecheck clean, yarn lint:hooks clean, yarn test 214/214 (213 prior + 1 net new for useUserPermissions). Backward compatible: older Arcturus deployments don't ship the map → empty snapshot → every gate is false → mod UI hidden (safe default).
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
/**
|
||||
* Deployment-specific rank-level constants.
|
||||
*
|
||||
* Mirrors the `level` column of `permission_ranks` for the operator's
|
||||
* Arcturus instance. Defined in ONE place so widget code can express
|
||||
* intent via `useHasRankLevel(STAFF_LEVELS.MOD)` instead of bare
|
||||
* integers, and so a deployment that re-numbers its ranks (e.g. adds
|
||||
* a "Super Admin" at level 8) only has to update this file.
|
||||
*
|
||||
* Default seed (Arcturus-Morningstar-Extended ≥ 4.2.10):
|
||||
* 1 Member | 2 VIP | 3 X
|
||||
* 4 Support | 5 Moderator | 6 Super Mod
|
||||
* 7 Administrator
|
||||
*
|
||||
* Update the constants here to match `permission_ranks.level` in your
|
||||
* deployment if you customised them.
|
||||
*/
|
||||
export const STAFF_LEVELS = {
|
||||
/** Member level — the floor for non-staff users. */
|
||||
MEMBER: 1,
|
||||
/** Lowest staff tier — Support agents. */
|
||||
SUPPORT: 4,
|
||||
/** Moderator (covers in-room moderation actions). */
|
||||
MOD: 5,
|
||||
/** Super Mod (extended moderation surface). */
|
||||
SUPER_MOD: 6,
|
||||
/** Administrator — full staff privileges. */
|
||||
ADMIN: 7
|
||||
} as const;
|
||||
@@ -16,6 +16,5 @@ export * from './HasHabboVip';
|
||||
export * from './IsOwnerOfFloorFurniture';
|
||||
export * from './IsOwnerOfFurniture';
|
||||
export * from './IsRidingHorse';
|
||||
export * from './RankLevels';
|
||||
export * from './StartRoomSession';
|
||||
export * from './VisitDesktop';
|
||||
|
||||
Reference in New Issue
Block a user