mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-14 23:24:46 -04:00
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>
This commit is contained in:
parent
4e298cccfb
commit
a852c79947
15 changed files with 925 additions and 787 deletions
34
backend/src/permissions/note-permission.enum.ts
Normal file
34
backend/src/permissions/note-permission.enum.ts
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*
|
||||
* 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';
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue