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; + } } /**