Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| FuncAclInitialisation | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
110 | |
0.00% |
0 / 1 |
| run | |
0.00% |
0 / 27 |
|
0.00% |
0 / 1 |
110 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU General Public License |
| 15 | * along with this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2013 (original work) Open Assessment Technologies SA (under the project TAO-PRODUCT); |
| 19 | */ |
| 20 | |
| 21 | namespace oat\funcAcl\models; |
| 22 | |
| 23 | use common_ext_ExtensionsManager; |
| 24 | use common_Logger; |
| 25 | use core_kernel_classes_Class; |
| 26 | use core_kernel_classes_Property; |
| 27 | use oat\tao\model\TaoOntology; |
| 28 | |
| 29 | /** |
| 30 | * Initialise the FuncAcl Model |
| 31 | * |
| 32 | * @access public |
| 33 | * |
| 34 | * @author Joel Bout, <joel@taotesting.com> |
| 35 | * |
| 36 | * @package tao |
| 37 | */ |
| 38 | class FuncAclInitialisation |
| 39 | { |
| 40 | public static function run() |
| 41 | { |
| 42 | // We get all the management roles and the extension they belong to. |
| 43 | $managementRoleClass = new core_kernel_classes_Class(TaoOntology::CLASS_URI_MANAGEMENT_ROLE); |
| 44 | $foundManagementRoles = $managementRoleClass->getInstances(true); |
| 45 | $managementRolesByExtension = []; |
| 46 | |
| 47 | foreach (common_ext_ExtensionsManager::singleton()->getInstalledExtensions() as $extension) { |
| 48 | $managementRole = $extension->getManagementRole(); |
| 49 | |
| 50 | if (empty($managementRole)) { |
| 51 | // try to discover it. |
| 52 | foreach ($foundManagementRoles as $mR) { |
| 53 | $moduleURIs = $mR->getPropertyValues( |
| 54 | new core_kernel_classes_Property(AccessService::PROPERTY_ACL_GRANTACCESS) |
| 55 | ); |
| 56 | |
| 57 | foreach ($moduleURIs as $moduleURI) { |
| 58 | $uri = explode('#', $moduleURI); |
| 59 | list($type, $extId) = explode('_', $uri[1]); |
| 60 | |
| 61 | if ($extId == $extension->getId()) { |
| 62 | $managementRole = $mR; |
| 63 | |
| 64 | break 2; |
| 65 | } |
| 66 | } |
| 67 | } |
| 68 | } |
| 69 | |
| 70 | if (!empty($managementRole)) { |
| 71 | $managementRolesByExtension[$extension->getId()] = $managementRole; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | foreach (common_ext_ExtensionsManager::singleton()->getInstalledExtensions() as $extension) { |
| 76 | if ($extension->getId() != 'generis') { |
| 77 | // 2. Grant access to Management Role. |
| 78 | if (!empty($managementRolesByExtension[$extension->getId()])) { |
| 79 | $extAccessService = ExtensionAccessService::singleton(); |
| 80 | $extAccessService->add( |
| 81 | $managementRolesByExtension[$extension->getId()]->getUri(), |
| 82 | $extAccessService->makeEMAUri($extension->getId()) |
| 83 | ); |
| 84 | } else { |
| 85 | common_Logger::i('Management Role not found for extension ' . $extension->getId()); |
| 86 | } |
| 87 | } |
| 88 | } |
| 89 | } |
| 90 | } |