Skip to content

Commit

Permalink
changes for incommon
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Sep 24, 2021
1 parent 80c4aa6 commit 91441b7
Show file tree
Hide file tree
Showing 5 changed files with 118 additions and 59 deletions.
125 changes: 77 additions & 48 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,6 @@ function isAuthorized() {
$p['emaillistsoptin'] = true;
$p['emaillistsmember'] = true;
$p['emaillistsmanage'] = true;
$p['emaillistsinfo'] = true;
$p['groupcreate'] = true;
$p['groupdelete'] = true;
$p['joingroup'] = true;
Expand All @@ -546,55 +545,104 @@ public function emaillistsOptin() {
//Set initial settings for pagination
$scope = [
'userId' => $this->userId,
'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']),
'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']),
'page' => ($this->passedArgs['page'] ?? $this->paginate['page']),
'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']),
];

try {
//Add settings for optinEmailLists
$scope['method'] = 'optinEmailGroups';
if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('searchcriteria', $searchCriteria);

try {
//Add setting for Group Membership
$scope['method'] = 'getSearchedGroups';
$scope['searchcriteria'] = $searchCriteria;
$scope['searchpage'] = 'optinEmailGroups';
$scope['emailonly'] = true;

$data = $this->Paginator->paginate('GrouperGroup', $scope);
$this->set('emailgroups', $data);
$data = $this->Paginator->paginate('GrouperGroup', $scope);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
$this->set('emailgroups', $data);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true));

$this->Flash->set("Your Email Optin List cannot be found, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
}
} else {
try {
//Add setting for Group Membership
$scope['method'] = 'optinEmailGroups';
$scope['emailonly'] = true;

$data = $this->Paginator->paginate('GrouperGroup', $scope);

$this->set('emailgroups', $data);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true));

$this->Flash->set("An error occurred with the Optin Email Lists, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
}
}

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

//##############################################################################################################
//TODO - Need to finish off the email list pages, once we get direction from I2
//##############################################################################################################

public function emaillistsMember() {
$this->set('title', _txt('pl.grouperlite.title.emaillists-member'));

//Set initial settings for pagination
$scope = [
'userId' => $this->userId,
'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page'] : $this->paginate['page']),
'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit'] : $this->paginate['limit']),
'page' => ($this->passedArgs['page'] ?? $this->paginate['page']),
'limit' => ($this->passedArgs['limit'] ?? $this->paginate['limit']),
];

try {
//Add setting for Group Membership
$scope['method'] = 'filteredMemberOfEmails';
if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('searchcriteria', $searchCriteria);

$data = $this->Paginator->paginate('GrouperGroup', $scope);
$this->set('emailgroups', $data);
try {
//Add setting for Group Membership
$scope['method'] = 'getSearchedGroups';
$scope['searchcriteria'] = $searchCriteria;
$scope['searchpage'] = 'filteredMemberOfEmails';
$scope['emailonly'] = true;

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$data = $this->Paginator->paginate('GrouperGroup', $scope);

$this->set('emailgroups', $data);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true));

$this->Flash->set("Your Email Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
}
} else {
try {
//Add setting for Group Membership
$scope['method'] = 'filteredMemberOfEmails';
$scope['emailonly'] = true;

$data = $this->Paginator->paginate('GrouperGroup', $scope);

$this->set('emailgroups', $data);

$this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true));

$this->Flash->set("Your Email Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('emailgroups', array());
return;
}
}

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
Expand All @@ -616,25 +664,6 @@ public function emaillistsManage() {
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}

public function emaillistInfo() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsinfo'));
// mock data
$this->set('groupergroupsdetail', array(
'member' => true,
'domain' => 'internet2',
'uuid' => 'abc123xyz789',
'displayExtension' => 'email-list-1',
'extension' => 'email-list-1',
'displayName' => 'Email List 1',
'typeOfGroup' => 'list',
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T',
'attributes' => array()
));
$this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url'));

}

private function getUserId($id) {
$args = array();
Expand Down
3 changes: 2 additions & 1 deletion Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -144,5 +144,6 @@
'pl.grouperlite.pagination.counter' => 'Viewing {:start}-{:end} of {:count}',
'pl.grouperlite.attributes.zero-state' => 'No Attributes Associated to this Group.',
'pl.grouperlite.groups.zero-state' => 'No groups found.',
'pl.grouperlite.working-groups.zero-state' => 'No working groups found.'
'pl.grouperlite.working-groups.zero-state' => 'No working groups found.',
'pl.grouperlite.email-lists.zero-state' => 'No email lists found.'
);
37 changes: 33 additions & 4 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ class GrouperGroup extends GrouperLiteAppModel
'ref:incommon-collab'
);

