From a4cb71f4d531ed9526f6f76d443cedda338c3fe9 Mon Sep 17 00:00:00 2001 From: axman Date: Mon, 1 Feb 2021 10:38:38 -0700 Subject: [PATCH] Changes to support Optin completed --- Controller/GrouperGroupsController.php | 125 +++++++++++++++---------- Model/GrouperGroup.php | 88 ++++++++++------- 2 files changed, 125 insertions(+), 88 deletions(-) diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index a7bf4df..2b79a7c 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -25,7 +25,7 @@ public function beforeFilter() { } } else { if (!isset($this->passedArgs['glid'])) { - //If user goes directly to GrouperLite url, will be sent to main index since they did not choose an + //If user links directly to GrouperLite url, will be redirected to main index to choose an //appropriate Dashboard Widget. return $this->redirect('/'); } @@ -33,6 +33,9 @@ public function beforeFilter() { } } + /** + * Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php + */ private function setConnection() { $this->Session->write('Plugin.Grouper.id', $this->passedArgs['glid']); @@ -45,18 +48,17 @@ private function setConnection() { $this->Session->write('Plugin.Grouper.pass', $connectionInfo['CoGrouperLite']['connPass']); } + /** + * No true Index page, so sent to default page of Optin + * + * @return CakeResponse Redirect to Optin page + */ public function index() { return $this->redirect( array('controller' => 'GrouperGroups', 'action' => 'groupoptin') ); } - public function groupUser() { - //TODO - Not being used, can delete? - $this->set('title', _txt('pl.grouperlite.title.root')); - - $this->set('groupergroupsmember', $this->GrouperGroup->optinGroups($this->userId)); - } public function groupInfo() { $name = urldecode($this->request->query['groupname']); @@ -80,8 +82,8 @@ public function groupOwner() { } /** - * Returns all Groups that the User is a member of in Grouper. - * This includes Optin groups that the User joined + * Returns all Groups that the User is a member of in Grouper + * This includes self-joined Optin Groups, as well as required Groups User cannot leave * */ public function groupMember() { @@ -102,6 +104,9 @@ public function groupMember() { } } + /** + * Display all Groups a User can Join + */ public function groupOptin() { $this->set('title', _txt('pl.grouperlite.title.groupoptin')); @@ -127,45 +132,6 @@ public function groupOptin() { } } - public function emailListsOptin() { - $this->set('title', _txt('pl.grouperlite.title.emaillists')); - // mock data - $this->set('group', array( - 'member' => true, - 'name' => 'Email List 1', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T' - )); - } - - public function emailListsManaged() { - $this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged')); - // mock data - $this->set('group', array( - 'member' => true, - 'name' => 'Email List 1', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T' - )); - } - - public function emailListInfo() { - $this->set('title', _txt('pl.grouperlite.title.emaillistsinfo')); - // mock data - $this->set('groupergroupsdetail', array( - 'member' => true, - 'uuid' => 'abc123xyz789', - 'displayExtension' => 'email-list-1', - 'extension' => 'email-list-1', - 'displayName' => 'Email List 1', - 'typeOfGroup' => 'list', - 'name' => 'Email List 1', - 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', - 'enabled' => 'T', - 'attributes' => array() - )); - } - //TODO - Need to combine this form with code below for groupCreate public function groupCreateForm() { $this->set('title', _txt('pl.grouperlite.title.groupcreate')); @@ -180,31 +146,47 @@ public function groupCreate() { $this->set('groupergroupadded', $this->GrouperGroup->createGroup($this->userId, $name, $set, $descr)); } + /** + * Process to join a group displayed on the "Optin" page + * + * @return CakeResponse Redirect back to "Optin" page + */ public function joinGroup() { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; + if($this->GrouperGroup->joinGroup($this->userId, $name)) { $this->Flash->success(_txt('pl.grouperlite.message.flash.join-group-success')); } else { $this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-failed')); } - return $this->redirect(array('action' => 'groupoptin')); + + } else { + $this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-error')); } - $this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-error')); + return $this->redirect(array('action' => 'groupoptin')); } + /** + * Process to leave a group displayed on the "Member Of" page + * + * @return CakeResponse Redirect back to "Member Of" page + */ public function leaveGroup() { if ($this->request->is('post')) { $name = $this->request->data['GroupName']; + if($this->GrouperGroup->leaveGroup($this->userId, $name)) { $this->Flash->success(_txt('pl.grouperlite.message.flash.leave-group-success')); } else { $this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-failed')); } - return $this->redirect(array('action' => 'groupoptin')); + } else { + $this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-error')); } - $this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-error')); + + return $this->redirect(array('action' => 'groupmember')); } /** @@ -250,4 +232,43 @@ function isAuthorized() { return ($p[$this->action]); } + public function emailListsOptin() { + $this->set('title', _txt('pl.grouperlite.title.emaillists')); + // mock data + $this->set('group', array( + 'member' => true, + 'name' => 'Email List 1', + 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', + 'enabled' => 'T' + )); + } + + public function emailListsManaged() { + $this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged')); + // mock data + $this->set('group', array( + 'member' => true, + 'name' => 'Email List 1', + 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', + 'enabled' => 'T' + )); + } + + public function emailListInfo() { + $this->set('title', _txt('pl.grouperlite.title.emaillistsinfo')); + // mock data + $this->set('groupergroupsdetail', array( + 'member' => true, + 'uuid' => 'abc123xyz789', + 'displayExtension' => 'email-list-1', + 'extension' => 'email-list-1', + 'displayName' => 'Email List 1', + 'typeOfGroup' => 'list', + 'name' => 'Email List 1', + 'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', + 'enabled' => 'T', + 'attributes' => array() + )); + } + } diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index f6c3e54..aa84d32 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -35,7 +35,7 @@ */ class GrouperGroup extends GrouperLiteAppModel { - //TODO - Add input validation, possibly??? + /** @var string $name used by CakePHP for locating model */ public $name = "GrouperGroup"; @@ -59,22 +59,12 @@ private function initApi() { } } - - private function memberOfGroups($userId) { - $this->initApi(); - - $args = array(); - $args['conditions']['userId'] = $userId; - - return $this->grouperAPI->getGrouperMemberOfGroups($args); - } - /** * Return all Groups that a User belongs to in Grouper. - * Will also compare against Optin Groups to determine if User given option to Optout of the Group + * Will also add Optin Groups and flag them as joined so can display Optout option in UI. * * @param string $userId Id of User - * @return array Records of Groups in Grouper that the User belongs to + * @return array Records of Groups from Grouper that the User belongs to * @throws GrouperLiteException * */ @@ -103,6 +93,22 @@ public function filteredMemberOfGroups(string $userId) { return $this->getFriendlyName($memberOfGroups); } + /** + * Internal process used by other functions to fetch Groups the User is a member of + * + * @param string $userId Id of User + * @return array Records of Groups from Grouper that the User belongs to + * @throws GrouperLiteException + * + */ + private function memberOfGroups(string $userId) { + + $args = array(); + $args['conditions']['userId'] = $userId; + + return $this->grouperAPI->getGrouperMemberOfGroups($args); + } + public function groupDescriptions($groupName) { $this->initApi(); @@ -120,7 +126,16 @@ public function groupDescriptions($groupName) { return $groupDescription; } - public function leaveGroup($userId, $groupName) { + /** + * Process for User to Leave a Group + * + * @param string $userId Id of User + * @param string $groupName Name of Group Leaving + * @return bool True|False + * @throws GrouperLiteException + * + */ + public function leaveGroup(string $userId, string $groupName) { $this->initApi(); $args = array(); @@ -131,7 +146,16 @@ public function leaveGroup($userId, $groupName) { return $this->grouperAPI->grouperGroupLeaveOrJoin($args); } - public function joinGroup($userId, $groupName) { + /** + * Process for User to Join a Group + * + * @param string $userId Id of User + * @param string $groupName Name of Group Leaving + * @return bool True|False + * @throws GrouperLiteException + * + */ + public function joinGroup(string $userId, string $groupName) { $this->initApi(); $args = array(); @@ -156,9 +180,9 @@ public function ownerGroups($userId) { } /** - * Get all Groups with Optin attribute set - * Will Match up with Groups User is a member of to determine which Optin groups the user is - * already a member of. + * Display 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 * * @param string $userId Id of user * @return array Listing of Optin groups available in Grouper @@ -172,25 +196,20 @@ public function optinGroups(string $userId) { $joinOrLeave = $this->grouperAPI->getOptinGroups($args); $userGroups = $this->memberOfGroups($userId); - if(isset($joinOrLeave['errorMessage'])){ - return $joinOrLeave; - } - //See if Optin group match any of the groups belong to already. - foreach ($joinOrLeave as &$groupsJoL) { - foreach ($userGroups as $key => $value) { - $groupsJoL['member'] = false; - if ($groupsJoL['name'] == $value['name']) { + //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!! - $groupsJoL['member'] = true; - //I am removing entry for faster processing of loop - unset($userGroups[$key]); + //Removing as already a member of. + unset($joinOrLeave[$key]); break; } } } - $groupsToOptin = $this->getFriendlyName($joinOrLeave); - return $groupsToOptin; + + return $this->getFriendlyName($joinOrLeave); } public function createGroup($userId, $groupName, $stemName, $groupDesc) { @@ -217,7 +236,7 @@ public function getOwnerStems($userId) { /** * Search for Groups/Lists related to Search term. - * Will import all records the user can see and then do search here rather than call Grouper WS Search + * Will import all records the user can see and then do search in this code rather than call Grouper WS Search * 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. * @@ -225,13 +244,11 @@ public function getOwnerStems($userId) { * @param $searchCriteria * @param $page * @return array + * @throws GrouperLiteException Captured in Controller */ public function getSearchedGroups($userId, $searchCriteria, $page) { $this->initApi(); - $args = array(); - $args['conditions']['userId'] = $userId; - if($page == 'groupOptin') { $pageResults = $this->optinGroups($userId); } elseif ($page == 'groupOwner') { @@ -263,7 +280,6 @@ public function getSearchedGroups($userId, $searchCriteria, $page) { * */ private function getFriendlyName(array $groups) { - $this->initApi(); foreach ($groups as &$group) { $group['friendlyName'] = $group['displayName'];