refactor(permissions): the permission catalog and its decision rule live in shared

PERMISSION_ACTIONS, PermissionLevel, PermissionKey and evaluatePermission()
move to shared/src/permissions. PermissionsService decides through
evaluatePermission and re-exports the catalog for its importers, and
@RequirePermission takes a PermissionKey, so a misspelt action fails to
compile. Levels, defaults and every verdict stay as they were.
This commit is contained in:
Maurice
2026-10-10 14:47:56 +02:00
parent 8d716aec2f
commit 5e797463fa
7 changed files with 193 additions and 73 deletions
@@ -7,7 +7,8 @@
* no business knowing), and a mutation additionally needs its own permission. They
* moved out of days.controller.test.ts with the check itself.
*/
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, expectTypeOf, vi } from 'vitest';
import type { PermissionKey } from '@trek/shared';
import { HttpException } from '@nestjs/common';
import { ROUTE_ARGS_METADATA } from '@nestjs/common/constants';
import { Reflector } from '@nestjs/core';
@@ -189,3 +190,11 @@ describe('@Trip() param decorator', () => {
expect(() => tripFactory()(undefined, ctx({}))).toThrow(/without @UseGuards\(TripAccessGuard\)/);
});
});
describe('RequirePermission', () => {
it('takes a key of the shared permission catalog, so a misspelt action does not compile', () => {
expectTypeOf(RequirePermission).parameter(0).toEqualTypeOf<PermissionKey>();
expectTypeOf<'day_edit'>().toMatchTypeOf<PermissionKey>();
expectTypeOf<'day_edits'>().not.toMatchTypeOf<PermissionKey>();
});
});