diff --git a/application/Espo/Controllers/Role.php b/application/Espo/Controllers/Role.php index bfc39e6c09..9703b1ee98 100644 --- a/application/Espo/Controllers/Role.php +++ b/application/Espo/Controllers/Role.php @@ -24,6 +24,6 @@ namespace Espo\Controllers; class Role extends \Espo\Core\Controllers\Record { - } + diff --git a/application/Espo/Controllers/User.php b/application/Espo/Controllers/User.php index 1e921f8533..550d8a96d0 100644 --- a/application/Espo/Controllers/User.php +++ b/application/Espo/Controllers/User.php @@ -22,7 +22,30 @@ namespace Espo\Controllers; -class User extends \Espo\Core\Controllers\Record -{ +use \Espo\Core\Exceptions\Error; +use \Espo\Core\Exceptions\NotFound; +use \Espo\Core\Exceptions\Forbidden; +class User extends \Espo\Core\Controllers\Record +{ + public function actionAcl($params, $data, $request) + { + $userId = $request->get('id'); + if (empty($userId)) { + throw new Error(); + } + + if (!$this->getUser()->isAdmin() && $this->getUser()->id != $userId) { + throw new Forbidden(); + } + + $user = $this->getEntityManager()->getEntity('User', $userId); + if (empty($user)) { + throw new NotFound(); + } + + $acl = new \Espo\Core\Acl($user); + + return $acl->toArray(); + } } diff --git a/application/Espo/Core/Acl.php b/application/Espo/Core/Acl.php index edd2e46b67..ffe405597a 100644 --- a/application/Espo/Core/Acl.php +++ b/application/Espo/Core/Acl.php @@ -36,10 +36,9 @@ class Acl private $fileManager; - public function __construct(\Espo\Entities\User $user, $config, $fileManager) + public function __construct(\Espo\Entities\User $user, $config = null, $fileManager = null) { - $this->user = $user; - $this->fileManager = $fileManager; + $this->user = $user; if (!$this->user->isFetched()) { throw new Error(); @@ -47,17 +46,23 @@ class Acl $this->user->loadLinkMultipleField('teams'); + if ($fileManager) { + $this->fileManager = $fileManager; + } + $this->cacheFile = 'data/cache/application/acl/' . $user->id . '.php'; - if ($config->get('useCache') && file_exists($this->cacheFile)) { + if ($config && $config->get('useCache') && file_exists($this->cacheFile)) { $cached = include $this->cacheFile; } else { $this->load(); $this->initSolid(); - if ($config->get('useCache')) { + if ($config && $fileManager && $config->get('useCache')) { $this->buildCache(); } } + + } public function checkScope($scope, $action = null, $isOwner = null, $inTeam = null)