add admin admin settings

This commit is contained in:
2023-08-28 04:31:58 +02:00
parent 4b84c475b8
commit 0958ff21b6
15 changed files with 524 additions and 28 deletions

56
src/lib/permissions.ts Normal file
View File

@@ -0,0 +1,56 @@
export class Permissions {
static readonly AdminRead = 2;
static readonly AdminWrite = 4;
static readonly UserRead = 8;
static readonly UserWrite = 16;
readonly value: number;
constructor(value: number | number[]) {
if (typeof value == 'number') {
this.value = value;
} else {
let finalValue = 0;
for (const v of Object.values(value)) {
finalValue |= v;
}
this.value = finalValue;
}
}
toJSON() {
return this.value;
}
static allPermissions(): number[] {
return [
Permissions.AdminRead,
Permissions.AdminWrite,
Permissions.UserRead,
Permissions.UserWrite
];
}
adminRead(): boolean {
return (this.value & Permissions.AdminRead) != 0;
}
adminWrite(): boolean {
return (this.value & Permissions.AdminWrite) != 0;
}
userRead(): boolean {
return (this.value & Permissions.UserRead) != 0;
}
userWrite(): boolean {
return (this.value & Permissions.UserWrite) != 0;
}
asArray(): number[] {
const array = [];
for (const perm of Permissions.allPermissions()) {
if ((this.value & perm) != 0) {
array.push(perm);
}
}
return array;
}
}