chg: [navigation] added keycloak self management

- also some changes to the navigation system
cli-modification-summary
iglocska 2022-08-24 11:39:56 +02:00
parent 94bfafb743
commit d35a674505
No known key found for this signature in database
GPG Key ID: BEA224F1FEF113AC
4 changed files with 35 additions and 1 deletions

View File

@ -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])) {

View File

@ -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;
} }

View File

@ -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);

View File

@ -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']);
} }