Skip to content

Commit

Permalink
fixed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Apr 5, 2021
1 parent 29f352c commit c27d6a8
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
13 changes: 8 additions & 5 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
*
Expand All @@ -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;
Expand Down
16 changes: 10 additions & 6 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;
}
}
Expand All @@ -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
Expand Down Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions View/GrouperGroups/groupmember.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
) ?>" title="<?php echo $group['name']; ?>"><?php echo isset($group['friendlyName']) ? $group['friendlyName'] : "No Name"; ?></a></td>
<td><?php echo isset($group['description']) ? $group['description'] : _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td>
<?php echo $group['optedin'] ? $this->element('GrouperLite.Components/optAction', array(
'member' => $group['optedin'],
<?php echo $group['optOut'] ? $this->element('GrouperLite.Components/optAction', array(
'member' => $group['optOut'],
'action' => 'leavegroup',
'group' => $group['name']
)) : ''; ?>
Expand Down

0 comments on commit c27d6a8

Please sign in to comment.