private $emailStem ='app:sympa';



// Current listing of stems that are allowed to be viewed in Comanage as AdHoc groups
Expand Down Expand Up @@ -126,9 +128,9 @@ public function filteredMemberOfEmails(array $conditions) {

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

// Strip out all Groups that are not in Sympa Stem/Directory
// Strip out all Groups that are not in app:sympa Stem/Directory
foreach ($memberOfEmails as $key => $value) {
if (strpos($value['name'], 'sympa') === false) {
if (strpos(strtolower($value['name']), $this->emailStem) === false) {
unset($memberOfEmails[$key]);
}
}
Expand Down Expand Up @@ -331,7 +333,7 @@ public function optinEmailGroups(array $conditions) {

// Strip out all Groups that are not in Sympa Stem/Directory
foreach ($allGroups as $key => $value) {
if (strpos($value['name'], 'sympa') === false) {
if (strpos($value['name'], $this->emailStem) === false) {
unset($allGroups[$key]);
}
}
Expand Down Expand Up @@ -555,6 +557,7 @@ public function getOwnedStems(string $userId) {

/**
* Search for Groups/Lists related to Search term.
*
* Will import all records the user can see and then do search in this code rather than call Grouper WS Search
* functionality. This is due to the fact that the grouperName is autogenerated and this app needs to search
* attributes which the Grouper WS does not do.
Expand Down Expand Up @@ -604,7 +607,12 @@ public function paginate($conditions) {

$resultSet = $this->$method($conditions);

$friendlyResults = $this->getFriendlyWorkingGroupName($resultSet);
if (isset($conditions['emailonly']) && $conditions['emailonly']) {
$friendlyResults = $this->getFriendlyEmailName($resultSet);
} else {
$friendlyResults = $this->getFriendlyWorkingGroupName($resultSet);
}


return $this->paginateRecords($friendlyResults, $conditions);
}
Expand Down Expand Up @@ -728,6 +736,27 @@ 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
6 changes: 3 additions & 3 deletions View/GrouperGroups/emaillistsmember.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
<tr>
<td><?php echo $this->Html->link(

isset($group['name']) ? $group['domain'] . ':' . $group['name'] : "No Name",
$group['friendlyEmail'] ?? "No Name",
array(
'controller' => 'grouper_groups',
'action' => 'emaillistinfo',
'?' => array('groupname' => urlencode($group['name']))
)
) ?></td>
<td><?php echo isset($group['description']) ? $group['description'] : _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td><?php echo $group['description'] ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td>
<?php echo $group['optedin'] ? $this->element('GrouperLite.Components/optAction', array(
'member' => $group['optedin'],
Expand All @@ -48,6 +48,6 @@
<?php endif; ?>
<?php if (count($emailgroups) < 1) : ?>
<div class="alert alert-info">
<p class="lead mb-0 text-center"><?php echo _txt('pl.grouperlite.working-groups.zero-state'); ?></p>
<p class="lead mb-0 text-center"><?php echo _txt('pl.grouperlite.email-lists.zero-state'); ?></p>
</div>
<?php endif; ?>
6 changes: 3 additions & 3 deletions View/GrouperGroups/emaillistsoptin.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@
<?php foreach ($emailgroups as $group) : ?>
<tr>
<td><?php echo $this->Html->link(
isset($group['name']) ? $group['domain'] . ':' . $group['name'] : "No Name",
$group['friendlyEmail'] ?? "No Name",
array(
'controller' => 'grouper_groups',
'action' => 'emaillistinfo',
'?' => array('groupname' => urlencode($group['name']))
)
) ?></td>
<td><?php echo isset($group['description']) ? $group['description'] : _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td><?php echo $group['description'] ?? _txt('pl.grouperlite.value.descr.zerostate'); ?></td>
<td class="text-center">
<button class="btn btn-raised btn-success" type="submit">
<?php echo _txt('pl.grouperlite.action.subscribe') ?>
Expand All @@ -44,6 +44,6 @@
<?php endif; ?>
<?php if (count($emailgroups) < 1) : ?>
<div class="alert alert-info">
<p class="lead mb-0 text-center"><?php echo _txt('pl.grouperlite.working-groups.zero-state'); ?></p>
<p class="lead mb-0 text-center"><?php echo _txt('pl.grouperlite.email-lists.zero-state'); ?></p>
</div>
<?php endif; ?>

0 comments on commit 91441b7

Please sign in to comment.