Skip to content

Commit

Permalink
fixing bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Sep 30, 2021
1 parent 36576b5 commit 0e4fbdd
Show file tree
Hide file tree
Showing 2 changed files with 109 additions and 60 deletions.
6 changes: 2 additions & 4 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ public function index() {
public function groupInfo() {
$name = urldecode($this->request->query['groupname']);

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));

$this->set('title', _txt('pl.grouperlite.title.groupinfo'));

try {
Expand All @@ -139,6 +137,7 @@ public function groupInfo() {
$this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
}

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
$this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.grouperUrl'));
}

Expand Down Expand Up @@ -752,11 +751,10 @@ private function breakoutGroups(array $recordSet, $type = 'basic') {
$wgRec['workingDesc'] = $this->hackDescription($rec['description']);
//Capturing record for incommon-collab since deleting a few lines below.
if ($rec['WGApp'] == 'incommon-collab') {
$recToDelete = $subCount;
if ($type == 'basic') {
//Removing record with stem of 'incommon-collab' since displaying on groups Member page,
// will show on Admin page
unset($wgRec['Groups'][$recToDelete]);
unset($wgRec['Groups'][$subCount]);
}
}
$subCount += 1;
Expand Down
163 changes: 107 additions & 56 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class GrouperGroup extends GrouperLiteAppModel
/** @var string Group whose members can create Groups via Template process */
private $templateCreationGroup = 'ref:workinggroupadmins';


private $wgStemsTopLevel = array(
'ref:incommon-collab'
);
Expand All @@ -61,9 +60,8 @@ class GrouperGroup extends GrouperLiteAppModel
'ref:incommon-collab'
);

private $emailStem ='app:sympa';


//Stem for email groups, only email groups using this stem are viewable
private $emailStem = 'app:sympa';

// Current listing of stems that are allowed to be viewed in Comanage as AdHoc groups
private $stemsAdHocAllowed = array(
Expand Down Expand Up @@ -109,7 +107,6 @@ public function isUserOwner(string $userId) {
}
}


