diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 091e994..00edecf 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -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; @@ -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 * @@ -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); @@ -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) @@ -318,7 +357,7 @@ private function useMembershipUrl(array $queryData) { //Build request logic $groupsToShow = array( "WsRestGetMembershipsRequest" => array( - "fieldName" => $fieldName, + "fieldName" => $groupType, "wsSubjectLookups" => array( array("subjectId" => $subjectId) ) @@ -326,7 +365,6 @@ private function useMembershipUrl(array $queryData) { ); } - $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); $connectionUrl = "{$this->config['fullUrl']}/memberships"; diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 86f5e41..52bd180 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -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. @@ -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);