Skip to content
Snippets Groups Projects
Commit 82331276 authored by kelly.nguyen's avatar kelly.nguyen
Browse files

add check privileges to user list

parent fab67593
No related branches found
No related tags found
No related merge requests found
Pipeline #29946 failed
......@@ -15,16 +15,12 @@ class UserChangeRoleCommand extends CommanderCommand {
}
protected async commandAction(id: string, newRole : string): Promise<void> {
// TODO : newRole -> type UserRole
// check privileges
{
console.log(chalk.cyan('Please wait while we are changing the role of the user...'));
const spinner = ora({
text : 'Retrieving gitlab tokens',
indent: 4
}).start();
// TODO : newRole -> type UserRole
// TODO : Can't modify own role
// check if ADMIN
const sessionResult = await SessionManager.testSession(true, [ 'admin' ]);
console.log(sessionResult);
console.log(SessionManager.profile?.id);
......@@ -32,6 +28,14 @@ class UserChangeRoleCommand extends CommanderCommand {
if ( !sessionResult || !sessionResult.admin ) {
return ;
}
}
// change role
{
const spinner = ora({
text : 'Updating role',
indent: 4
}).start();
try {
if (SessionManager.profile?.id != +id) {
......
......@@ -3,6 +3,7 @@ import CommanderCommand from "../../CommanderCommand";
import DojoBackendManager from "../../../managers/DojoBackendManager";
import User from "../../../sharedByClients/models/User";
import ora from "ora";
import SessionManager from "../../../managers/SessionManager";
class UserListCommand extends CommanderCommand {
protected commandName : string = 'list';
......@@ -16,9 +17,23 @@ class UserListCommand extends CommanderCommand {
protected async commandAction(): Promise<void> {
let users : User[] = [];
// Retrieve data
// check privileges
{
console.log(chalk.cyan('Please wait while we are retrieving the users...'));
// check if ADMIN
const sessionResult = await SessionManager.testSession(true, [ 'admin' ]);
console.log(sessionResult);
console.log(SessionManager.profile?.id);
if ( !sessionResult || !sessionResult.admin ) {
return ;
}
}
// Retrieve data
{
// TODO : display data in table
users = await DojoBackendManager.getAllUsers();
users.forEach(user => {
const oraInfo = (message: string) => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment