/** * Get the sections of the current extension's structure * * @param string $shownExtension * @param string $shownStructure * @return array the sections */ private function getSections($shownExtension, $shownStructure) { $sections = array(); $user = common_Session_SessionManager::getSession()->getUser(); $structure = MenuService::getPerspective($shownExtension, $shownStructure); if (!is_null($structure)) { foreach ($structure->getChildren() as $section) { $resolver = new ActionResolver($section->getUrl()); if (FuncProxy::accessPossible($user, $resolver->getController(), $resolver->getAction())) { foreach ($section->getActions() as $action) { $resolver = new ActionResolver($action->getUrl()); if (!FuncProxy::accessPossible($user, $resolver->getController(), $resolver->getAction())) { $section->removeAction($action); } } $sections[] = $section; } } } return $sections; }
/** * Add permission information to the tree structure * * @param array $tree * @return array */ protected function addPermissions($tree) { $user = \common_Session_SessionManager::getSession()->getUser(); $section = MenuService::getSection($this->getRequestParameter('extension'), $this->getRequestParameter('perspective'), $this->getRequestParameter('section')); $actions = array(); foreach ($section->getActions() as $index => $action) { try { $actions[$index] = array('resolver' => new ActionResolver($action->getUrl()), 'id' => $action->getId(), 'context' => $action->getContext()); } catch (\ResolverException $re) { common_Logger::d('do not handle permissions for action : ' . $action->getName() . ' ' . $action->getUrl()); } } //then compute ACL for each node of the tree $treeKeys = array_keys($tree); if (is_int($treeKeys[0])) { foreach ($tree as $index => $treeNode) { $tree[$index] = $this->computePermissions($actions, $user, $treeNode); } } else { $tree = $this->computePermissions($actions, $user, $tree); } return $tree; }
/** * Get the sections of the current extension's structure * * @param string $shownExtension * @param string $shownStructure * @return array the sections */ private function getSections($shownExtension, $shownStructure) { $sections = array(); $user = common_Session_SessionManager::getSession()->getUser(); $structure = MenuService::getPerspective($shownExtension, $shownStructure); if (!is_null($structure)) { foreach ($structure->getChildren() as $section) { if (tao_models_classes_accessControl_AclProxy::hasAccess($section->getAction(), $section->getController(), $section->getExtensionId())) { foreach ($section->getActions() as $action) { $resolver = ActionResolver::getByControllerName($action->getController(), $action->getExtensionId()); if (!FuncProxy::accessPossible($user, $resolver->getController(), $action->getAction())) { $section->removeAction($action); } } $sections[] = $section; } } } return $sections; }
/** * Renders json data from the current ontology root class. * * The possible request parameters are the following: * * * labelFilter: A filter string to be used. The returned hierarchy will be a single root class, with children without class hierarchy. * * uniqueNode: A URI indicating the returned hiearchy will be a single class, with a single children corresponding to the URI. * * browse: * * hideInstances: * * chunk: * * offset: * * limit: * * subclasses: * * classUri: * * @return void */ public function getOntologyData() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } $options = array('subclasses' => true, 'instances' => true, 'highlightUri' => '', 'labelFilter' => '', 'chunk' => false, 'offset' => 0, 'limit' => 0); if ($this->hasRequestParameter('filter')) { $options['labelFilter'] = $this->getRequestParameter('filter'); } if ($this->hasRequestParameter('loadNode')) { $options['uniqueNode'] = $this->getRequestParameter('loadNode'); } if ($this->hasRequestParameter("selected")) { $options['browse'] = array($this->getRequestParameter("selected")); } if ($this->hasRequestParameter('hideInstances')) { if ((bool) $this->getRequestParameter('hideInstances')) { $options['instances'] = false; } } if ($this->hasRequestParameter('classUri')) { $clazz = $this->getCurrentClass(); $options['chunk'] = !$clazz->equals($this->getRootClass()); } else { $clazz = $this->getRootClass(); } if ($this->hasRequestParameter('offset')) { $options['offset'] = $this->getRequestParameter('offset'); } if ($this->hasRequestParameter('limit')) { $options['limit'] = $this->getRequestParameter('limit'); } if ($this->hasRequestParameter('subclasses')) { $options['subclasses'] = $this->getRequestParameter('subclasses'); } //generate the tree from the given parameters $tree = $this->service->toTree($clazz, $options); //load the user URI from the session $user = common_Session_SessionManager::getSession()->getUser(); //Get the requested section $section = MenuService::getSection($this->getRequestParameter('extension'), $this->getRequestParameter('perspective'), $this->getRequestParameter('section')); //Get the actions from the section and bind them an ActionResolver that helps getting controller/action from action URL. $actions = array(); foreach ($section->getActions() as $index => $action) { try { $actions[$index] = array('resolver' => new ActionResolver($action->getUrl()), 'id' => $action->getId(), 'context' => $action->getContext()); } catch (\ResolverException $re) { common_Logger::d('do not handle permissions for action : ' . $action->getName() . ' ' . $action->getUrl()); } } //then compute ACL for each node of the tree $treeKeys = array_keys($tree); if (is_int($treeKeys[0])) { foreach ($tree as $index => $treeNode) { $tree[$index] = $this->computePermissions($actions, $user, $treeNode); } } else { $tree = $this->computePermissions($actions, $user, $tree); } //expose the tree $this->returnJson($tree); }