Skip to content

Commit

Permalink
ICPCO-168
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Oct 1, 2021
1 parent 0e4fbdd commit 4a3e1fc
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 21 deletions.
76 changes: 57 additions & 19 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -192,14 +192,27 @@ public function getOptionalGroups(array $queryData) {
*
*/
public function getOwnedGroups(array $queryData) {
$queryData['groupType'] = 'Owner';

try {
$results = $this->useMembershipUrl($queryData);
$queryData['groupType'] = 'admin';
$resultsAdmin = $this->useMembershipUrl($queryData);

if (isset($results['WsGetMembershipsResults']['wsGroups']) && $results['WsGetMembershipsResults']['wsGroups'] != NULL) {
return $results['WsGetMembershipsResults']['wsGroups'];
$queryData['groupType'] = 'update';
$resultsUpdate = $this->useMembershipUrl($queryData);

if (isset($resultsAdmin['WsGetMembershipsResults']['wsGroups']) && $resultsAdmin['WsGetMembershipsResults']['wsGroups'] != NULL) {
$admins = $resultsAdmin['WsGetMembershipsResults']['wsGroups'];
} else {
$admins = array();
}

if (isset($resultsUpdate['WsGetMembershipsResults']['wsGroups']) && $resultsUpdate['WsGetMembershipsResults']['wsGroups'] != NULL) {
$updaters = $resultsUpdate['WsGetMembershipsResults']['wsGroups'];
} else {
$updaters = array();
}

return $this->removeDuplicates($admins, $updaters);
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
Expand All @@ -208,6 +221,40 @@ public function getOwnedGroups(array $queryData) {
}


/**
* Currently not being used, but would be needed if Bill K does not want to show a group where
* the user is the admin and the updater.
*
* @param array $arrOne
* @param array $arrTwo
* @return array
*/
public function removeDuplicates(array $arrOne, array $arrTwo) {

//Determine which array is bigger and use as base
$countOne = count($arrOne);
$countTwo = count($arrTwo);
if($countOne >= $countTwo) {
$arrL = $arrOne;
$arrS = $arrTwo;
} else {
$arrL = $arrTwo;
$arrS = $arrOne;
}

foreach ($arrL as $large) {
foreach ($arrS as $key => $val) {
if ($large['uuid'] == $val['uuid']) {
unset($arrS[$key]);
}
}
}

$results = array_merge_recursive($arrL, $arrS);
return $results;
}


/**
* Get members associated to a specific Grouper Group
*
Expand Down Expand Up @@ -255,7 +302,7 @@ public function getMembersInGroup(array $queryData) {
* @throws GrouperLiteException
*/
public function getOwnedStems(array $queryData) {
$queryData['groupType'] = 'StemOwner';
$queryData['groupType'] = 'stemAdmin';

try {
$results = $this->useMembershipUrl($queryData);
Expand Down Expand Up @@ -286,28 +333,20 @@ private function useMembershipUrl(array $queryData) {
$groupType = $queryData['groupType'];
$userId = $queryData['userId'];

if ($groupType == 'Optins') {
$fieldName = "optins";
if ($groupType == 'optins' || $groupType == 'optouts') {
$subjectId = "GrouperAll";
} elseif ($groupType == 'Optouts') {
$fieldName = "optouts";
$subjectId = "GrouperAll";
} elseif ($groupType == 'Owner') {
$fieldName = "admin";
$subjectId = $userId;
} elseif ($groupType == 'StemOwner') {
$fieldName = "stemAdmin";
} elseif ($groupType == 'admin' || $groupType == 'update' || $groupType == 'stemAdmin') {
$subjectId = $userId;
} else {
CakeLog::write('error', __METHOD__ . ": Option of $groupType is not supported");
throw new GrouperLiteException("Option of $groupType is not supported");
}

if ($groupType == 'Optins' || $groupType == 'Optouts') {
if ($groupType == 'optins' || $groupType == 'optouts') {
//Build request logic, 2 subjectId's, second is for when user in "Secret" Optin/Optout Group
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"fieldName" => $groupType,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId),
array("subjectId" => $userId)
Expand All @@ -318,15 +357,14 @@ private function useMembershipUrl(array $queryData) {
//Build request logic
$groupsToShow = array(
"WsRestGetMembershipsRequest" => array(
"fieldName" => $fieldName,
"fieldName" => $groupType,
"wsSubjectLookups" => array(
array("subjectId" => $subjectId)
)
)
);
}


$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
$connectionUrl = "{$this->config['fullUrl']}/memberships";

Expand Down
4 changes: 2 additions & 2 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public function filteredMemberOfGroups(array $conditions) {
$this->initApi();

try {
$conditions['groupType'] = 'Optouts';
$conditions['groupType'] = 'optouts';
$memberOfGroups = $this->memberOfGroups($conditions);

// Determine which groups can be left by user, if want.
Expand Down Expand Up @@ -383,7 +383,7 @@ public function optinGroups(array $conditions) {
$this->initApi();

try {
$conditions['groupType'] = 'Optins';
$conditions['groupType'] = 'optins';

$joinOrLeave = $this->grouperAPI->getOptionalGroups($conditions);
$userGroups = $this->memberOfGroups($conditions);
Expand Down

0 comments on commit 4a3e1fc

Please sign in to comment.