Skip to content

Commit

Permalink
work completed
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Feb 10, 2021
1 parent 5da9108 commit 4c86879
Show file tree
Hide file tree
Showing 5 changed files with 156 additions and 63 deletions.
203 changes: 144 additions & 59 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,14 @@
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');

Expand All @@ -42,12 +47,14 @@ class GrouperGroupsController extends GrouperLiteAppController
* @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 @@ -62,12 +69,15 @@ 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 All @@ -84,95 +94,151 @@ private function setConnection() {
*
* @return CakeResponse Redirect to Optin page
*/
public function index() {
public function index()
{
return $this->redirect(
array('controller' => 'GrouperGroups', 'action' => 'groupoptin')
);
}


public function groupInfo() {
/**
* Display of Grouper Group Information, such as Group Properties, Members and Attributes
*
*/
public function groupInfo()
{
$name = urldecode($this->request->query['groupname']);
$details = $this->GrouperGroup->groupDescriptions($name);

$this->set('groupname', $name);
$this->set('title', _txt('pl.grouperlite.title.groupinfo'));
$this->set('groupergroupsdetail', $details[0]);

try {
$this->set('groupergroupsdetail', $details[0]);
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupInfo: ' . var_export($e->getMessage(), true));
$this->set('groupergroupsdetail', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.info-group-failed'), array('key' => 'error'));
}
}

public function groupOwner() {
/**
* Listing of all Grouper Groups owned/admin by User Or search those Grouper Groups
*/
public function groupOwner()
{
$this->set('title', _txt('pl.grouperlite.title.groupowner'));

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

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

} else {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
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('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
}

/**
* 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
* 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
*
*/
public function groupMember() {
public function groupMember()
{
$this->set('title', _txt('pl.grouperlite.title.groupmember'));
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 {

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 {
$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));

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

/**
* Display all Groups a User can Join
* Display all Grouper Groups that are Optin and a User can join Or search those Grouper Groups
*/
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);
} else {

try {
$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);
}
$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));
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite Controller: Seeing is believing');
$this->Flash->set($e->getMessage(), array('key' => 'error'));
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'));
$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 @@ -185,18 +251,25 @@ 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'];

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'));
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'));
}

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

return $this->redirect(array('action' => 'groupoptin'));
Expand All @@ -207,15 +280,23 @@ 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'];

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'));
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'));
}

} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error'));
}
Expand All @@ -231,14 +312,15 @@ public function leaveGroup() {
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions
*
* @since COmanage Registry v3.2.0
* @return Array Permissions
* @since COmanage Registry v3.2.0
*/
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 @@ -266,7 +348,8 @@ 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 @@ -277,7 +360,8 @@ 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 @@ -288,7 +372,8 @@ 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
1 change: 1 addition & 0 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ public function grouperGroupLeaveOrJoin(array $queryData) {
)
)
);

$this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json'));
$connectionUrl = "{$this->config['fullUrl']}/groups/{$groupName}/members";

Expand Down
11 changes: 8 additions & 3 deletions Lib/lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@
'pl.grouperlite.message.flash.join-group-success' => 'You have been added to the group!',
'pl.grouperlite.message.flash.join-group-failed' => 'You are unable to join the group!',
'pl.grouperlite.message.flash.join-group-error' => 'An error occurred in joining the group, please try again later.',
'pl.grouperlite.message.flash.info-group-failed' => 'Error in viewing group info, please try again later.',

'pl.grouperlite.message.flash.leave-group-success' => 'You have been deleted from the group!',
'pl.grouperlite.message.flash.leave-group-failed' => 'You are unable to delete the group!',
'pl.grouperlite.message.flash.leave-group-error' => 'An error occurred in leaving the group, please try again later.',
'pl.grouperlite.message.flash.owner-group-failed' => 'Error occurred in viewing groups you manage, please try again later.',
'pl.grouperlite.message.flash.member-group-failed' => 'Error occurred in viewing groups you are a member, please try again later.',
'pl.grouperlite.message.flash.optin-group-failed' => 'Error occurred in viewing Optin groups, please try again later.',

'pl.grouperlite.message.flash.leave-group-success' => 'You have been deleted from the group!',
'pl.grouperlite.message.flash.leave-group-failed' => 'You are unable to delete the group!',
'pl.grouperlite.message.flash.leave-group-error' => 'An error occurred in leaving the group, please try again later.',

'pl.grouperlite.table.name' => 'Name',
'pl.grouperlite.table.description' => 'Description',
Expand Down
2 changes: 2 additions & 0 deletions Model/GrouperAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ private function initApi() {
* @throws GrouperLiteException
*/
public function getGroupAttributes(string $groupName) {
$this->initApi();

try {
$args = array();
$args['conditions']['groupName'] = $groupName;
Expand Down
2 changes: 1 addition & 1 deletion View/CoGrouperLites/fields.inc
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,6 @@ print $this->Form->hidden('co_dashboard_widget_id', array('default' => $vv_dwid)

<div id="grouper-plugin" class="pt-2">
<div class="d-flex align-items-center">
<h2><?php echo $title; ?></h2>
<h2><?php echo $params['title']; ?></h2>
</div>
</div>

0 comments on commit 4c86879

Please sign in to comment.