Skip to content

Commit

Permalink
Merge branch 'develop' into feature/ICPCO-87
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Feb 10, 2021
2 parents 4c86879 + 765768d commit 4644e29
Show file tree
Hide file tree
Showing 8 changed files with 1,201 additions and 163 deletions.
169 changes: 52 additions & 117 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,33 +28,20 @@
App::uses('Validator', 'Vendor/cakephp/Validation');
App::uses('CoGrouperLite', 'GrouperLite.Model/');

/**
* Class GrouperGroupsController
* Main Class for Grouper Lite functionality
*
*/

class GrouperGroupsController extends GrouperLiteAppController
{

public $helpers = array('Html', 'Form', 'Flash');
public $components = array('Flash');

public $name = 'GrouperGroups';

/**
* Overrides parent beforeFilter to verify that Session contains the correct API settings.
*
* @return CakeResponse|void|null
*
*/
public function beforeFilter()
{
public function beforeFilter() {
parent::beforeFilter();

//Need to find which plugin instance choosing, if more than one from cm_co_grouper_lites
// table being used in COmanage.
$grouperConnData = $this->Session->read('Plugin.Grouper.Api');

if ($this->Session->check('Plugin.Grouper.Api.id') && count($grouperConnData) == 5) {
if (isset($this->passedArgs['glid'])) {
if ($this->Session->read('Plugin.Grouper.Api.id') !== $this->passedArgs['glid']) {
Expand All @@ -69,15 +56,12 @@ public function beforeFilter()
}
$this->setConnection();
}

}

/**
* Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php
*
*/
private function setConnection()
{
private function setConnection() {
$this->Session->write('Plugin.Grouper.Api.id', $this->passedArgs['glid']);

//Now get the setup Dasboard instance from db for connection info.
Expand Down Expand Up @@ -143,102 +127,72 @@ public function groupOwner()
}

} else {
try {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupOwner: ' . var_export($e->getMessage(), true));
$this->set('groupergroupsowner', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error'));
}

$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
}

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

/**
* Listing of all Grouper Groups that the User is a member of Or search those Grouper Groups
* This includes self-joined Optin Groups, as well as non-Optin Groups User cannot leave
* Returns all Groups that the User is a member of in Grouper
* This includes self-joined Optin Groups, as well as required Groups User cannot leave
*
*/
public function groupMember()
{
public function groupMember() {
$this->set('title', _txt('pl.grouperlite.title.groupmember'));

if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('searchcriteria', $searchCriteria);

try {
$this->set('groupergroupmemberships',
$this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember'));
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupMember Search: ' . var_export($e->getMessage(), true));
$this->set('groupergroupmemberships', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.member-group-failed'), array('key' => 'error'));
}

} else {
try {
try {
if (isset($this->request->data['search'])){
$searchCriteria = urldecode($this->request->data['search']);
$this->set('groupergroupmemberships', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember'));
$this->set('searchcriteria', $searchCriteria);
} else {
$this->set('groupergroupmemberships', $this->GrouperGroup->filteredMemberOfGroups($this->userId));
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupMember: ' . var_export($e->getMessage(), true));
$this->set('groupergroupmemberships', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.member-group-failed'), array('key' => 'error'));
}

} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupMember: ' . var_export($e->getMessage(), true));
$this->Flash->set("Your Membership Groups cannot be found currently, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
}

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

}

/**
* Display all Grouper Groups that are Optin and a User can join Or search those Grouper Groups
* Display all Groups a User can Join
*/
public function groupOptin()
{
public function groupOptin() {
$this->set('title', _txt('pl.grouperlite.title.groupoptin'));

if (isset($this->request->data['search'])) {
if (isset($this->request->data['search'])){
$searchCriteria = urldecode($this->request->data['search']);
$this->set('groupergroupoptin', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOptin'));
$this->set('searchcriteria', $searchCriteria);

try {
$this->set('groupergroupoptin', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOptin'));
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupOptin Search: ' . var_export($e->getMessage(), true));
$this->set('groupergroupoptin', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.optin-group-failed'), array('key' => 'error'));
}

} else {
try {
$this->set('groupergroupoptin', $this->GrouperGroup->optinGroups($this->userId));
$optin = $this->GrouperGroup->optinGroups($this->userId);
if (isset($optin['errorMessage'])){
$this->Flash->set('Some error', array('key' => 'error'));
$this->set('groupergroupoptin', array());
} else {
$this->set('groupergroupoptin', $optin);
}

} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupOptin: ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.optin-group-failed'), array('key' => 'error'));
CakeLog::write('error', 'GrouperLite Controller: Seeing is believing');
$this->Flash->set($e->getMessage(), array('key' => 'error'));
$this->set('groupergroupoptin', array());
}

}

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

//TODO - Need to combine this form with code below for groupCreate
public function groupCreateForm()
{
public function groupCreateForm() {
$this->set('title', _txt('pl.grouperlite.title.groupcreate'));
$this->set('grouperstems', $this->GrouperGroup->getOwnerStems($this->userId));
}

public function groupCreate()
{
public function groupCreate() {
$name = urldecode($this->request->data['name']);
$set = urldecode($this->request->data['set']);
$descr = urldecode($this->request->data['description']);
Expand All @@ -251,25 +205,18 @@ public function groupCreate()
*
* @return CakeResponse Redirect back to "Optin" page
*/
public function joinGroup()
{
public function joinGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

try {
if ($this->GrouperGroup->joinGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-failed'), array('key' => 'error'));
}
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - joinGroup: ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'), array('key' => 'error'));
if($this->GrouperGroup->joinGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-failed'), array('key' => 'error'));
}

} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'), array('key' => 'error'));
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'));
}

return $this->redirect(array('action' => 'groupoptin'));
Expand All @@ -280,23 +227,15 @@ public function joinGroup()
*
* @return CakeResponse Redirect back to "Member Of" page
*/
public function leaveGroup()
{
public function leaveGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

try {
if ($this->GrouperGroup->leaveGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-failed'), array('key' => 'error'));
}
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - leaveGroup: ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error'));
if($this->GrouperGroup->leaveGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-failed'), array('key' => 'error'));
}

} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error'));
}
Expand All @@ -312,15 +251,14 @@ public function leaveGroup()
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions
*
* @return Array Permissions
* @since COmanage Registry v3.2.0
* @return Array Permissions
*/
function isAuthorized()
{
function isAuthorized() {
$roles = $this->Role->calculateCMRoles();

//Need to pull in UserID for access to Grouper
if ($this->Session->check('Auth.User.username')) {
if($this->Session->check('Auth.User.username')) {
$this->userId = $this->Session->read('Auth.User.username');
}

Expand Down Expand Up @@ -348,8 +286,7 @@ function isAuthorized()
return ($p[$this->action]);
}

public function emailListsOptin()
{
public function emailListsOptin() {
$this->set('title', _txt('pl.grouperlite.title.emaillists'));
// mock data
$this->set('group', array(
Expand All @@ -360,8 +297,7 @@ public function emailListsOptin()
));
}

public function emailListsManaged()
{
public function emailListsManaged() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged'));
// mock data
$this->set('group', array(
Expand All @@ -372,8 +308,7 @@ public function emailListsManaged()
));
}

public function emailListInfo()
{
public function emailListInfo() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsinfo'));
// mock data
$this->set('groupergroupsdetail', array(
Expand Down
28 changes: 15 additions & 13 deletions View/Elements/Components/navigation.ctp
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,19 @@
</div>
*/ ?>
</div>
<div class="align-self">
<?php
$createGroupUrl = $this->Html->url(
array(
'controller' => 'groupergroups',
'action' => 'groupcreateform'
)
);
?>
<a href="<?php echo $createGroupUrl; ?>" class="btn btn-link px-3 py-2">
<i class="fa fa-plus-circle"></i>&nbsp; <?php echo _txt('pl.grouperlite.nav.create-group'); ?>
</a>
</div>
<?php if ($isuserowner === 'T') { ?>
<div class="align-self">
<?php
$createGroupUrl = $this->Html->url(
array(
'controller' => 'groupergroups',
'action' => 'groupcreateform'
)
);
?>
<a href="<?php echo $createGroupUrl; ?>" class="btn btn-link px-3 py-2">
<i class="fa fa-plus-circle"></i>&nbsp; <?php echo _txt('pl.grouperlite.nav.create-group'); ?>
</a>
</div>
<?php } ?>
</nav>
16 changes: 11 additions & 5 deletions View/Elements/Components/subscriberList.ctp
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<ul class="list-group list-group-flush">
<?php foreach ($subscribers as $sub): ?>
<li class="list-group-item"><?php echo $sub['name']; ?> - <?php echo $sub['email']; ?></li>
<?php endforeach; ?>
</ul>

<table class="table table-striped">
<tbody>
<?php foreach ($subscribers as $sub) : ?>
<tr>
<td><?php echo $sub['name']; ?></td>
<td><?php echo $sub['email']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
Loading

0 comments on commit 4644e29

Please sign in to comment.