added JS api to access current user in frontend (#4064)
This commit is contained in:
@@ -88,4 +88,11 @@ export default class KimaiContainer {
|
|||||||
return this._configuration;
|
return this._configuration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {KimaiUser}
|
||||||
|
*/
|
||||||
|
getUser() {
|
||||||
|
return this.getPlugin('user');
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -41,6 +41,7 @@ import KimaiDateNowForm from "./forms/KimaiDateNowForm";
|
|||||||
import KimaiNotification from "./plugins/KimaiNotification";
|
import KimaiNotification from "./plugins/KimaiNotification";
|
||||||
import KimaiHotkeys from "./plugins/KimaiHotkeys";
|
import KimaiHotkeys from "./plugins/KimaiHotkeys";
|
||||||
import KimaiRemoteModal from "./plugins/KimaiRemoteModal";
|
import KimaiRemoteModal from "./plugins/KimaiRemoteModal";
|
||||||
|
import KimaiUser from "./plugins/KimaiUser";
|
||||||
|
|
||||||
export default class KimaiLoader {
|
export default class KimaiLoader {
|
||||||
|
|
||||||
@@ -55,6 +56,7 @@ export default class KimaiLoader {
|
|||||||
);
|
);
|
||||||
|
|
||||||
// GLOBAL HELPER PLUGINS
|
// GLOBAL HELPER PLUGINS
|
||||||
|
kimai.registerPlugin(new KimaiUser());
|
||||||
kimai.registerPlugin(new KimaiEscape());
|
kimai.registerPlugin(new KimaiEscape());
|
||||||
kimai.registerPlugin(new KimaiEvent());
|
kimai.registerPlugin(new KimaiEvent());
|
||||||
kimai.registerPlugin(new KimaiAPI());
|
kimai.registerPlugin(new KimaiAPI());
|
||||||
|
|||||||
52
assets/js/plugins/KimaiUser.js
Normal file
52
assets/js/plugins/KimaiUser.js
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
2
public/build/app.79ed1fb4.js
Normal file
2
public/build/app.79ed1fb4.js
Normal file
File diff suppressed because one or more lines are too long
@@ -160,6 +160,10 @@
|
|||||||
* [KIMAI] KimaiTranslation: handling translation strings
|
* [KIMAI] KimaiTranslation: handling translation strings
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*!
|
||||||
|
* [KIMAI] KimaiUser: information about the current user
|
||||||
|
*/
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
* [KIMAI] Notification: notifications for Kimai
|
* [KIMAI] Notification: notifications for Kimai
|
||||||
*/
|
*/
|
||||||
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@
|
|||||||
"app": {
|
"app": {
|
||||||
"js": [
|
"js": [
|
||||||
"/build/runtime.f0079159.js",
|
"/build/runtime.f0079159.js",
|
||||||
"/build/app.f0378e96.js"
|
"/build/app.79ed1fb4.js"
|
||||||
],
|
],
|
||||||
"css": [
|
"css": [
|
||||||
"/build/app.5710a463.css"
|
"/build/app.5710a463.css"
|
||||||
@@ -63,7 +63,7 @@
|
|||||||
},
|
},
|
||||||
"integrity": {
|
"integrity": {
|
||||||
"/build/runtime.f0079159.js": "sha384-H22sAW1aTvyIPqvHOvGXWSWTxf0y6mptp+MsVmyXCfjx/WJjBbhX9gbUZ+qIuihV",
|
"/build/runtime.f0079159.js": "sha384-H22sAW1aTvyIPqvHOvGXWSWTxf0y6mptp+MsVmyXCfjx/WJjBbhX9gbUZ+qIuihV",
|
||||||
"/build/app.f0378e96.js": "sha384-ohZkuGMYJFa1nD/JJb1XJy6CYfqk/ubIo9QuY3yYJFg7NEG+0U93+YIIvUnCm2xm",
|
"/build/app.79ed1fb4.js": "sha384-QQ83F5EDtEEzO9+/Sg8jAkxsM/GVnZmTdC/a7p83t4zxVU1VYPD2AKp21pcM1Lj1",
|
||||||
"/build/app.5710a463.css": "sha384-kqam1K3HVJSgDgp3YsKvzA5VGQQB2USKq6UbuIHQvn9tshMribY5Axgg2ar7vTIR",
|
"/build/app.5710a463.css": "sha384-kqam1K3HVJSgDgp3YsKvzA5VGQQB2USKq6UbuIHQvn9tshMribY5Axgg2ar7vTIR",
|
||||||
"/build/export-pdf.d367a32e.js": "sha384-Z5baqnzjI636nYFs4g63ViIKBZKRW4Jhv/7PQmTEQlqhfA7eK0vUMUtiyy0R5A9u",
|
"/build/export-pdf.d367a32e.js": "sha384-Z5baqnzjI636nYFs4g63ViIKBZKRW4Jhv/7PQmTEQlqhfA7eK0vUMUtiyy0R5A9u",
|
||||||
"/build/export-pdf.d8a6c23b.css": "sha384-ztepocHE4rnGE9eKZ4kL6jTKaePUyiwiB9TjJjstjpf/ckcKg1HedrEOOk/8ElJg",
|
"/build/export-pdf.d8a6c23b.css": "sha384-ztepocHE4rnGE9eKZ4kL6jTKaePUyiwiB9TjJjstjpf/ckcKg1HedrEOOk/8ElJg",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"build/app.css": "/build/app.5710a463.css",
|
"build/app.css": "/build/app.5710a463.css",
|
||||||
"build/app.js": "/build/app.f0378e96.js",
|
"build/app.js": "/build/app.79ed1fb4.js",
|
||||||
"build/export-pdf.css": "/build/export-pdf.d8a6c23b.css",
|
"build/export-pdf.css": "/build/export-pdf.d8a6c23b.css",
|
||||||
"build/export-pdf.js": "/build/export-pdf.d367a32e.js",
|
"build/export-pdf.js": "/build/export-pdf.d367a32e.js",
|
||||||
"build/invoice.css": "/build/invoice.5bea118e.css",
|
"build/invoice.css": "/build/invoice.5bea118e.css",
|
||||||
|
|||||||
@@ -211,6 +211,7 @@ final class LocaleFormatExtensions extends AbstractExtension implements LocaleAw
|
|||||||
'twentyFourHours' => $this->localeService->is24Hour($this->locale),
|
'twentyFourHours' => $this->localeService->is24Hour($this->locale),
|
||||||
'updateBrowserTitle' => (bool) $user->getPreferenceValue('update_browser_title'),
|
'updateBrowserTitle' => (bool) $user->getPreferenceValue('update_browser_title'),
|
||||||
'timezone' => $user->getTimezone(),
|
'timezone' => $user->getTimezone(),
|
||||||
|
'user' => ['id' => $user->getId(), 'name' => $user->getDisplayName(), 'admin' => $user->isAdmin(), 'superAdmin' => $user->isSuperAdmin()],
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -44,12 +44,17 @@ class HtmlRendererTest extends AbstractRendererTest
|
|||||||
|
|
||||||
public function testRender()
|
public function testRender()
|
||||||
{
|
{
|
||||||
$kernel = self::bootKernel();
|
|
||||||
/** @var Environment $twig */
|
/** @var Environment $twig */
|
||||||
$twig = self::getContainer()->get('twig');
|
$twig = self::getContainer()->get('twig');
|
||||||
|
|
||||||
|
$user = $this->createMock(User::class);
|
||||||
|
$user->method('getId')->willReturn(1);
|
||||||
|
$user->method('getName')->willReturn('Testing');
|
||||||
|
$user->method('isAdmin')->willReturn(false);
|
||||||
|
$user->method('isSuperAdmin')->willReturn(false);
|
||||||
|
$user->method('getTimezone')->willReturn('America/Edmonton');
|
||||||
$token = $this->createMock(TokenInterface::class);
|
$token = $this->createMock(TokenInterface::class);
|
||||||
$token->expects($this->any())->method('getUser')->willReturn(new User());
|
$token->expects($this->any())->method('getUser')->willReturn($user);
|
||||||
|
|
||||||
$tokenStorage = new TokenStorage();
|
$tokenStorage = new TokenStorage();
|
||||||
$tokenStorage->setToken($token);
|
$tokenStorage->setToken($token);
|
||||||
|
|||||||
@@ -472,9 +472,19 @@ class LocaleFormatExtensionsTest extends TestCase
|
|||||||
'twentyFourHours' => false,
|
'twentyFourHours' => false,
|
||||||
'updateBrowserTitle' => false,
|
'updateBrowserTitle' => false,
|
||||||
'timezone' => 'America/Edmonton',
|
'timezone' => 'America/Edmonton',
|
||||||
|
'user' => [
|
||||||
|
'id' => 1,
|
||||||
|
'name' => null,
|
||||||
|
'admin' => false,
|
||||||
|
'superAdmin' => false,
|
||||||
|
],
|
||||||
];
|
];
|
||||||
$user = new User();
|
$user = $this->createMock(User::class);
|
||||||
$user->setTimezone('America/Edmonton');
|
$user->method('getId')->willReturn(1);
|
||||||
|
$user->method('getName')->willReturn('Testing');
|
||||||
|
$user->method('isAdmin')->willReturn(false);
|
||||||
|
$user->method('isSuperAdmin')->willReturn(false);
|
||||||
|
$user->method('getTimezone')->willReturn('America/Edmonton');
|
||||||
$sut = $this->getSut('en', $this->localeEn);
|
$sut = $this->getSut('en', $this->localeEn);
|
||||||
self::assertEquals($expected, $sut->getJavascriptConfiguration($user));
|
self::assertEquals($expected, $sut->getJavascriptConfiguration($user));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user