Merge branch 'develop' of github.com:cerebrate-project/cerebrate into develop
commit
74e95855bd
|
@ -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()) {
|
||||
|
|
|
@ -277,9 +277,29 @@ class ACLComponent extends Component
|
|||
$this->user = $user;
|
||||
}
|
||||
|
||||
public function getUser(): User
|
||||
public function getUser(): ?User
|
||||
{
|
||||
return $this->user;
|
||||
if (!empty($this->user)) {
|
||||
return $this->user;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public function canEditUser(User $currentUser, User $user): bool
|
||||
{
|
||||
if (empty($user) || empty($currentUser)) {
|
||||
return false;
|
||||
}
|
||||
if (!$currentUser['role']['perm_admin']) {
|
||||
if (!$currentUser['role']['perm_org_admin']) {
|
||||
return false;
|
||||
} else {
|
||||
if ($currentUser['organisation_id'] !== $user['organisation_id']) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<?php
|
||||
namespace BreadcrumbNavigation;
|
||||
|
||||
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
|
||||
{
|
||||
|
@ -24,17 +24,21 @@ class UsersNavigation extends BaseNavigation
|
|||
$bcf = $this->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];
|
||||
|
|
|
@ -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() {}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,5 +10,10 @@ class Organisation extends AppModel
|
|||
protected $_accessible = [
|
||||
'*' => true,
|
||||
'id' => false,
|
||||
'created' => false
|
||||
];
|
||||
|
||||
protected $_accessibleOnNew = [
|
||||
'created' => true
|
||||
];
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue