diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 67fad1e..ee80616 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -203,17 +203,16 @@ public function grouperGroupLeaveOrJoin(array $queryData) { } /** - * Gets all available Optin groups in Grouper - * Checks to see which Optin groups the user is already a member of - * Returns Optin groups that can be joined and ones that the user is already joined + * Gets all available Optin/OptOut groups in Grouper + * + * Returns Optin/OptOut groups that can be joined/left * * @param array $queryData Array of conditions for querying * @return array Optin groups from Grouper * @throws GrouperLiteException * */ - public function getOptinGroups(array $queryData) { - $queryData['groupType'] = 'Optins'; + public function getOptionalGroups(array $queryData) { try { $results = $this->useMembershipUrl($queryData); @@ -319,6 +318,7 @@ public function getOwnedStems(array $queryData) { * Used for requests made to Membership endpoint in Grouper WS * * @see getOptinGroups() + * @see getOptOutGroups() * @see getOwnedGroups() * @see getOwnedStems() * @@ -333,6 +333,9 @@ private function useMembershipUrl(array $queryData) { if ($groupType == 'Optins') { $fieldName = "optins"; $subjectId = "GrouperAll"; + } elseif ($groupType == 'Optouts') { + $fieldName = "optouts"; + $subjectId = "GrouperAll"; } elseif ($groupType == 'Owner') { $fieldName = "admin"; $subjectId = $userId; diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index fb3c7f4..548cb2b 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -120,7 +120,7 @@ public function getGrouperUserId() { /** * Return all Groups that a User belongs to in Grouper. - * Will also add Optin Groups and flag them as joined so can display Optout option in UI. + * Will also add OptOut Groups and flag them as joined so can display Optout option in UI. * * @param array $conditions Listing of conditions for display of records, including UserId * @return array Records of Groups from Grouper that the User belongs to @@ -131,18 +131,19 @@ public function filteredMemberOfGroups(array $conditions) { $this->initApi(); try { + $conditions['groupType'] = 'Optouts'; $memberOfGroups = $this->memberOfGroups($conditions); // Determine which groups can be left by user, if want. - $optInGroups = $this->grouperAPI->getOptinGroups($conditions); + $optOutGroups = $this->grouperAPI->getOptionalGroups($conditions); foreach ($memberOfGroups as &$memberOfGroup) { - foreach ($optInGroups as $key => $value) { + foreach ($optOutGroups as $key => $value) { if ($value['name'] == $memberOfGroup['name']) { //Match! - $memberOfGroup['optedin'] = true; + $memberOfGroup['optOut'] = true; //Remove Optin group since already found and now less loops - unset($optInGroups[$key]); + unset($optOutGroups[$key]); break; } } @@ -157,6 +158,7 @@ public function filteredMemberOfGroups(array $conditions) { } public function filteredMemberOfEmails(array $conditions) { + $memberOfEmails = $this->filteredMemberOfGroups($conditions); // Strip out all Groups that are not in Sympa Stem/Directory @@ -364,7 +366,9 @@ public function optinGroups(array $conditions) { $this->initApi(); try { - $joinOrLeave = $this->grouperAPI->getOptinGroups($conditions); + $conditions['groupType'] = 'Optins'; + + $joinOrLeave = $this->grouperAPI->getOptionalGroups($conditions); $userGroups = $this->memberOfGroups($conditions); //See if Optin group match any of the groups user already belongs to. diff --git a/View/GrouperGroups/groupmember.ctp b/View/GrouperGroups/groupmember.ctp index 8e0c956..d4fb8b3 100644 --- a/View/GrouperGroups/groupmember.ctp +++ b/View/GrouperGroups/groupmember.ctp @@ -30,8 +30,8 @@ ) ?>" title=""> - element('GrouperLite.Components/optAction', array( - 'member' => $group['optedin'], + element('GrouperLite.Components/optAction', array( + 'member' => $group['optOut'], 'action' => 'leavegroup', 'group' => $group['name'] )) : ''; ?>