Skip to content
This repository was archived by the owner on Sep 19, 2022. It is now read-only.

Commit 6e6f431

Browse files
vyskocilpavelpajavyskocil
authored andcommitted
Fix the AdapterRpc
* Completed the method isUserOnFacility for connection to Perun via RPC.
1 parent 119d7d4 commit 6e6f431

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

lib/AdapterRpc.php

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* Class sspmod_perun_AdapterRpc
55
*
66
* Perun adapter which uses Perun RPC interface
7+
* @author Michal Prochazka <[email protected]>
8+
* @author Pavel Vyskocil <[email protected]>
79
*/
810
class sspmod_perun_AdapterRpc extends sspmod_perun_Adapter
911
{
@@ -154,7 +156,45 @@ public function getUserAttributes($user, $attrNames)
154156

155157
public function isUserOnFacility($spEntityId, $userId)
156158
{
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;
158198
}
159199

160200
}

0 commit comments

Comments
 (0)