From c186c88d5c186961f1ecdd5aa97e5f361f29cee8 Mon Sep 17 00:00:00 2001 From: iglocska Date: Wed, 26 Jan 2022 14:21:27 +0100 Subject: [PATCH] chg: [navigation] Breadcrumb generation is user aware - moved the initialisation of the generation to be invoked from the appcontroller's beforefilter, after the user is loaded into the ACL component - Only show user setting edits when the user is editing themselves --- src/Controller/AppController.php | 1 + src/Controller/Component/Navigation/Users.php | 28 +++++++++++-------- src/Controller/Component/Navigation/base.php | 8 +++++- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/src/Controller/AppController.php b/src/Controller/AppController.php index 0bb2373..006736c 100644 --- a/src/Controller/AppController.php +++ b/src/Controller/AppController.php @@ -110,6 +110,7 @@ class AppController extends Controller } unset($user['password']); $this->ACL->setUser($user); + $this->Navigation->genBreadcrumbs($user); $this->request->getSession()->write('authUser', $user); $this->isAdmin = $user['role']['perm_admin']; if (!$this->ParamHandler->isRest()) { diff --git a/src/Controller/Component/Navigation/Users.php b/src/Controller/Component/Navigation/Users.php index 7e228db..860545d 100644 --- a/src/Controller/Component/Navigation/Users.php +++ b/src/Controller/Component/Navigation/Users.php @@ -1,7 +1,7 @@ bcf; $request = $this->request; $passedData = $this->request->getParam('pass'); - $this->bcf->addLink('Users', 'view', 'UserSettings', 'index', function ($config) use ($bcf, $request, $passedData) { - if (!empty($passedData[0])) { - $user_id = $passedData[0]; - $linkData = [ - 'label' => __('Account settings', h($user_id)), - 'url' => sprintf('/users/settings/%s', h($user_id)) - ]; - return $linkData; - } - return []; - }); + $currentUser = $this->currentUser; + $ownUser = (!empty($passedData[0]) && $passedData[0] === $currentUser['id']); + if ($ownUser) { + $this->bcf->addLink('Users', 'view', 'UserSettings', 'index', function ($config) use ($bcf, $request, $passedData, $currentUser) { + if (!empty($passedData[0])) { + $user_id = $passedData[0]; + $linkData = [ + 'label' => __('Account settings', h($user_id)), + 'url' => sprintf('/users/settings/%s', h($user_id)) + ]; + return $linkData; + } + return []; + }); + } $this->bcf->addLink('Users', 'view', 'UserSettings', 'index', function ($config) use ($bcf, $request, $passedData) { if (!empty($passedData[0])) { $user_id = $passedData[0]; diff --git a/src/Controller/Component/Navigation/base.php b/src/Controller/Component/Navigation/base.php index 84dde96..b426ab5 100644 --- a/src/Controller/Component/Navigation/base.php +++ b/src/Controller/Component/Navigation/base.php @@ -5,6 +5,7 @@ class BaseNavigation { protected $bcf; protected $request; + public $currentUser; public function __construct($bcf, $request) { @@ -12,8 +13,13 @@ class BaseNavigation $this->request = $request; } + public function setCurrentUser($currentUser) + { + $this->currentUser = $currentUser; + } + public function addRoutes() {} public function addParents() {} public function addLinks() {} public function addActions() {} -} \ No newline at end of file +}