defaultData(); $rolesc = new \core_kernel_classes_Class(GenerisRdf::CLASS_ROLE); $roles = []; foreach ($rolesc->getInstances(true) as $id => $r) { $roles[] = ['id' => $id, 'label' => $r->getLabel()]; } usort($roles, function ($a, $b) { return strcmp($a['label'], $b['label']); }); $this->setData('roles', $roles); $this->setView('list.tpl'); } /** * @throws \common_exception_Error * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function getModules() { $this->beforeAction(); $role = new \core_kernel_classes_Class($this->getRequestParameter('role')); $included = []; foreach (\tao_models_classes_RoleService::singleton()->getIncludedRoles($role) as $includedRole) { $included[$includedRole->getUri()] = $includedRole->getLabel(); } $extManager = \common_ext_ExtensionsManager::singleton(); $extData = []; foreach ($extManager->getInstalledExtensions() as $extension) { if ($extension->getId() != 'generis') { $extData[] = $this->buildExtensionData($extension, $role->getUri(), array_keys($included)); } } usort($extData, function ($a, $b) { return strcmp($a['label'], $b['label']); }); $this->returnJson([ 'extensions' => $extData, 'includedRoles' => $included, 'locked' => $this->isLocked(), ]); } protected function buildExtensionData(\common_ext_Extension $extension, $roleUri, $includedRoleUris) { $extAccess = CacheHelper::getExtensionAccess($extension->getId()); $extAclUri = AccessService::singleton()->makeEMAUri($extension->getId()); $atLeastOneAccess = false; $allAccess = in_array($roleUri, $extAccess); $inherited = count(array_intersect($includedRoleUris, $extAccess)) > 0; $controllers = []; foreach (ControllerHelper::getControllers($extension->getId()) as $controllerClassName) { $controllerData = $this->buildControllerData($controllerClassName, $roleUri, $includedRoleUris); $atLeastOneAccess = $atLeastOneAccess || $controllerData['access'] != self::ACCESS_NONE; $controllers[] = $controllerData; } usort($controllers, function ($a, $b) { return strcmp($a['label'], $b['label']); }); $access = $inherited ? 'inherited' : ($allAccess ? 'full' : ($atLeastOneAccess ? 'partial' : 'none')); return [ 'uri' => $extAclUri, 'label' => $extension->getName(), 'access' => $access, 'modules' => $controllers ]; } protected function buildControllerData($controllerClassName, $roleUri, $includedRoleUris) { $modUri = MapHelper::getUriForController($controllerClassName); $moduleAccess = CacheHelper::getControllerAccess($controllerClassName); $uri = explode('#', $modUri); list($type, $extId, $modId) = explode('_', $uri[1]); $access = self::ACCESS_NONE; if (count(array_intersect($includedRoleUris, $moduleAccess['module'])) > 0) { $access = self::ACCESS_INHERITED; } elseif (true === in_array($roleUri, $moduleAccess['module'])) { $access = self::ACCESS_FULL; } else { // have a look at actions. foreach ($moduleAccess['actions'] as $roles) { if (in_array($roleUri, $roles) || count(array_intersect($includedRoleUris, $roles)) > 0) { $access = self::ACCESS_PARTIAL; break; } } } return [ 'uri' => $modUri, 'label' => $modId, 'access' => $access, ]; } /** * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ private function beforeAction() { $this->defaultData(); if (!\tao_helpers_Request::isAjax()) { throw new common_exception_BadRequest('wrong request mode'); } } /** * @return bool */ private function isLocked() { $locked = !$this->getServiceLocator()->get(AclProxy::SERVICE_ID) instanceof FuncAcl; $locked = $locked || !$this->getServiceLocator()->get(ApplicationService::SERVICE_ID)->isDebugMode(); return $locked; } /** * @throws \common_exception_NotFound */ private function prodLocker() { if ($this->isLocked()) { throw new \common_exception_NotFound(); } } /** * Shows the access to the actions of a controller for a specific role * * @throws \common_exception_Error * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function getActions() { $this->beforeAction(); $role = new \core_kernel_classes_Resource($this->getRequestParameter('role')); $included = []; foreach (\tao_models_classes_RoleService::singleton()->getIncludedRoles($role) as $includedRole) { $included[] = $includedRole->getUri(); } $module = new \core_kernel_classes_Resource($this->getRequestParameter('module')); $controllerClassName = MapHelper::getControllerFromUri($module->getUri()); $controllerAccess = CacheHelper::getControllerAccess($controllerClassName); $actions = []; foreach (ControllerHelper::getActions($controllerClassName) as $actionName) { $uri = MapHelper::getUriForAction($controllerClassName, $actionName); $part = explode('#', $uri); list($type, $extId, $modId, $actId) = explode('_', $part[1]); $allowedRoles = isset($controllerAccess['actions'][$actionName]) ? array_merge($controllerAccess['module'], $controllerAccess['actions'][$actionName]) : $controllerAccess['module']; $access = count(array_intersect($included, $allowedRoles)) > 0 ? self::ACCESS_INHERITED : (in_array($role->getUri(), $allowedRoles) ? self::ACCESS_FULL : self::ACCESS_NONE); $actions[$actId] = [ 'uri' => $uri, 'access' => $access, 'locked' => $this->isLocked(), ]; } ksort($actions); $this->returnJson($actions); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function removeExtensionAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $extensionService = ExtensionAccessService::singleton(); $extensionService->remove($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function addExtensionAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $extensionService = ExtensionAccessService::singleton(); $extensionService->add($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function removeModuleAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $moduleService = ModuleAccessService::singleton(); $moduleService->remove($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function addModuleAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $moduleService = ModuleAccessService::singleton(); $moduleService->add($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function removeActionAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $actionService = ActionAccessService::singleton(); $actionService->remove($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } /** * @throws \common_exception_NotFound * @throws \common_ext_ExtensionException * @throws common_exception_BadRequest */ public function addActionAccess() { $this->beforeAction(); $this->prodLocker(); $role = $this->getRequestParameter('role'); $uri = $this->getRequestParameter('uri'); $actionService = ActionAccessService::singleton(); $actionService->add($role, $uri); $this->returnJson([ 'uri' => $uri, ]); } }