Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ModuleAccessService | |
0.00% |
0 / 28 |
|
0.00% |
0 / 2 |
56 | |
0.00% |
0 / 1 |
| add | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| remove | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
30 | |||
| 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_Logger; |
| 24 | use core_kernel_classes_Class; |
| 25 | use core_kernel_classes_Property; |
| 26 | use core_kernel_classes_Resource; |
| 27 | use oat\funcAcl\helpers\CacheHelper; |
| 28 | use oat\funcAcl\helpers\ModelHelper; |
| 29 | use oat\funcAcl\models\event\AccessRightAddedEvent; |
| 30 | use oat\funcAcl\models\event\AccessRightRemovedEvent; |
| 31 | |
| 32 | /** |
| 33 | * access operation for modules |
| 34 | * |
| 35 | * @access public |
| 36 | * |
| 37 | * @author Jehan Bihin |
| 38 | * |
| 39 | * @package tao |
| 40 | * |
| 41 | * @since 2.2 |
| 42 | */ |
| 43 | class ModuleAccessService extends AccessService |
| 44 | { |
| 45 | /** |
| 46 | * Short description of method add |
| 47 | * |
| 48 | * @access public |
| 49 | * |
| 50 | * @author Jehan Bihin, <jehan.bihin@tudor.lu> |
| 51 | * |
| 52 | * @param string $roleUri |
| 53 | * @param string $accessUri |
| 54 | * |
| 55 | * @return mixed |
| 56 | */ |
| 57 | public function add($roleUri, $accessUri) |
| 58 | { |
| 59 | $module = new core_kernel_classes_Resource($accessUri); |
| 60 | $role = new core_kernel_classes_Resource($roleUri); |
| 61 | $moduleAccessProperty = new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS); |
| 62 | |
| 63 | $values = $role->getPropertyValues($moduleAccessProperty); |
| 64 | |
| 65 | if (!in_array($module->getUri(), $values)) { |
| 66 | $role->setPropertyValue($moduleAccessProperty, $module->getUri()); |
| 67 | $this->getEventManager()->trigger(new AccessRightAddedEvent($roleUri, $accessUri)); |
| 68 | CacheHelper::cacheModule($module); |
| 69 | } else { |
| 70 | common_Logger::w('Tried to add role ' . $role->getUri() . ' again to controller ' . $accessUri); |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Short description of method remove |
| 76 | * |
| 77 | * @access public |
| 78 | * |
| 79 | * @author Jehan Bihin, <jehan.bihin@tudor.lu> |
| 80 | * |
| 81 | * @param string $roleUri |
| 82 | * @param string $accessUri |
| 83 | * |
| 84 | * @return mixed |
| 85 | */ |
| 86 | public function remove($roleUri, $accessUri) |
| 87 | { |
| 88 | $module = new core_kernel_classes_Resource($accessUri); |
| 89 | $role = new core_kernel_classes_Class($roleUri); |
| 90 | $accessProperty = new core_kernel_classes_Property(static::PROPERTY_ACL_GRANTACCESS); |
| 91 | |
| 92 | // Retrieve the module ID. |
| 93 | $uri = explode('#', $module->getUri()); |
| 94 | list($type, $extId, $modId) = explode('_', $uri[1]); |
| 95 | |
| 96 | // access via extension? |
| 97 | $extAccess = CacheHelper::getExtensionAccess($extId); |
| 98 | |
| 99 | if (in_array($roleUri, $extAccess)) { |
| 100 | // remove access to extension |
| 101 | $extUri = $this->makeEMAUri($extId); |
| 102 | ExtensionAccessService::singleton()->remove($roleUri, $extUri); |
| 103 | |
| 104 | // add access to all other controllers |
| 105 | foreach (ModelHelper::getModules($extId) as $eModule) { |
| 106 | if (!$module->equals($eModule)) { |
| 107 | $this->add($roleUri, $eModule->getUri()); |
| 108 | $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $eModule->getUri())); |
| 109 | //$role->setPropertyValue($accessProperty, $eModule->getUri()); |
| 110 | } |
| 111 | } |
| 112 | //CacheHelper::flushExtensionAccess($extId); |
| 113 | } |
| 114 | |
| 115 | // Remove the access to the module for this role. |
| 116 | $role->removePropertyValue($accessProperty, $module->getUri()); |
| 117 | |
| 118 | $this->getEventManager()->trigger(new AccessRightRemovedEvent($roleUri, $accessUri)); |
| 119 | |
| 120 | CacheHelper::cacheModule($module); |
| 121 | |
| 122 | // Remove the access to the actions corresponding to the module for this role. |
| 123 | foreach (ModelHelper::getActions($module) as $actionResource) { |
| 124 | ActionAccessService::singleton()->remove($role->getUri(), $actionResource->getUri()); |
| 125 | } |
| 126 | |
| 127 | CacheHelper::cacheModule($module); |
| 128 | } |
| 129 | } |