hedgedoc/backend/src/permissions/note-permission.enum.ts
Tilman Vatteroth a852c79947 refactor: replace permission check methods with ordered permission enum
This commit replaces the "mayWrite", "mayRead" and "checkPermissionOnNote"
functions with one that returns a sortable permission value.
This is done because many places in the code need to do actions based on the fact if
the user has no, read or write access. If done with the may-functions then the permission
data need to be looked through multiple times.

Also, the whole check code is split into more functions that are tested separately and make it easier
to understand the process.

Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
2023-05-19 19:10:45 +02:00

34 lines
783 B
TypeScript

/*
* SPDX-FileCopyrightText: 2023 The HedgeDoc developers (see AUTHORS file)
*
* SPDX-License-Identifier: AGPL-3.0-only
*/
/**
* Defines if a user can access a note and if yes how much power they have.
*/
export enum NotePermission {
DENY = 0,
READ = 1,
WRITE = 2,
OWNER = 3,
}
/**
* Returns the display name for the given {@link NotePermission}.
*
* @param {NotePermission} value the note permission to display
* @return {string} The display name
*/
export function getNotePermissionDisplayName(value: NotePermission): string {
switch (value) {
case NotePermission.DENY:
return 'deny';
case NotePermission.READ:
return 'read';
case NotePermission.WRITE:
return 'write';
case NotePermission.OWNER:
return 'owner';
}
}