diff --git a/backend/src/permissions/permissions.guard.ts b/backend/src/permissions/permissions.guard.ts index ff821f62e..ddc969f53 100644 --- a/backend/src/permissions/permissions.guard.ts +++ b/backend/src/permissions/permissions.guard.ts @@ -11,6 +11,7 @@ import { CompleteRequest } from '../api/utils/request.type'; import { ConsoleLoggerService } from '../logger/console-logger.service'; import { NotesService } from '../notes/notes.service'; import { PermissionsService } from './permissions.service'; +import { PERMISSION_METADATA_KEY } from './require-permission.decorator'; import { RequiredPermission } from './required-permission.enum'; /** @@ -32,7 +33,7 @@ export class PermissionsGuard implements CanActivate { async canActivate(context: ExecutionContext): Promise { const permissions = this.reflector.get( - 'permissions', + PERMISSION_METADATA_KEY, context.getHandler(), ); // If no permissions are set this is probably an error and this guard should not let the request pass diff --git a/backend/src/permissions/require-permission.decorator.ts b/backend/src/permissions/require-permission.decorator.ts index 1e5bd0444..3971b92ce 100644 --- a/backend/src/permissions/require-permission.decorator.ts +++ b/backend/src/permissions/require-permission.decorator.ts @@ -7,12 +7,13 @@ import { CustomDecorator, SetMetadata } from '@nestjs/common'; import { RequiredPermission } from './required-permission.enum'; +export const PERMISSION_METADATA_KEY = 'requiredPermission'; + /** - * This decorator gathers the {@link Permission Permission} a user must hold for the {@link PermissionsGuard} - * @param permissions - an array of permissions. In practice this should always contain exactly one {@link Permission} - * @constructor + * This decorator gathers the {@link RequiredPermission Permission} a user must hold for the {@link PermissionsGuard} + * @param permissions - an array of permissions. In practice this should always contain exactly one {@link RequiredPermission} */ // eslint-disable-next-line func-style,@typescript-eslint/naming-convention export const RequirePermission = ( ...permissions: RequiredPermission[] -): CustomDecorator => SetMetadata('permissions', permissions); +): CustomDecorator => SetMetadata(PERMISSION_METADATA_KEY, permissions);