|
4 | 4 | * Class sspmod_perun_AdapterRpc |
5 | 5 | * |
6 | 6 | * Perun adapter which uses Perun RPC interface |
| 7 | + * @author Michal Prochazka <[email protected]> |
| 8 | + * @author Pavel Vyskocil <[email protected]> |
7 | 9 | */ |
8 | 10 | class sspmod_perun_AdapterRpc extends sspmod_perun_Adapter |
9 | 11 | { |
@@ -154,7 +156,45 @@ public function getUserAttributes($user, $attrNames) |
154 | 156 |
|
155 | 157 | public function isUserOnFacility($spEntityId, $userId) |
156 | 158 | { |
157 | | - throw new BadMethodCallException("NotImplementedException"); |
| 159 | + $facilities = sspmod_perun_RpcConnector::get('facilitiesManager', 'getFacilitiesByAttribute', array( |
| 160 | + 'attributeName' => 'urn:perun:facility:attribute-def:def:entityID', |
| 161 | + 'attributeValue' => $spEntityId, |
| 162 | + )); |
| 163 | + |
| 164 | + $allowedResources = array(); |
| 165 | + foreach ($facilities as $facility) { |
| 166 | + $resources = sspmod_perun_RpcConnector::get('facilitiesManager', 'getAssignedResources', array( |
| 167 | + 'facility' => $facility['id'], |
| 168 | + )); |
| 169 | + $allowedResources = array_merge($allowedResources, $resources); |
| 170 | + } |
| 171 | + |
| 172 | + $members = sspmod_perun_RpcConnector::get('membersManager', 'getMembersByUser', array( |
| 173 | + 'user' => $userId, |
| 174 | + )); |
| 175 | + |
| 176 | + $validMembers = array(); |
| 177 | + foreach ($members as $member) { |
| 178 | + if ($member['status'] === 'VALID') { |
| 179 | + array_push($validMembers, $member); |
| 180 | + } |
| 181 | + } |
| 182 | + |
| 183 | + $allGroups = array(); |
| 184 | + foreach ($allowedResources as $resource) { |
| 185 | + foreach ($validMembers as $member) { |
| 186 | + $groups = sspmod_perun_RpcConnector::get('resourcesManager', 'getAssignedGroups', array( |
| 187 | + 'resource' => $resource['id'], |
| 188 | + 'member' => $member['id'], |
| 189 | + )); |
| 190 | + foreach ($groups as $group) { |
| 191 | + array_push($allGroups, new sspmod_perun_model_Group($group['id'], $group['name'], $group['description'])); |
| 192 | + } |
| 193 | + } |
| 194 | + } |
| 195 | + |
| 196 | + $allGroups = $this->removeDuplicateEntities($allGroups); |
| 197 | + return $allGroups; |
158 | 198 | } |
159 | 199 |
|
160 | 200 | } |
0 commit comments