/** * @param \SimpleXMLElement $node * @param $structureExtensionId extension of structures.xml * @return static */ public static function fromSimpleXMLElement(\SimpleXMLElement $node, $structureExtensionId) { $url = isset($node['url']) ? (string) $node['url'] : '#'; if ($url == '#' || empty($url)) { $extension = null; $controller = null; $action = null; } else { $parts = explode('/', trim($url, '/')); $parts = array_replace(array_fill(0, 3, null), $parts); list($extension, $controller, $action) = $parts; } $data = array('id' => (string) $node['id'], 'name' => (string) $node['name'], 'url' => $url, 'extension' => $extension, 'controller' => $controller, 'action' => $action, 'binding' => isset($node['binding']) ? (string) $node['binding'] : null, 'policy' => isset($node['policy']) ? (string) $node['policy'] : self::POLICY_MERGE, 'disabled' => isset($node['disabled']) ? true : false); $trees = array(); foreach ($node->xpath("trees/tree") as $treeNode) { $trees[] = Tree::fromSimpleXMLElement($treeNode, $structureExtensionId); } $actions = array(); foreach ($node->xpath("actions/action") as $actionNode) { $actions[] = Action::fromSimpleXMLElement($actionNode, $structureExtensionId); } $includeClassActions = isset($node->actions) && isset($node->actions['allowClassActions']) && $node->actions['allowClassActions'] == 'true'; if ($includeClassActions) { foreach ($trees as $tree) { $rootNodeUri = $tree->get('rootNode'); if (!empty($rootNodeUri)) { $rootNode = new \core_kernel_classes_Class($rootNodeUri); foreach (ClassActionRegistry::getRegistry()->getClassActions($rootNode) as $action) { $actions[] = $action; } } } } return new static($data, $trees, $actions); }
/** * * @param string $currentVersion * @return string $versionUpdatedTo */ public function update($initialVersion) { $currentVersion = $initialVersion; if ($currentVersion == '1.0') { $impl = new PermissionProvider(); // add read access to Items $class = new \core_kernel_classes_Class(TAO_ITEM_CLASS); AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, array('READ')); // add backoffice user rights to Tests $class = new \core_kernel_classes_Class(TAO_TEST_CLASS); AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, $impl->getSupportedRights()); $currentVersion = '1.0.1'; } if ($currentVersion == '1.0.1') { $currentVersion = '1.0.2'; } if ($currentVersion == '1.0.2') { $taoClass = new \core_kernel_classes_Class(TAO_OBJECT_CLASS); $classAdmin = new AdminAction(); ClassActionRegistry::getRegistry()->registerAction($taoClass, $classAdmin); $currentVersion = '1.1'; } if ($currentVersion == '1.1') { $classesToAdd = array(new \core_kernel_classes_Class(CLASS_GENERIS_USER), new \core_kernel_classes_Class(CLASS_ROLE)); // add admin to new instances $classAdmin = new AdminAction(); foreach ($classesToAdd as $class) { ClassActionRegistry::getRegistry()->registerAction($class, $classAdmin); } // add base permissions to new classes $taoClass = new \core_kernel_classes_Class(TAO_OBJECT_CLASS); foreach ($taoClass->getSubClasses(false) as $class) { if (!in_array($class->getUri(), array(TAO_ITEM_CLASS, TAO_TEST_CLASS))) { $classesToAdd[] = $class; } } $rights = PermissionManager::getPermissionModel()->getSupportedRights(); foreach ($classesToAdd as $class) { if (count(AdminService::getUsersPermissions($class->getUri())) == 0) { AdminService::addPermissionToClass($class, INSTANCE_ROLE_BACKOFFICE, $rights); } else { \common_Logger::w('Unexpected rights present for ' . $class->getUri()); } } $currentVersion = '1.2.0'; } return $currentVersion; }
<?php /** * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; under version 2 * of the License (non-upgradable). * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); * * */ use oat\taoBackOffice\model\menuStructure\ClassActionRegistry; use oat\taoDacSimple\model\PermissionProvider; use oat\taoDacSimple\model\action\AdminAction; $classAdmin = new AdminAction(); foreach (PermissionProvider::getSupportedRootClasses() as $class) { ClassActionRegistry::getRegistry()->registerAction($class, $classAdmin); }