chg: [navigation:individuals] Only show edit and deletion buttons if users are allowed to do it
parent
3514f8bd7c
commit
7377e77204
|
@ -5,4 +5,21 @@ require_once(APP . 'Controller' . DS . 'Component' . DS . 'Navigation' . DS . 'b
|
||||||
|
|
||||||
class IndividualsNavigation extends BaseNavigation
|
class IndividualsNavigation extends BaseNavigation
|
||||||
{
|
{
|
||||||
|
public function addLinks()
|
||||||
|
{
|
||||||
|
$controller = 'Individuals';
|
||||||
|
if (empty($this->viewVars['canEdit'])) {
|
||||||
|
$this->bcf->removeLink($controller, 'view', $controller, 'edit');
|
||||||
|
$this->bcf->removeLink($controller, 'edit', $controller, 'edit');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function addActions()
|
||||||
|
{
|
||||||
|
$controller = 'Individuals';
|
||||||
|
if (empty($this->viewVars['canDelete'])) {
|
||||||
|
$this->bcf->removeAction($controller, 'view', $controller, 'delete');
|
||||||
|
$this->bcf->removeAction($controller, 'edit', $controller, 'delete');
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -402,6 +402,20 @@ class BreadcrumbFactory
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function removeAction(string $sourceController, string $sourceAction, string $targetController, string $targetAction)
|
||||||
|
{
|
||||||
|
$routeSourceConfig = $this->getRouteConfig($sourceController, $sourceAction, true);
|
||||||
|
if (!empty($routeSourceConfig['actions'])) {
|
||||||
|
foreach ($routeSourceConfig['actions'] as $i => $routeConfig) {
|
||||||
|
if ($routeConfig['controller'] == $targetController && $routeConfig['action'] == $targetAction) {
|
||||||
|
unset($routeSourceConfig['actions'][$i]);
|
||||||
|
$this->endpoints[$sourceController][$sourceAction]['actions'] = $routeSourceConfig['actions'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public function getRouteConfig($controller, $action, $fullRoute = false)
|
public function getRouteConfig($controller, $action, $fullRoute = false)
|
||||||
{
|
{
|
||||||
$routeConfig = $this->get($controller, $action);
|
$routeConfig = $this->get($controller, $action);
|
||||||
|
|
|
@ -69,6 +69,7 @@ class IndividualsController extends AppController
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
$this->set('canEdit', $this->canEdit($id));
|
$this->set('canEdit', $this->canEdit($id));
|
||||||
|
$this->set('canDelete', $this->canDelete($id));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function edit($id)
|
public function edit($id)
|
||||||
|
@ -89,6 +90,8 @@ class IndividualsController extends AppController
|
||||||
if (!empty($responsePayload)) {
|
if (!empty($responsePayload)) {
|
||||||
return $responsePayload;
|
return $responsePayload;
|
||||||
}
|
}
|
||||||
|
$this->set('canEdit', $this->canEdit($id));
|
||||||
|
$this->set('canDelete', $this->canDelete($id));
|
||||||
$this->render('add');
|
$this->render('add');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -155,4 +158,17 @@ class IndividualsController extends AppController
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function canDelete($indId): bool
|
||||||
|
{
|
||||||
|
$associatedUsersCount = $this->Individuals->Users->find()->select(['id'])->where(['individual_id' => $indId])->count();
|
||||||
|
if ($associatedUsersCount > 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
$currentUser = $this->ACL->getUser();
|
||||||
|
if ($currentUser['role']['perm_admin']) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue