mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 15:14:56 -04:00

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>
34 lines
783 B
TypeScript
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';
|
|
}
|
|
}
|