new: [ACL Helper] check access for controller / action pair for given user
- accesible everywhere in the UIpull/79/head
parent
e408f29a05
commit
1e31f4d1dd
|
@ -44,5 +44,6 @@ class AppView extends View
|
||||||
$this->loadHelper('FormFieldMassage');
|
$this->loadHelper('FormFieldMassage');
|
||||||
$this->loadHelper('Paginator', ['templates' => 'cerebrate-pagination-templates']);
|
$this->loadHelper('Paginator', ['templates' => 'cerebrate-pagination-templates']);
|
||||||
$this->loadHelper('Tags.Tag');
|
$this->loadHelper('Tags.Tag');
|
||||||
|
$this->loadHelper('ACL');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,25 @@
|
||||||
|
<?php
|
||||||
|
namespace App\View\Helper;
|
||||||
|
|
||||||
|
use Cake\View\Helper;
|
||||||
|
|
||||||
|
// This helper helps determining the brightness of a colour (initially only used for the tagging) in order to decide
|
||||||
|
// what text colour to use against the background (black or white)
|
||||||
|
class ACLHelper extends Helper {
|
||||||
|
|
||||||
|
private $roleAccess = [];
|
||||||
|
|
||||||
|
public function checkAccess($controller, $action) {
|
||||||
|
if (empty($this->roleAccess)) {
|
||||||
|
$this->roleAccess = $this->getView()->get('roleAccess');
|
||||||
|
}
|
||||||
|
if (
|
||||||
|
in_array($action, $this->roleAccess['*']) ||
|
||||||
|
(isset($this->roleAccess[$controller]) && in_array($action, $this->roleAccess[$controller]))
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue