mirror of
https://github.com/mauriceboe/TREK.git
synced 2026-11-27 15:17:30 +00:00
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:
@@ -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>();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user