chg: [navigation] added keycloak self management
- also some changes to the navigation systemcli-modification-summary
parent
94bfafb743
commit
d35a674505
|
@ -1,6 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
namespace BreadcrumbNavigation;
|
namespace BreadcrumbNavigation;
|
||||||
|
|
||||||
|
use Cake\Core\Configure;
|
||||||
require_once(APP . 'Controller' . DS . 'Component' . DS . 'Navigation' . DS . 'base.php');
|
require_once(APP . 'Controller' . DS . 'Component' . DS . 'Navigation' . DS . 'base.php');
|
||||||
|
|
||||||
class UsersNavigation extends BaseNavigation
|
class UsersNavigation extends BaseNavigation
|
||||||
|
@ -24,6 +25,7 @@ class UsersNavigation extends BaseNavigation
|
||||||
$bcf = $this->bcf;
|
$bcf = $this->bcf;
|
||||||
$request = $this->request;
|
$request = $this->request;
|
||||||
$passedData = $this->request->getParam('pass');
|
$passedData = $this->request->getParam('pass');
|
||||||
|
$currentUserId = $this->currentUserId;
|
||||||
$currentUser = $this->currentUser;
|
$currentUser = $this->currentUser;
|
||||||
$this->bcf->addLink('Users', 'view', 'UserSettings', 'index', function ($config) use ($bcf, $request, $passedData, $currentUser) {
|
$this->bcf->addLink('Users', 'view', 'UserSettings', 'index', function ($config) use ($bcf, $request, $passedData, $currentUser) {
|
||||||
if (!empty($passedData[0])) {
|
if (!empty($passedData[0])) {
|
||||||
|
@ -69,6 +71,21 @@ class UsersNavigation extends BaseNavigation
|
||||||
}
|
}
|
||||||
return [];
|
return [];
|
||||||
});
|
});
|
||||||
|
if (
|
||||||
|
!empty(Configure::read('keycloak.enabled')) &&
|
||||||
|
!empty(Configure::read('keycloak.provider.baseUrl')) &&
|
||||||
|
!empty(Configure::read('keycloak.provider.realm')) &&
|
||||||
|
$currentUserId == $passedData[0]
|
||||||
|
) {
|
||||||
|
$url = sprintf(
|
||||||
|
'%s/realms/%s/account',
|
||||||
|
Configure::read('keycloak.provider.baseUrl'),
|
||||||
|
Configure::read('keycloak.provider.realm')
|
||||||
|
);
|
||||||
|
foreach (['edit', 'view', 'settings'] as $sourceAction) {
|
||||||
|
$this->bcf->addCustomLink('Users', $sourceAction, $url, __('Manage KeyCloak Account'));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$this->bcf->addLink('Users', 'settings', 'Users', 'view', function ($config) use ($bcf, $request, $passedData) {
|
$this->bcf->addLink('Users', 'settings', 'Users', 'view', function ($config) use ($bcf, $request, $passedData) {
|
||||||
if (!empty($passedData[0])) {
|
if (!empty($passedData[0])) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ class BaseNavigation
|
||||||
{
|
{
|
||||||
$this->bcf = $bcf;
|
$this->bcf = $bcf;
|
||||||
$this->request = $request;
|
$this->request = $request;
|
||||||
|
$this->currentUserId = $this->request->getAttribute('identity')->getIdentifier();
|
||||||
$this->viewVars = $viewVars;
|
$this->viewVars = $viewVars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -346,6 +346,18 @@ class BreadcrumbFactory
|
||||||
$this->endpoints[$sourceController][$sourceAction]['links'] = $links;
|
$this->endpoints[$sourceController][$sourceAction]['links'] = $links;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function addCustomLink(string $sourceController, string $sourceAction, string $targetUrl, string $label, $overrides = [])
|
||||||
|
{
|
||||||
|
$routeSourceConfig = $this->getRouteConfig($sourceController, $sourceAction, true);
|
||||||
|
$links = array_merge($routeSourceConfig['links'] ?? [], [[
|
||||||
|
'url' => $targetUrl,
|
||||||
|
'icon' => 'link',
|
||||||
|
'label' => $label,
|
||||||
|
'route_path' => 'foo:bar'
|
||||||
|
]]);
|
||||||
|
$this->endpoints[$sourceController][$sourceAction]['links'] = $links;
|
||||||
|
}
|
||||||
|
|
||||||
public function addAction(string $sourceController, string $sourceAction, string $targetController, string $targetAction, $overrides = [])
|
public function addAction(string $sourceController, string $sourceAction, string $targetController, string $targetAction, $overrides = [])
|
||||||
{
|
{
|
||||||
$routeSourceConfig = $this->getRouteConfig($sourceController, $sourceAction, true);
|
$routeSourceConfig = $this->getRouteConfig($sourceController, $sourceAction, true);
|
||||||
|
|
|
@ -49,7 +49,11 @@ if (!empty($breadcrumb)) {
|
||||||
if (!empty($lastCrumb['links'])) {
|
if (!empty($lastCrumb['links'])) {
|
||||||
// dd($lastCrumb['links']);
|
// dd($lastCrumb['links']);
|
||||||
foreach ($lastCrumb['links'] as $i => $linkEntry) {
|
foreach ($lastCrumb['links'] as $i => $linkEntry) {
|
||||||
$active = $linkEntry['route_path'] == $lastCrumb['route_path'];
|
if (empty($linkEntry['route_path'])) {
|
||||||
|
$active = false;
|
||||||
|
} else {
|
||||||
|
$active = $linkEntry['route_path'] == $lastCrumb['route_path'];
|
||||||
|
}
|
||||||
if (!empty($linkEntry['url_vars'])) {
|
if (!empty($linkEntry['url_vars'])) {
|
||||||
$linkEntry['url'] = $this->DataFromPath->buildStringFromDataPath($linkEntry['url'], $entity, $linkEntry['url_vars']);
|
$linkEntry['url'] = $this->DataFromPath->buildStringFromDataPath($linkEntry['url'], $entity, $linkEntry['url_vars']);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue