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

Commit 8c15ca0

Browse files
Merge pull request #55 from BaranekD/CodeOptimalization
Code optimalization
2 parents a092299 + 356c663 commit 8c15ca0

2 files changed

Lines changed: 25 additions & 40 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ All notable changes to this project will be documented in this file.
4343
- sspmod_perun_LdapConnector to SimpleSAML\Module\perun\LdapConnector
4444
- sspmod_perun_RpcConnector to SimpleSAML\Module\perun\RpcConnector
4545
- Added disco-tpl template file
46+
- Method getUsersGroupsOnFacility in AdapterRpc was optimized
4647

4748
[Fixed]
4849
- Fixed the bug generating Array to string conversion Exception in PerunAttributes,

lib/AdapterRpc.php

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -289,61 +289,45 @@ public function getFacilityAttribute($facility, $attrName)
289289
return $perunAttr['value'];
290290
}
291291

292+
292293
public function getUsersGroupsOnFacility($spEntityId, $userId)
293294
{
294295
$facilities = $this->connector->get('facilitiesManager', 'getFacilitiesByAttribute', array(
295296
'attributeName' => 'urn:perun:facility:attribute-def:def:entityID',
296297
'attributeValue' => $spEntityId,
297298
));
298299

299-
$allowedResources = array();
300-
foreach ($facilities as $facility) {
301-
$resources = $this->connector->get('facilitiesManager', 'getAssignedResources', array(
302-
'facility' => $facility['id'],
303-
));
304-
$allowedResources = array_merge($allowedResources, $resources);
305-
}
300+
$groups = array();
306301

307-
$members = $this->connector->get('membersManager', 'getMembersByUser', array(
308-
'user' => $userId,
309-
));
302+
foreach ($facilities as $facility) {
303+
$usersGroupsOnFacility = $this->connector->get(
304+
'usersManager',
305+
'getRichGroupsWhereUserIsActive',
306+
array(
307+
'facility' => $facility['id'],
308+
'user' => $userId,
309+
'attrNames' => array('urn:perun:group:attribute-def:virt:voShortName')
310+
)
311+
);
310312

311-
$validMembers = array();
312-
foreach ($members as $member) {
313-
if ($member['status'] === 'VALID') {
314-
array_push($validMembers, $member);
315-
}
316-
}
313+
foreach ($usersGroupsOnFacility as $usersGroupOnFacility) {
314+
if (isset($usersGroupOnFacility['attributes'][0]['friendlyName']) &&
315+
$usersGroupOnFacility['attributes'][0]['friendlyName'] == 'voShortName') {
316+
$uniqueName = $usersGroupOnFacility['attributes'][0]['value'] . ":" . $usersGroupOnFacility['name'];
317317

318-
$allGroups = array();
319-
foreach ($allowedResources as $resource) {
320-
foreach ($validMembers as $member) {
321-
$groups = $this->connector->get('resourcesManager', 'getAssignedGroups', array(
322-
'resource' => $resource['id'],
323-
'member' => $member['id'],
324-
));
325-
foreach ($groups as $group) {
326-
$attr = $this->connector->get('attributesManager', 'getAttribute', array(
327-
'group' => $group['id'],
328-
'attributeName' => 'urn:perun:group:attribute-def:virt:voShortName'
318+
array_push($groups, new Group(
319+
$usersGroupOnFacility['id'],
320+
$usersGroupOnFacility['voId'],
321+
$usersGroupOnFacility['name'],
322+
$uniqueName,
323+
$usersGroupOnFacility['description']
329324
));
330-
$uniqueName = $attr['value'] . ":" . $group['name'];
331-
array_push(
332-
$allGroups,
333-
new Group(
334-
$group['id'],
335-
$group['voId'],
336-
$group['name'],
337-
$uniqueName,
338-
$group['description']
339-
)
340-
);
341325
}
342326
}
343327
}
328+
$groups = $this->removeDuplicateEntities($groups);
344329

345-
$allGroups = $this->removeDuplicateEntities($allGroups);
346-
return $allGroups;
330+
return $groups;
347331
}
348332

349333
public function getFacilitiesByEntityId($spEntityId)

0 commit comments

Comments
 (0)