Skip to content

Commit

Permalink
completed and cleaned up errors messages
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Feb 12, 2021
1 parent fe66d17 commit 3eb4dfc
Show file tree
Hide file tree
Showing 6 changed files with 188 additions and 149 deletions.
143 changes: 94 additions & 49 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,24 @@
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() {
parent::beforeFilter();

Expand Down Expand Up @@ -78,8 +88,7 @@ private function setConnection() {
*
* @return CakeResponse Redirect to Optin page
*/
public function index()
{
public function index() {
return $this->redirect(
array('controller' => 'GrouperGroups', 'action' => 'groupoptin')
);
Expand All @@ -89,18 +98,18 @@ public function index()
* Display of Grouper Group Information, such as Group Properties, Members and Attributes
*
*/
public function groupInfo()
{
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'));

try {
$details = $this->GrouperGroup->groupDescriptions($name);
$this->set('groupergroupsdetail', $details[0]);

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

$this->set('groupergroupsdetail', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.info-group-failed'), array('key' => 'error'));
}
Expand All @@ -109,25 +118,34 @@ public function groupInfo()
/**
* Listing of all Grouper Groups owned/admin by User Or search those Grouper Groups
*/
public function groupOwner()
{
public function groupOwner() {
$this->set('title', _txt('pl.grouperlite.title.groupowner'));

if (isset($this->request->data['search'])){
if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$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));
CakeLog::write('error', __METHOD__ . ' Search: ' . var_export($e->getMessage(), true));

$this->set('groupergroupsowner', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error'));
return;
}

} else {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
try {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

$this->set('groupergroupsowner', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error'));
return;
}

}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
}
Expand All @@ -139,22 +157,34 @@ public function groupOwner()
*/
public function groupMember() {
$this->set('title', _txt('pl.grouperlite.title.groupmember'));
try {
if (isset($this->request->data['search'])){
$searchCriteria = urldecode($this->request->data['search']);

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'));
$this->set('searchcriteria', $searchCriteria);
} else {

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

$this->Flash->set("Your Search Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
return;
}
} else {
try {
$this->set('groupergroupmemberships', $this->GrouperGroup->filteredMemberOfGroups($this->userId));

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

$this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
return;
}
} 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));

}

/**
Expand All @@ -163,24 +193,29 @@ public function groupMember() {
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', __METHOD__ . 'Search: ' . var_export($e->getMessage(), true));

$this->Flash->set("Your Optin Group Search cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupoptin', array());
return;
}
} 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->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', __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('groupergroupoptin', array());
return;
}
}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
Expand Down Expand Up @@ -209,10 +244,15 @@ 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', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'), array('key' => 'error'));
}

} else {
Expand All @@ -231,11 +271,17 @@ 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', __METHOD__ . ': ' . 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 @@ -251,14 +297,14 @@ 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() {
$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 @@ -324,5 +370,4 @@ public function emailListInfo() {
'attributes' => array()
));
}

}
28 changes: 13 additions & 15 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function __construct() {
$this->http = new GrouperHTTPWrapper();

if (!CakeSession::check('Plugin.Grouper.Api.id')) {
CakeLog::write('error', 'GrouperLite API: No Widget record in Session');
CakeLog::write('error', __METHOD__ . ': No Widget record in Session');
throw new GrouperLiteException("No GrouperLite instance captured");
}

Expand Down Expand Up @@ -110,7 +110,7 @@ public function getGrouperUser(array $queryData) {
}

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

Expand Down Expand Up @@ -138,7 +138,7 @@ public function getGrouperMemberOfGroups(array $queryData) {
return $results['WsGetGroupsLiteResult']['wsGroups'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getGrouperMemberOfGroups: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

Expand Down Expand Up @@ -168,8 +168,7 @@ public function grouperGroupLeaveOrJoin(array $queryData) {
$resultResponse = 'WsAddMemberResults';
$resultGroup = 'wsGroupAssigned';
} else {
CakeLog::write('error',
"GrouperLite API - grouperGroupLeaveOrJoin: Option of $groupLeaveOrJoin is not supported");
CakeLog::write('error',__METHOD__ . ": Option of $groupLeaveOrJoin is not supported");
throw new GrouperLiteException("Receved option of $groupLeaveOrJoin which is not supported");
}

Expand Down Expand Up @@ -199,7 +198,7 @@ public function grouperGroupLeaveOrJoin(array $queryData) {
}
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - grouperGroupLeaveOrJoin: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}

Expand All @@ -226,7 +225,7 @@ public function getOptinGroups(array $queryData) {
return $results['WsGetMembershipsResults']['wsGroups'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getOptinGroups: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return array();
Expand All @@ -250,7 +249,7 @@ public function getOwnerGroups(array $queryData) {
return $results['WsGetMembershipsResults']['wsGroups'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getOwnerGroups: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return array();
Expand All @@ -273,7 +272,7 @@ public function getOwnerStems(array $queryData) {
return $results['WsGetMembershipsResults']['wsStems'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getOwnerStems: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return array();
Expand Down Expand Up @@ -304,8 +303,7 @@ private function useMembershipUrl(array $queryData) {
$fieldName = "stemAdmin";
$subjectId = $userId;
} else {
CakeLog::write('error',
"GrouperLite API - useMembershipUrl: Option of $groupType is not supported");
CakeLog::write('error', __METHOD__ . ": Option of $groupType is not supported");
throw new GrouperLiteException("Option of $groupType is not supported");
}

Expand All @@ -324,7 +322,7 @@ private function useMembershipUrl(array $queryData) {
try {
return $this->http->sendRequest('POST', $connectionUrl, json_encode($groupsToShow));
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - useMembershipUrl: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
}
Expand All @@ -350,7 +348,7 @@ public function getGrouperGroupDescription(array $queryData) {
return $results['WsGetMembershipsResults']['wsGroups'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getGrouperGroupDescription: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return array();
Expand Down Expand Up @@ -407,7 +405,7 @@ public function createUpdateGroup(array $queryData) {
}
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - createUpdateGroup: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return false;
Expand Down Expand Up @@ -446,7 +444,7 @@ public function getGroupAttributes(array $queryData) {
return $results['WsGetAttributeAssignmentsResults']['wsAttributeAssigns'];
}
} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite API - getGroupAttributes: An error occurred');
CakeLog::write('error', __METHOD__ . ': An error occurred');
throw $e;
}
return array();
Expand Down
Loading

0 comments on commit 3eb4dfc

Please sign in to comment.