Update dashboard permissions

This commit is contained in:
Ninjdai 2023-12-12 14:11:34 +01:00
parent 8a8b21ba85
commit 3879f698d1
16 changed files with 33 additions and 24 deletions

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/call/:phone",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CALL,
type: "post",
async execute(request, response) {
const { phone } = request.params;

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/contacts/:phone",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CONTACTS,
type: "post",
async execute(request, response) {
const { phone } = request.params;

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/contacts/:phone",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CONTACTS,
type: "delete",
async execute(request, response) {
const { phone } = request.params;

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/users/:username",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "post",
async execute(request, response) {
const { username } = request.params;

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/users/:username",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "delete",
async execute(request, response) {
const { username } = request.params;

View File

@ -3,7 +3,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/api/users/:username",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.DEFAULT,
type: "get",
async execute(request, response) {
const { username } = request.params;

View File

@ -5,7 +5,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/dashboard/contacts/create",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CONTACTS | permissionBits.ADMIN,
type: "get",
async execute(request, response, args) {
let res = await readFile(

View File

@ -5,7 +5,7 @@ import { navbar } from '../../../../../utils/navbar.js';
export default {
path: "/dashboard/contacts",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CONTACTS | permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const html = await readFile(`${process.env.WWW}/dashboard/contacts/index.html`);

View File

@ -5,7 +5,7 @@ import { permissionBits, checkPermissions } from '../../../../../utils/permissio
export default {
path: "/dashboard/contacts/list",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.CONTACTS | permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const contactList = await global.database.contacts.findAll();

View File

@ -5,7 +5,7 @@ import { permissionBits } from "../../../../../utils/permissions.js";
export default {
path: "/dashboard/users/create",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "get",
async execute(request, response, args) {
let res = await readFile(

View File

@ -5,7 +5,7 @@ import { navbar } from '../../../../../utils/navbar.js';
export default {
path: "/dashboard/users",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const html = await readFile(`${process.env.WWW}/dashboard/users/index.html`);

View File

@ -5,7 +5,7 @@ import { permissionBits, checkPermissions } from '../../../../../utils/permissio
export default {
path: "/dashboard/users/list",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const userList = await global.database.users.findAll();

View File

@ -8,7 +8,7 @@ import { navbar } from "../../../../../utils/navbar.js";
export default {
path: "/dashboard/users/:username",
requiresLogin: true,
permissions: permissionBits.ADMIN,
permissions: permissionBits.USERS | permissionBits.ADMIN,
type: "get",
async execute(request, response) {
const { username } = request.params;

View File

@ -1,8 +1,9 @@
const permissionBits = {
DEFAULT: 1, // 0001
CALL: 2, // 0010
UNUSED: 4, // 0100
ADMIN: 8, // 1000
DEFAULT: 1, // 00001
CALL: 2, // 00010
USERS: 4, // 00100
ADMIN: 8, // 01000
CONTACTS: 16, // 10000
}
function checkPermissions(userPermissionBits) {
@ -10,8 +11,9 @@ function checkPermissions(userPermissionBits) {
let permissions = {
default: false,
call: false,
unused: false,
users: false,
admin: false,
contacts: false,
}
if(userPermissionBits & permissionBits.DEFAULT) {
@ -20,12 +22,15 @@ function checkPermissions(userPermissionBits) {
if(userPermissionBits & permissionBits.CALL) {
permissions.call = true;
}
if(userPermissionBits & permissionBits.UNUSED) {
permissions.unused = true;
if(userPermissionBits & permissionBits.USERS) {
permissions.users = true;
}
if(userPermissionBits & permissionBits.ADMIN) {
permissions.admin = true;
}
if(userPermissionBits & permissionBits.CONTACTS) {
permissions.contacts = true;
}
return permissions;
}
/*

View File

@ -104,7 +104,7 @@ a {
<NAVBAR>
<form action="javascript:createContactFromForm()" id="contactCreateForm">
<div class="container">
<h1>Création de compte</h1>
<h1>Création de contact</h1>
<p>Formulaire d'ajout de contact.</p>
<hr>

View File

@ -126,10 +126,14 @@ a {
<input type="checkbox" name="permissions" value="2">
<span class="checkmark"></span>
</label>
<!--<label class="container">Unused
<input type="checkbox">
<label class="container">Gestion des utilisateurs
<input type="checkbox" name="permissions" value="4">
<span class="checkmark"></span>
</label>-->
</label>
<label class="container">Gestion des contacts
<input type="checkbox" name="permissions" value="16">
<span class="checkmark"></span>
</label>
<label class="container">Admin
<input type="checkbox" name="permissions" value="8">
<span class="checkmark"></span>