mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-25 11:16:31 -05:00
feat: create permission decorator
This gathers the permission a user needs to hold to access a resource for the PermissionsGuard. See https://docs.nestjs.com/guards#setting-roles-per-handler Signed-off-by: Philip Molares <philip.molares@udo.edu>
This commit is contained in:
parent
4a7ccc8178
commit
7404ebf5ea
1 changed files with 17 additions and 0 deletions
17
src/permissions/permissions.decorator.ts
Normal file
17
src/permissions/permissions.decorator.ts
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
/*
|
||||||
|
* SPDX-FileCopyrightText: 2021 The HedgeDoc developers (see AUTHORS file)
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
*/
|
||||||
|
import { CustomDecorator, SetMetadata } from '@nestjs/common';
|
||||||
|
|
||||||
|
import { Permission } from './permissions.enum';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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
|
||||||
|
*/
|
||||||
|
// eslint-disable-next-line func-style,@typescript-eslint/naming-convention
|
||||||
|
export const Permissions = (...permissions: Permission[]): CustomDecorator =>
|
||||||
|
SetMetadata('permissions', permissions);
|
Loading…
Reference in a new issue