added JS api to access current user in frontend (#4064)

This commit is contained in:
Kevin Papst
2023-05-26 18:40:54 +02:00
committed by GitHub
parent b4a4d81ca8
commit 9c1150c50e
11 changed files with 90 additions and 9 deletions

View File

@@ -88,4 +88,11 @@ export default class KimaiContainer {
return this._configuration;
}
/**
* @returns {KimaiUser}
*/
getUser() {
return this.getPlugin('user');
}
}

View File

@@ -41,6 +41,7 @@ import KimaiDateNowForm from "./forms/KimaiDateNowForm";
import KimaiNotification from "./plugins/KimaiNotification";
import KimaiHotkeys from "./plugins/KimaiHotkeys";
import KimaiRemoteModal from "./plugins/KimaiRemoteModal";
import KimaiUser from "./plugins/KimaiUser";
export default class KimaiLoader {
@@ -55,6 +56,7 @@ export default class KimaiLoader {
);
// GLOBAL HELPER PLUGINS
kimai.registerPlugin(new KimaiUser());
kimai.registerPlugin(new KimaiEscape());
kimai.registerPlugin(new KimaiEvent());
kimai.registerPlugin(new KimaiAPI());

View File

@@ -0,0 +1,52 @@
/*
* This file is part of the Kimai time-tracking app.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
/*!
* [KIMAI] KimaiUser: information about the current user
*/
import KimaiPlugin from "../KimaiPlugin";
export default class KimaiUser extends KimaiPlugin {
getId() {
return 'user';
}
init() {
this.user = this.getConfigurations().get('user');
}
/**
* @returns {string}
*/
getUserId() {
return this.user.id;
}
/**
* @returns {string}
*/
getName() {
return this.user.name;
}
/**
* @returns {boolean}
*/
isAdmin() {
return this.user.admin;
}
/**
* @returns {boolean}
*/
isSuperAdmin() {
return this.user.superAdmin;
}
}