/**
* Used to instantiate API class
*
Expand All @@ -124,18 +121,33 @@ private function initApi() {
}
}

/**
* Listing of members in an email group
*
* @param array $conditions Listing of conditions for display of records, including UserId
* @return array List of members that belong to email group
* @throws GrouperLiteException
*
*/
public function filteredMemberOfEmails(array $conditions) {
$this->initApi();

$memberOfEmails = $this->filteredMemberOfGroups($conditions);
try {
$memberOfEmails = $this->filteredMemberOfGroups($conditions);

// Strip out all Groups that are not in app:sympa Stem/Directory
foreach ($memberOfEmails as $key => $value) {
if (strpos(strtolower($value['name']), $this->emailStem) === false) {
unset($memberOfEmails[$key]);
// Strip out all Groups that are not in app:sympa Stem/Directory
foreach ($memberOfEmails as $key => $value) {
if (strpos(strtolower($value['name']), $this->emailStem) === false) {
unset($memberOfEmails[$key]);
}
}
return array_values($memberOfEmails);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

return array_values($memberOfEmails);
}

/**
Expand Down Expand Up @@ -201,7 +213,7 @@ private function memberOfGroups(array $conditions) {
* Gets the Grouper Groups params and values as well as its associated attributes.
*
* @param string $groupName Name of Group, do not confuse with DisplayName field!
* @return array An set of attributes associated to a specific Grouper Group
* @return array A set of attributes associated to a specific Grouper Group
* @throws GrouperLiteException
*/
public function groupDescriptions(string $groupName) {
Expand Down Expand Up @@ -328,17 +340,34 @@ public function membersInGroup(array $conditions) {
}
}

/**
* List of Email Groups a user can opt into.
*
* @param array $conditions Listing of conditions for display of records, including UserId
* @return array Listing of Optin email groups available in Groupe
* @throws GrouperLiteException Captured in Controller
*
*/
public function optinEmailGroups(array $conditions) {
$allGroups = $this->optinGroups($conditions);
$this->initApi();

try {
$allGroups = $this->optinGroups($conditions);

// Strip out all Groups that are not in Sympa Stem/Directory
foreach ($allGroups as $key => $value) {
if (strpos($value['name'], $this->emailStem) === false) {
unset($allGroups[$key]);
// Strip out all Groups that are not in Sympa Stem/Directory
foreach ($allGroups as $key => $value) {
if (strpos($value['name'], $this->emailStem) === false) {
unset($allGroups[$key]);
}
}

return array_values($allGroups);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

return array_values($allGroups);
}

/**
Expand Down Expand Up @@ -598,23 +627,64 @@ public function getSearchedGroups(array $conditions) {
*
* @param array $conditions Listing of conditions for display of records with pagination
* @return array Records requested by user with pagination support
* @throws Exception Captured in Controller
*
*/
public function paginate($conditions) {
try {
//Pull out the method that should be run.
$method = $conditions['method'];

//Pull out the method that should be run.
$method = $conditions['method'];
$resultSet = $this->$method($conditions);

$resultSet = $this->$method($conditions);
if (isset($conditions['emailonly']) && $conditions['emailonly']) {
if ($method == 'getSearchedGroups' || $method == 'filteredMemberOfEmails') {
$friendlyResults = $this->getFriendlyEmailName($resultSet, 'member');
} else {
$friendlyResults = $this->getFriendlyEmailName($resultSet, '');
}

if (isset($conditions['emailonly']) && $conditions['emailonly']) {
$friendlyResults = $this->getFriendlyEmailName($resultSet);
} else {
$friendlyResults = $this->getFriendlyWorkingGroupName($resultSet);
} else {
if ($method == 'getSearchedGroups' || $method == 'filteredMemberOfGroups') {
$friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, 'member');
} else {
$friendlyResults = $this->getFriendlyWorkingGroupName($resultSet, '');
}
}

return $this->paginateRecords($friendlyResults, $conditions);
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

}

private function getFriendlyEmailName(array $groups, $method) {

return $this->paginateRecords($friendlyResults, $conditions);
$arrayIndex = 0;
foreach ($groups as &$group) {
$appName = '';
if ($method == 'member') {
if ($group['extension'] == 'admins' || $group['extension'] == 'owners') {
unset($groups[$arrayIndex]);
}
}
$stems = explode(':', $group['name']);
$sectionCount = count($stems) - 2;
$groupName = $stems[$sectionCount];
$domain = $stems[2];
if (strtolower($domain) == 'incommon') {
$address = $groupName . '@lists.incommon.org';
} elseif (strtolower($domain) == 'internet2') {
$address = $groupName . '@lists.internet2.edu';
} else {
$address = $groupName . '@lists.' . strtolower($domain) . '.org';
}
$group['friendlyEmail'] = $address;
$arrayIndex += 1;
}
return $groups;
}

/**
Expand All @@ -629,7 +699,7 @@ public function paginate($conditions) {
* @return array Listing of Groups in WG format for display
*
*/
private function getFriendlyWorkingGroupName(array $groups) {
private function getFriendlyWorkingGroupName(array $groups, $method) {

$arrayIndex = 0;

Expand All @@ -642,8 +712,8 @@ private function getFriendlyWorkingGroupName(array $groups) {
$stemSections = explode(':', $group['name']);
//Get second to last stem section
$sectionCount = count($stemSections) - 2;
if (in_array($stemSections[$sectionCount], $topLevelWG) === false){
$topLevelWG[] = $stemSections[$sectionCount];
if (in_array($stemSections[$sectionCount], $topLevelWG) === false) {
$topLevelWG[] = $stemSections[$sectionCount];
}
}
}
Expand All @@ -659,7 +729,7 @@ private function getFriendlyWorkingGroupName(array $groups) {
//Get second to last stem section
$sectionCount = count($stemSections) - 2;
//If group not part of a top level WG, then do not show!
if (in_array($stemSections[$sectionCount], $topLevelWG) === false){
if (in_array($stemSections[$sectionCount], $topLevelWG) === false) {
break;
}
$group['WGName'] = $stemSections[$sectionCount];
Expand Down Expand Up @@ -694,11 +764,13 @@ private function getFriendlyWorkingGroupName(array $groups) {

}
$group['WGApp'] = $appName;
//TODO - FOR DEMO PURPOSE THAT LEAVES OUT ADMIN GROUPS TO SHOW WHAT AVERAGE USER SEES
// if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') {
// $workingGroups[] = $group;
// }
$workingGroups[] = $group;
if ($method == 'member') {
if ($group['WGRole'] !== 'admins' && $group['WGRole'] !== 'owners') {
$workingGroups[] = $group;
}
} else {
$workingGroups[] = $group;
}
unset($groups[$arrayIndex]);
}
}
Expand Down Expand Up @@ -736,27 +808,6 @@ private function getFriendlyWorkingGroupName(array $groups) {
return $finalWorkingGroups;
}

private function getFriendlyEmailName(array $groups) {

foreach($groups as &$group) {
$appCount = 0;
$appName = '';
$stems = explode(':', $group['name']);
$sectionCount = count($stems) - 2;
$groupName = $stems[$sectionCount];
$domain = $stems[2];
if (strtolower($domain) == 'incommon') {
$address = $groupName . '@lists.incommon.org';
} elseif (strtolower($domain) == 'internet2') {
$address = $groupName . '@lists.internet2.edu';
} else {
$address = $groupName . '@lists.' . strtolower($domain) . '.org';
}
$group['friendlyEmail'] = $address;
}
return $groups;
}

/**
* Verify that the AdHoc groups are only coming from stems listed in $stemsAdHocAllowed
*
Expand Down

0 comments on commit 0e4fbdd

Please sign in to comment.