Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ExtensionAccessService | |
0.00% |
0 / 31 |
|
0.00% |
0 / 2 |
30 | |
0.00% |
0 / 1 |
| add | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
6 | |||
| remove | |
0.00% |
0 / 20 |
|
0.00% |
0 / 1 |
12 | |||
| 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) 2009-2012 (original work) Public Research Centre Henri Tudor (under the project TAO-SUSTAIN & TAO-DEV); |
| 19 | */ |
| 20 | |
| 21 | namespace oat\funcAcl\models; |
| 22 | |
| 23 | use common_ext_ExtensionsManager; |
| 24 | use common_Logger; |
| 25 | use core_kernel_classes_Property; |
| 26 | use core_kernel_classes_Resource; |
| 27 | use oat\funcAcl\helpers\CacheHelper; |
| 28 | use oat\funcAcl\models\event\AccessRightAddedEvent; |
| 29 | use oat\funcAcl\models\event\AccessRightRemovedEvent; |
| 30 | |
| 31 | /** |
| 32 | * access operation for extensions |
| 33 | * |
| 34 | * @access public |
| 35 | * |
| 36 | * @author Jehan Bihin |
| 37 | * |
| 38 | * @package tao |
| 39 | * |
| 40 | * @since 2.2 |
| 41 | */ |
| 42 | class ExtensionAccessService extends AccessService |
| 43 | { |
| 44 | // --- ASSOCIATIONS --- |
| 45 | |
| 46 | // --- ATTRIBUTES --- |
| 47 | |
| 48 | // --- OPERATIONS --- |
| 49 | |
| 50 | /** |
| 51 | * Short description of method add |
| 52 | * |
| 53 | * @access public |
| 54 | * |
| 55 | * @author Jehan Bihin, <jehan.bihin@tudor.lu> |
| 56 | * |
| 57 | * @param string $roleUri |
| 58 | * @param string $accessUri |
| 59 | * |
| 60 | * @return mixed |
| 61 | */ |
| 62 | public function add($roleUri, $accessUri) |
| 63 | { |
| 64 | $uri = explode('#', $accessUri); |
| 65 | list($type, $extId) = explode('_', $uri[1]); |
| 66 | |
| 67 | $extManager = common_ext_ExtensionsManager::singleton(); |
| 68 | $extension = $extManager->getExtensionById($extId); |
| 69 | $role = new core_kernel_classes_Resource($roleUri); |
| 70 | |
| 71 | $values = $role->getPropertyValues(new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS)); |
| 72 | |
| 73 | if (!in_array($accessUri, $values)) { |
| 74 | $role->setPropertyValue(new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS), $accessUri); |
| 75 | $this->getEventManager()->trigger(new AccessRightAddedEvent($roleUri, $accessUri)); |
| 76 | CacheHelper::flushExtensionAccess($extId); |
| 77 | } else { |
| 78 | common_Logger::w('Tried to regrant access for role ' . $role->getUri() . ' to extension ' . $accessUri); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Short description of method remove |
| 84 | * |
| 85 | * @access public |
| 86 | * |
| 87 | * @author Jehan Bihin, <jehan.bihin@tudor.lu> |
| 88 | * |
| 89 | * @param string $roleUri |
| 90 | * @param string $accessUri |
| 91 | * |
| 92 | * @return mixed |
| 93 | */ |
| 94 | public function remove($roleUri, $accessUri) |
| 95 | { |
| 96 | $uri = explode('#', $accessUri); |
| 97 | list($type, $extId) = explode('_', $uri[1]); |
| 98 | |
| 99 | // Remove the access to the extension for this role. |
| 100 | $extManager = common_ext_ExtensionsManager::singleton(); |
| 101 | $extension = $extManager->getExtensionById($extId); |
| 102 | $role = new core_kernel_classes_Resource($roleUri); |
| 103 | |
| 104 | $role->removePropertyValues( |
| 105 | new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS), |
| 106 | ['pattern' => $accessUri] |
| 107 | ); |
| 108 | CacheHelper::flushExtensionAccess($extId); |
| 109 | |
| 110 | // also remove access to all the controllers |
| 111 | $moduleAccessProperty = new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS); |
| 112 | $moduleAccessService = ModuleAccessService::singleton(); |
| 113 | $grantedModules = $role->getPropertyValues($moduleAccessProperty); |
| 114 | |
| 115 | foreach ($grantedModules as $gM) { |
| 116 | $gM = new core_kernel_classes_Resource($gM); |
| 117 | $uri = explode('#', $gM->getUri()); |
| 118 | list($type, $ext) = explode('_', $uri[1]); |
| 119 | |
| 120 | if ($extId == $ext) { |
| 121 | $moduleAccessService->remove($role->getUri(), $gM->getUri()); |
| 122 | $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $accessUri)); |
| 123 | } |
| 124 | } |
| 125 | } |
| 126 | } |