From 5da910826565bb28ef16a15da890cbbd876cbd43 Mon Sep 17 00:00:00 2001 From: axman Date: Mon, 8 Feb 2021 14:55:31 -0700 Subject: [PATCH 1/4] WIP --- Controller/GrouperGroupsController.php | 31 +++ Lib/GrouperApiAccess.php | 32 +-- Model/GrouperAttribute.php | 12 +- Model/GrouperGroup.php | 312 ++++++++++++++++--------- 4 files changed, 255 insertions(+), 132 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 96df0fd..045b45a 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -1,4 +1,29 @@ getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getGrouperUser: An error occurred'); throw $e; } @@ -139,8 +138,7 @@ public function getGrouperMemberOfGroups(array $queryData) { return $results['WsGetGroupsLiteResult']['wsGroups']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getGrouperMemberOfGroups: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getGrouperMemberOfGroups: An error occurred'); throw $e; } @@ -200,8 +198,7 @@ public function grouperGroupLeaveOrJoin(array $queryData) { } } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - grouperGroupLeaveOrJoin: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - grouperGroupLeaveOrJoin: An error occurred'); throw $e; } @@ -228,8 +225,7 @@ public function getOptinGroups(array $queryData) { return $results['WsGetMembershipsResults']['wsGroups']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getOptinGroups: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getOptinGroups: An error occurred'); throw $e; } return array(); @@ -253,8 +249,7 @@ public function getOwnerGroups(array $queryData) { return $results['WsGetMembershipsResults']['wsGroups']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getOwnerGroups: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getOwnerGroups: An error occurred'); throw $e; } return array(); @@ -277,8 +272,7 @@ public function getOwnerStems(array $queryData) { return $results['WsGetMembershipsResults']['wsStems']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getOwnerStems: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getOwnerStems: An error occurred'); throw $e; } return array(); @@ -329,14 +323,13 @@ 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 issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - useMembershipUrl: An error occurred'); throw $e; } } /** - * Returns a Distinct Grouper Group with its associated attributes and values + * Returns a Distinct Grouper Group with its associated values * * @param array $queryData Array of conditions for querying * @return array Array of attributes for a Group @@ -356,8 +349,7 @@ public function getGrouperGroupDescription(array $queryData) { return $results['WsGetMembershipsResults']['wsGroups']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getGrouperGroupDescription: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getGrouperGroupDescription: An error occurred'); throw $e; } return array(); @@ -414,8 +406,7 @@ public function createUpdateGroup(array $queryData) { } } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - createUpdateGroup: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - createUpdateGroup: An error occurred'); throw $e; } return false; @@ -454,8 +445,7 @@ public function getGroupAttributes(array $queryData) { return $results['WsGetAttributeAssignmentsResults']['wsAttributeAssigns']; } } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API - getGroupAttributes: An issue surfaced of ' . var_export($e->getMessage(), true)); + CakeLog::write('error', 'GrouperLite API - getGroupAttributes: An error occurred'); throw $e; } return array(); diff --git a/Model/GrouperAttribute.php b/Model/GrouperAttribute.php index d1c865f..aedfa06 100644 --- a/Model/GrouperAttribute.php +++ b/Model/GrouperAttribute.php @@ -58,10 +58,16 @@ private function initApi() { * @throws GrouperLiteException */ public function getGroupAttributes(string $groupName) { - $args = array(); - $args['conditions']['groupName'] = $groupName; + try { + $args = array(); + $args['conditions']['groupName'] = $groupName; - return $this->grouperAPI->getGroupAttributes($args); + return $this->grouperAPI->getGroupAttributes($args); + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Attribute Model - getGroupAttributes: An error occurred'); + throw $e; + } } } diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 017677c..5525000 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -74,17 +74,23 @@ public function isUserOwner(string $userId) { $this->initApi(); - $args = array(); - $args['conditions']['userId'] = $userId; + try { + $args = array(); + $args['conditions']['userId'] = $userId; - $ownGroups = $this->grouperAPI->getOwnerGroups($args); + $ownGroups = $this->grouperAPI->getOwnerGroups($args); - if (count($ownGroups) > 0) { - CakeSession::write('Plugin.Grouper.isUserOwner', 'T'); - return 'T'; + if (count($ownGroups) > 0) { + CakeSession::write('Plugin.Grouper.isUserOwner', 'T'); + return 'T'; + } + CakeSession::write('Plugin.Grouper.isUserOwner', 'F'); + return 'F'; + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - isUserOwner: An error occurred'); + throw $e; } - CakeSession::write('Plugin.Grouper.isUserOwner', 'F'); - return 'F'; } /** @@ -111,26 +117,31 @@ private function resetUserOwner() { public function filteredMemberOfGroups(string $userId) { $this->initApi(); - $memberOfGroups = $this->memberOfGroups($userId); - - $args = array(); - $args['conditions']['userId'] = $userId; - // Determine which groups can be left by user, if want. - $optInGroups = $this->grouperAPI->getOptinGroups($args); - - foreach($memberOfGroups as &$memberOfGroup) { - foreach($optInGroups as $key => $value) { - if ($value['name'] == $memberOfGroup['name']) { - //Match! - $memberOfGroup['optedin'] = true; - //Remove Optin group since already found and now less loops - unset($optInGroups[$key]); - break; + try { + $memberOfGroups = $this->memberOfGroups($userId); + + $args = array(); + $args['conditions']['userId'] = $userId; + // Determine which groups can be left by user, if want. + $optInGroups = $this->grouperAPI->getOptinGroups($args); + + foreach($memberOfGroups as &$memberOfGroup) { + foreach($optInGroups as $key => $value) { + if ($value['name'] == $memberOfGroup['name']) { + //Match! + $memberOfGroup['optedin'] = true; + //Remove Optin group since already found and now less loops + unset($optInGroups[$key]); + break; + } } } - } + return $this->getFriendlyName($memberOfGroups); - return $this->getFriendlyName($memberOfGroups); + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - filteredMemberOfGroups: An error occurred'); + throw $e; + } } /** @@ -143,33 +154,52 @@ public function filteredMemberOfGroups(string $userId) { */ private function memberOfGroups(string $userId) { - $args = array(); - $args['conditions']['userId'] = $userId; + try { + $args = array(); + $args['conditions']['userId'] = $userId; - return $this->grouperAPI->getGrouperMemberOfGroups($args); + return $this->grouperAPI->getGrouperMemberOfGroups($args); + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - memberOfGroups: An error occurred'); + throw $e; + } } - public function groupDescriptions($groupName) { + /** + * 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 + * @throws GrouperLiteException + */ + public function groupDescriptions(string $groupName) { $this->initApi(); - $args = array(); - $args['conditions']['groupName'] = $groupName; + try { + $args = array(); + $args['conditions']['groupName'] = $groupName; - $groupDescription = $this->grouperAPI->getGrouperGroupDescription($args); - //make call to get attributes for group - $grouperAtt = new GrouperAttribute(); - $groupAttributes = $grouperAtt->getGroupAttributes($groupName); + $groupDescription = $this->grouperAPI->getGrouperGroupDescription($args); + //make call to get attributes for group + $grouperAtt = new GrouperAttribute(); + $groupAttributes = $grouperAtt->getGroupAttributes($groupName); - $groupDescription[0]["attributes"] = $groupAttributes; + $groupDescription[0]["attributes"] = $groupAttributes; + return $groupDescription; + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - groupDescriptions: An error occurred'); + throw $e; + } - return $groupDescription; } /** * Process for User to Leave a Group * * @param string $userId Id of User - * @param string $groupName Name of Group Leaving + * @param string $groupName Name of Group Leaving, do not confuse with DisplayName field! * @return bool True|False * @throws GrouperLiteException * @@ -177,19 +207,25 @@ public function groupDescriptions($groupName) { public function leaveGroup(string $userId, string $groupName) { $this->initApi(); - $args = array(); - $args['conditions']['LeaveJoin'] = 'Leave'; - $args['conditions']['userId'] = $userId; - $args['conditions']['groupName'] = $groupName; + try { + $args = array(); + $args['conditions']['LeaveJoin'] = 'Leave'; + $args['conditions']['userId'] = $userId; + $args['conditions']['groupName'] = $groupName; + + return $this->grouperAPI->grouperGroupLeaveOrJoin($args); - return $this->grouperAPI->grouperGroupLeaveOrJoin($args); + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - leaveGroup: An error occurred'); + throw $e; + } } /** * Process for User to Join a Group * * @param string $userId Id of User - * @param string $groupName Name of Group Leaving + * @param string $groupName Name of Group Joining, do not confuse with DisplayName field! * @return bool True|False * @throws GrouperLiteException * @@ -197,30 +233,48 @@ public function leaveGroup(string $userId, string $groupName) { public function joinGroup(string $userId, string $groupName) { $this->initApi(); - $args = array(); - $args['conditions']['LeaveJoin'] = 'Join'; - $args['conditions']['userId'] = $userId; - $args['conditions']['groupName'] = $groupName; + try { + $args = array(); + $args['conditions']['LeaveJoin'] = 'Join'; + $args['conditions']['userId'] = $userId; + $args['conditions']['groupName'] = $groupName; - return $this->grouperAPI->grouperGroupLeaveOrJoin($args); - } + return $this->grouperAPI->grouperGroupLeaveOrJoin($args); + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - joinGroup: An error occurred'); + throw $e; + } + } - public function ownerGroups($userId) { + /** + * Return all Grouper Groups that the User has a role of owner/admin + * + * @param string $userId + * @return array + * @throws GrouperLiteException + * + */ + public function ownerGroups(string $userId) { $this->initApi(); - $args = array(); - $args['conditions']['userId'] = $userId; + try { + $args = array(); + $args['conditions']['userId'] = $userId; - $ownGroups = $this->grouperAPI->getOwnerGroups($args); - $ownerGroups = $this->getFriendlyName($ownGroups); + $ownGroups = $this->grouperAPI->getOwnerGroups($args); + $ownerGroups = $this->getFriendlyName($ownGroups); - return $ownerGroups; + return $ownerGroups; + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - ownerGroups: An error occurred'); + throw $e; + } } /** - * Display all Groups the User can JOIN + * Return all Groups the User can JOIN * Get all Groups with Optin attribute set and display ones User can join. * Will Match up with Groups User is already a member of to determine which Optin groups to not display * @@ -231,50 +285,85 @@ public function ownerGroups($userId) { public function optinGroups(string $userId) { $this->initApi(); - $args = array(); - $args['conditions']['userId'] = $userId; - - $joinOrLeave = $this->grouperAPI->getOptinGroups($args); - $userGroups = $this->memberOfGroups($userId); - - //See if Optin group match any of the groups user already belongs to. - foreach ($joinOrLeave as $key => $value) { - foreach ($userGroups as $userGroup) { - if ($value['name'] == $userGroup['name']) { - //Match!! - //Removing as already a member of. - unset($joinOrLeave[$key]); - break; + try { + $args = array(); + $args['conditions']['userId'] = $userId; + + $joinOrLeave = $this->grouperAPI->getOptinGroups($args); + $userGroups = $this->memberOfGroups($userId); + + //See if Optin group match any of the groups user already belongs to. + foreach ($joinOrLeave as $key => $value) { + foreach ($userGroups as $userGroup) { + if ($value['name'] == $userGroup['name']) { + //Match!! + //Removing as already a member of. + unset($joinOrLeave[$key]); + break; + } } } - } + return $this->getFriendlyName($joinOrLeave); - return $this->getFriendlyName($joinOrLeave); + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - optinGroups: An error occurred'); + throw $e; + } } - public function createGroup($userId, $groupName, $stemName, $groupDesc) { + /** + * Creates a new Grouper Group + * + * @param string $userId Id of user + * @param string $groupName Display Name of Group creating, do not confuse with Name field that is ID! + * @param string $stemName Full Stem (Folder) Name in format of 'stem:substem:subsubstem' + * @param string $groupDesc Description of Group creating + * @return bool True if saved | False if already created + * @throws GrouperLiteException + * + */ + public function createGroup(string $userId, string $groupName, string $stemName, string $groupDesc) { $this->initApi(); - $args = array(); - $args['conditions']['groupType'] = 'Optins'; - $args['conditions']['userId'] = $userId; - $args['conditions']['groupName'] = $groupName; - $args['conditions']['stemName'] = $stemName; - $args['conditions']['groupDescription'] = $groupDesc; + try { + $args = array(); + $args['conditions']['groupType'] = 'Optins'; + $args['conditions']['userId'] = $userId; + $args['conditions']['groupName'] = $groupName; + $args['conditions']['stemName'] = $stemName; + $args['conditions']['groupDescription'] = $groupDesc; - // Reset Session variable holding if User is an owner - $this->resetUserOwner(); + // Reset Session variable that shows if User is an owner or not + $this->resetUserOwner(); - return $this->grouperAPI->createUpdateGroup($args); + return $this->grouperAPI->createUpdateGroup($args); + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - createGroup: An error occurred'); + throw $e; + } } - public function getOwnerStems($userId) { + /** + * Get Grouper Stems where User has authority to create a Grouper Group + * + * @param string $userId Id of User + * @return array Stem records + * @throws GrouperLiteException + */ + public function getOwnerStems(string $userId) { $this->initApi(); - $args = array(); - $args['conditions']['userId'] = $userId; + try { + $args = array(); + $args['conditions']['userId'] = $userId; - return $this->grouperAPI->getOwnerStems($args); + return $this->grouperAPI->getOwnerStems($args); + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - getOwnerStems: An error occurred'); + throw $e; + } } /** @@ -283,35 +372,42 @@ public function getOwnerStems($userId) { * 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. * - * @param $userId - * @param $searchCriteria - * @param $page - * @return array + * @param string $userId Id of User + * @param string $searchCriteria Search term entered by user + * @param string $page Page where search was executed, so can search correct criteria + * @return array Records that meet search criteria * @throws GrouperLiteException Captured in Controller */ - public function getSearchedGroups($userId, $searchCriteria, $page) { + public function getSearchedGroups(string $userId, string $searchCriteria, string $page) { $this->initApi(); - if($page == 'groupOptin') { - $pageResults = $this->optinGroups($userId); - } elseif ($page == 'groupOwner') { - $pageResults = $this->ownerGroups($userId); - } elseif ($page == 'groupMember') { - $pageResults = $this->filteredMemberOfGroups($userId); - } else { - $pageResults = array(); - } + try { + // Current list of views that search can be executed from + if($page == 'groupOptin') { + $pageResults = $this->optinGroups($userId); + } elseif ($page == 'groupOwner') { + $pageResults = $this->ownerGroups($userId); + } elseif ($page == 'groupMember') { + $pageResults = $this->filteredMemberOfGroups($userId); + } else { + $pageResults = array(); + } - $returnResults = array(); + $returnResults = array(); - foreach($pageResults as $result) { - $match = preg_grep("/$searchCriteria/i", $result); - if (!empty($match)) { - $returnResults[] = $result; + foreach($pageResults as $result) { + $match = preg_grep("/$searchCriteria/i", $result); + if (!empty($match)) { + $returnResults[] = $result; + } } - } - return $returnResults; + return $returnResults; + + } catch (Exception $e) { + CakeLog::write('error', 'GrouperLite Model - getSearchedGroups: An error occurred'); + throw $e; + } } /** From 4c868790a2dbe0b3cf35a513d58da6f8698b0253 Mon Sep 17 00:00:00 2001 From: axman Date: Wed, 10 Feb 2021 14:06:15 -0700 Subject: [PATCH 2/4] work completed --- Controller/GrouperGroupsController.php | 203 ++++++++++++++++++------- Lib/GrouperApiAccess.php | 1 + Lib/lang.php | 11 +- Model/GrouperAttribute.php | 2 + View/CoGrouperLites/fields.inc | 2 +- 5 files changed, 156 insertions(+), 63 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 045b45a..5a6a705 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -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'); @@ -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']) { @@ -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. @@ -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']); @@ -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')); @@ -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')); } @@ -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'); } @@ -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( @@ -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( @@ -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( diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 568221b..b7f53eb 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -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"; diff --git a/Lib/lang.php b/Lib/lang.php index 60baf2d..4ef1ffc 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -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', diff --git a/Model/GrouperAttribute.php b/Model/GrouperAttribute.php index aedfa06..80f716b 100644 --- a/Model/GrouperAttribute.php +++ b/Model/GrouperAttribute.php @@ -58,6 +58,8 @@ private function initApi() { * @throws GrouperLiteException */ public function getGroupAttributes(string $groupName) { + $this->initApi(); + try { $args = array(); $args['conditions']['groupName'] = $groupName; diff --git a/View/CoGrouperLites/fields.inc b/View/CoGrouperLites/fields.inc index 7bdff65..3811a43 100644 --- a/View/CoGrouperLites/fields.inc +++ b/View/CoGrouperLites/fields.inc @@ -204,6 +204,6 @@ print $this->Form->hidden('co_dashboard_widget_id', array('default' => $vv_dwid)
-

+

\ No newline at end of file From 67c796c91dd41eead349649c9390c6df7a68717b Mon Sep 17 00:00:00 2001 From: axman Date: Thu, 11 Feb 2021 13:35:36 -0700 Subject: [PATCH 3/4] fixed --- Model/CoGrouperLite.php | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/Model/CoGrouperLite.php b/Model/CoGrouperLite.php index 154c0e6..a0798e3 100644 --- a/Model/CoGrouperLite.php +++ b/Model/CoGrouperLite.php @@ -42,39 +42,33 @@ class CoGrouperLite extends CoDashboardWidgetBackend { public $hasMany = array( ); + /* + Not sure if will use public $duplicatableModels = array( "CoGrouperLite" => array( "parent" => "CoDashboardWidget", "fk" => "co_dashboard_widget_id" ) - ); + );*/ // Validation rules for table elements + //Tried adding rule to each field to make alphaNumeric, but keeps throwing errors. will research. public $validate = array( 'co_dashboard_widget_id' => array( 'rule' => 'numeric', - 'required' => true, - 'allowEmpty' => false + 'required' => true ), 'connUrl' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'allowEmpty' => false + 'required' => true ), 'connVer' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'allowEmpty' => false + 'required' => true ), 'connUser' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'allowEmpty' => false + 'required' => true ), 'connPass' => array( - 'rule' => 'alphaNumeric', - 'required' => true, - 'allowEmpty' => false + 'required' => true ), ); From 3eb4dfcf1cab74fb259bd1de859592fe939f1470 Mon Sep 17 00:00:00 2001 From: axman Date: Fri, 12 Feb 2021 08:02:52 -0700 Subject: [PATCH 4/4] completed and cleaned up errors messages --- Controller/GrouperGroupsController.php | 143 ++++++++++++++++--------- Lib/GrouperApiAccess.php | 28 +++-- Lib/GrouperHTTPWrapper.php | 12 +-- Lib/lang.php | 120 ++++++++++----------- Model/GrouperGroup.php | 32 +++--- View/GrouperGroups/groupinfo.ctp | 2 +- 6 files changed, 188 insertions(+), 149 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index b6f7a93..c2b9f69 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -28,7 +28,11 @@ 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'); @@ -36,6 +40,12 @@ class GrouperGroupsController extends GrouperLiteAppController public $name = 'GrouperGroups'; + /** + * Overrides parent beforeFilter to verify that Session contains the correct API settings. + * + * @return CakeResponse|void|null + * + */ public function beforeFilter() { parent::beforeFilter(); @@ -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') ); @@ -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')); } @@ -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)); } @@ -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)); - } /** @@ -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)); @@ -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 { @@ -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')); } @@ -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'); } @@ -324,5 +370,4 @@ public function emailListInfo() { 'attributes' => array() )); } - } diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index b7f53eb..81377e5 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -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"); } @@ -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; } @@ -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; } @@ -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"); } @@ -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; } @@ -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(); @@ -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(); @@ -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(); @@ -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"); } @@ -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; } } @@ -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(); @@ -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; @@ -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(); diff --git a/Lib/GrouperHTTPWrapper.php b/Lib/GrouperHTTPWrapper.php index 9c9abb9..625d96c 100644 --- a/Lib/GrouperHTTPWrapper.php +++ b/Lib/GrouperHTTPWrapper.php @@ -115,8 +115,7 @@ public function sendRequest(string $method, string $uri, string $body = ''): arr try { $results = $this->request($this->_request); } catch (Exception $e) { - CakeLog::write('error', - 'GrouperLite API: An error occurred: ' . var_export($e->getMessage(), true)); + CakeLog::write('error', __METHOD__ . ': An error occurred: ' . var_export($e->getMessage(), true)); throw new GrouperLiteException('An error occurred talking to Grouper WS'); } return $this->_verifyResults($results); @@ -139,15 +138,12 @@ private function _verifyResults(HttpSocketResponse $apiResults): array { $apiSuccess = $resBody[$mainKey]['resultMetadata']['resultCode']; if ($apiSuccess != 'SUCCESS') { - CakeLog::write('error', - 'GrouperLite: Result Code was not SUCCESS, it was: ' . var_export($apiSuccess, true)); - CakeLog::write('error', - 'GrouperLite: Error message: ' . var_export($apiResults->body(), true)); + CakeLog::write('error', __METHOD__ . ': Result Code was ' . var_export($apiSuccess, true)); + CakeLog::write('error', __METHOD__ . ': Error of ' . var_export($apiResults->body(), true)); throw new GrouperLiteException('Result from Grouper WS was' . var_export($apiSuccess, true)); } } else { - CakeLog::write('error', - 'GrouperLite Verify: Error message = ' . var_export($apiResults->body(), true)); + CakeLog::write('error', __METHOD__ . ': Verify error of ' . var_export($apiResults->body(), true)); throw new GrouperLiteException('An error occurred while talking to Grouper WS'); } return $resBody; diff --git a/Lib/lang.php b/Lib/lang.php index 4ef1ffc..b52f529 100644 --- a/Lib/lang.php +++ b/Lib/lang.php @@ -1,35 +1,35 @@ 'Grouper Configuration Settings', - 'pl.grouperlite.config.edit.title' => 'Edit Grouper Configuration Settings', - 'pl.grouperlite.config.grouper-url' => 'Grouper URL', - 'pl.grouperlite.config.grouper-version' => 'Grouper Version', - 'pl.grouperlite.config.grouper-un' => 'Username', - 'pl.grouperlite.config.grouper-pw' => 'Password', + 'pl.grouperlite.config.display.title' => 'Grouper Configuration Settings', + 'pl.grouperlite.config.edit.title' => 'Edit Grouper Configuration Settings', + 'pl.grouperlite.config.grouper-url' => 'Grouper URL', + 'pl.grouperlite.config.grouper-version' => 'Grouper Version', + 'pl.grouperlite.config.grouper-un' => 'Username', + 'pl.grouperlite.config.grouper-pw' => 'Password', - 'pl.grouperlite.crumb.root' => 'Grouper', - 'pl.grouperlite.nav.groups-can-join' => 'Groups I can join', - 'pl.grouperlite.nav.groups-presided' => 'Groups I manage', - 'pl.grouperlite.nav.memberships' => 'My memberships', - 'pl.grouperlite.nav.email-lists' => 'Email lists', - 'pl.grouperlite.nav.email-lists-managed' => 'Email lists I manage', - 'pl.grouperlite.nav.create-group' => 'Create group', + 'pl.grouperlite.crumb.root' => 'Grouper', + 'pl.grouperlite.nav.groups-can-join' => 'Groups I can join', + 'pl.grouperlite.nav.groups-presided' => 'Groups I manage', + 'pl.grouperlite.nav.memberships' => 'My memberships', + 'pl.grouperlite.nav.email-lists' => 'Email lists', + 'pl.grouperlite.nav.email-lists-managed' => 'Email lists I manage', + 'pl.grouperlite.nav.create-group' => 'Create group', - 'pl.grouperlite.title.root' => 'Grouper Collaborations:', - 'pl.grouperlite.title.groupinfo' => 'Group configuration and attributes', - 'pl.grouperlite.title.groupowner' => 'Groups I manage', - 'pl.grouperlite.title.groupmember' => 'My Memberships', - 'pl.grouperlite.title.groupoptin' => 'Groups I can join', - 'pl.grouperlite.title.emaillists' => 'Email lists', - 'pl.grouperlite.title.emaillistsmanaged' => 'Email lists I manage', - 'pl.grouperlite.title.emaillistsinfo' => 'Email list configuration and attributes', - 'pl.grouperlite.title.groupcreate' => 'Create Group', + 'pl.grouperlite.title.root' => 'Grouper Collaborations:', + 'pl.grouperlite.title.groupinfo' => 'Group configuration and attributes', + 'pl.grouperlite.title.groupowner' => 'Groups I manage', + 'pl.grouperlite.title.groupmember' => 'My Memberships', + 'pl.grouperlite.title.groupoptin' => 'Groups I can join', + 'pl.grouperlite.title.emaillists' => 'Email lists', + 'pl.grouperlite.title.emaillistsmanaged' => 'Email lists I manage', + 'pl.grouperlite.title.emaillistsinfo' => 'Email list configuration and attributes', + 'pl.grouperlite.title.groupcreate' => 'Create Group', - '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.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!', @@ -39,42 +39,42 @@ 'pl.grouperlite.message.flash.optin-group-failed' => 'Error occurred in viewing Optin groups, please try again later.', - 'pl.grouperlite.table.name' => 'Name', - 'pl.grouperlite.table.description' => 'Description', - 'pl.grouperlite.table.status' => 'Status', - 'pl.grouperlite.table.action' => 'Action', + 'pl.grouperlite.table.name' => 'Name', + 'pl.grouperlite.table.description' => 'Description', + 'pl.grouperlite.table.status' => 'Status', + 'pl.grouperlite.table.action' => 'Action', - 'pl.grouperlite.value.descr.zerostate' => 'No Description', - 'pl.grouperlite.value.enabled' => 'Enabled', - 'pl.grouperlite.value.disabled' => 'Disabled', + 'pl.grouperlite.value.descr.zerostate' => 'No Description', + 'pl.grouperlite.value.enabled' => 'Enabled', + 'pl.grouperlite.value.disabled' => 'Disabled', - 'pl.grouperlite.action.join-group' => 'Join group', - 'pl.grouperlite.action.leave-group' => 'Leave group', - 'pl.grouperlite.action.edit-group' => 'Edit', - 'pl.grouperlite.action.disable-group' => 'Disable', - 'pl.grouperlite.action.subscribe' => 'Subscribe', - 'pl.grouperlite.action.unsubscribe' => 'Unsubscribe', - 'pl.grouperlite.action.search' => 'Search', - 'pl.grouperlite.action.remove' => 'Remove', + 'pl.grouperlite.action.join-group' => 'Join group', + 'pl.grouperlite.action.leave-group' => 'Leave group', + 'pl.grouperlite.action.edit-group' => 'Edit', + 'pl.grouperlite.action.disable-group' => 'Disable', + 'pl.grouperlite.action.subscribe' => 'Subscribe', + 'pl.grouperlite.action.unsubscribe' => 'Unsubscribe', + 'pl.grouperlite.action.search' => 'Search', + 'pl.grouperlite.action.remove' => 'Remove', - 'pl.grouperlite.form.group.template.label' => 'Select a template', - 'pl.grouperlite.form.group.template.empty' => '(choose one)', - 'pl.grouperlite.form.group.name.label' => 'Display name', - 'pl.grouperlite.form.group.name.help' => 'Name is the label that identifies this group, and might change.', - 'pl.grouperlite.form.group.stem.label' => 'Create in this folder:', - 'pl.grouperlite.form.group.stem.help' => 'Enter a folder name.', - 'pl.grouperlite.form.group.description.label' => 'Description:', - 'pl.grouperlite.form.group.description.help' => 'Description contains notes about the group, which could include: what the group represents, why it was created, etc.', - 'pl.grouperlite.form.group.privs.label' => 'Privileges', - 'pl.grouperlite.form.group.privs.label.READ' => 'READ', - 'pl.grouperlite.form.group.privs.label.VIEW' => 'VIEW', - 'pl.grouperlite.form.group.privs.label.OPTIN' => 'OPTIN', - 'pl.grouperlite.form.group.privs.label.OPTOUT' => 'OPTOUT', - 'pl.grouperlite.form.group.privs.label.ATTRIBUTE_READ' => 'ATTRIBUTE READ', - 'pl.grouperlite.form.group.subs.label' => 'Subscribers:', - 'pl.grouperlite.form.group.subs.help' => 'Select subscribers to add to the group.', - 'pl.grouperlite.form.group.subs.placeholder' => 'Search subscribers', - 'pl.grouperlite.form.group.action.save' => 'Save Group', + 'pl.grouperlite.form.group.template.label' => 'Select a template', + 'pl.grouperlite.form.group.template.empty' => '(choose one)', + 'pl.grouperlite.form.group.name.label' => 'Display name', + 'pl.grouperlite.form.group.name.help' => 'Name is the label that identifies this group, and might change.', + 'pl.grouperlite.form.group.stem.label' => 'Create in this folder:', + 'pl.grouperlite.form.group.stem.help' => 'Enter a folder name.', + 'pl.grouperlite.form.group.description.label' => 'Description:', + 'pl.grouperlite.form.group.description.help' => 'Description contains notes about the group, which could include: what the group represents, why it was created, etc.', + 'pl.grouperlite.form.group.privs.label' => 'Privileges', + 'pl.grouperlite.form.group.privs.label.READ' => 'READ', + 'pl.grouperlite.form.group.privs.label.VIEW' => 'VIEW', + 'pl.grouperlite.form.group.privs.label.OPTIN' => 'OPTIN', + 'pl.grouperlite.form.group.privs.label.OPTOUT' => 'OPTOUT', + 'pl.grouperlite.form.group.privs.label.ATTRIBUTE_READ' => 'ATTRIBUTE READ', + 'pl.grouperlite.form.group.subs.label' => 'Subscribers:', + 'pl.grouperlite.form.group.subs.help' => 'Select subscribers to add to the group.', + 'pl.grouperlite.form.group.subs.placeholder' => 'Search subscribers', + 'pl.grouperlite.form.group.action.save' => 'Save Group', - 'pl.grouperlite.search.tags.text' => 'Search', + 'pl.grouperlite.search.tags.text' => 'Search', ); \ No newline at end of file diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 5525000..72e814e 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -88,7 +88,7 @@ public function isUserOwner(string $userId) { return 'F'; } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - isUserOwner: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -139,7 +139,7 @@ public function filteredMemberOfGroups(string $userId) { return $this->getFriendlyName($memberOfGroups); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - filteredMemberOfGroups: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -161,7 +161,7 @@ private function memberOfGroups(string $userId) { return $this->grouperAPI->getGrouperMemberOfGroups($args); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - memberOfGroups: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -181,15 +181,17 @@ public function groupDescriptions(string $groupName) { $args['conditions']['groupName'] = $groupName; $groupDescription = $this->grouperAPI->getGrouperGroupDescription($args); + $groupInfo = $this->getFriendlyName($groupDescription); + //make call to get attributes for group $grouperAtt = new GrouperAttribute(); $groupAttributes = $grouperAtt->getGroupAttributes($groupName); - $groupDescription[0]["attributes"] = $groupAttributes; - return $groupDescription; + $groupInfo[0]["attributes"] = $groupAttributes; + return $groupInfo; } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - groupDescriptions: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } @@ -216,7 +218,7 @@ public function leaveGroup(string $userId, string $groupName) { return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - leaveGroup: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -242,7 +244,7 @@ public function joinGroup(string $userId, string $groupName) { return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - joinGroup: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -263,12 +265,10 @@ public function ownerGroups(string $userId) { $args['conditions']['userId'] = $userId; $ownGroups = $this->grouperAPI->getOwnerGroups($args); - $ownerGroups = $this->getFriendlyName($ownGroups); - - return $ownerGroups; + return $this->getFriendlyName($ownGroups); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - ownerGroups: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -306,7 +306,7 @@ public function optinGroups(string $userId) { return $this->getFriendlyName($joinOrLeave); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - optinGroups: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -339,7 +339,7 @@ public function createGroup(string $userId, string $groupName, string $stemName, return $this->grouperAPI->createUpdateGroup($args); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - createGroup: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -361,7 +361,7 @@ public function getOwnerStems(string $userId) { return $this->grouperAPI->getOwnerStems($args); } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - getOwnerStems: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } @@ -405,7 +405,7 @@ public function getSearchedGroups(string $userId, string $searchCriteria, string return $returnResults; } catch (Exception $e) { - CakeLog::write('error', 'GrouperLite Model - getSearchedGroups: An error occurred'); + CakeLog::write('error', __METHOD__ . ': An error occurred'); throw $e; } } diff --git a/View/GrouperGroups/groupinfo.ctp b/View/GrouperGroups/groupinfo.ctp index c74a6b6..f20f1cc 100644 --- a/View/GrouperGroups/groupinfo.ctp +++ b/View/GrouperGroups/groupinfo.ctp @@ -13,7 +13,7 @@ $isuserowner = 'T';
-

Group:

+

Group: