diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 4dd3f1f..e28a23b 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -137,6 +137,8 @@ public function groupInfo() { $this->set('groupergroupssubscribers', array()); $this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error')); } + + $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url')); } /** @@ -286,8 +288,8 @@ public function groupOptin() { //Set initial settings for pagination $scope = [ 'userId' => $this->userId, - 'page' => ($this->passedArgs['page'] ? $this->passedArgs['page']: $this->paginate['page']), - 'limit' => ($this->passedArgs['limit'] ? $this->passedArgs['limit']: $this->paginate['limit']), + 'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']), + 'limit' => (isset($this->passedArgs['limit']) ? $this->passedArgs['limit']: $this->paginate['limit']), ]; if (isset($this->request->data['search'])) { @@ -337,31 +339,62 @@ public function groupOptin() { * Editing via a template will not be supported in this version of the plugin - Bill Kaufman * */ - public function groupCreateTemplateForm() { + public function groupCreateTemplate() { if ($this->request->is('post')){ - if(!$this->GrouperGroup->createGroupFromTemplate($this->userId, $this->request->data)){ + if(!$this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data)){ $this->Flash->set("Error in creating group!", array('key' => 'error')); return $this->redirect(array('action' => 'groupoptin')); + } else { + $this->Flash->set("Success in creating group!", array('key' => 'success')); + return $this->redirect(array('action' => 'groupoptin')); } } $this->set('title', _txt('pl.grouperlite.title.templatecreate')); } + /** + * Delete a Grouper Group via Grouper Template + * + */ + public function groupDeleteTemplate() { + if(!$this->GrouperGroup->deleteGroupWithTemplate($this->userId, $this->request->data)){ + $this->Flash->set("Error in deleting group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupoptin')); + } + + $this->set('title', _txt('pl.grouperlite.title.templatecreate')); + } + + + public function groupCreate() { + if ($this->request->is('post')){ + if(!$this->GrouperGroup->createUpdateGroup($this->userId, $this->request->data)){ + $this->Flash->set("Error in creating group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupOwner')); + } else { + $this->Flash->set("Your Group has been created!", array('key' => 'success')); + return $this->redirect(array('action' => 'groupOwner')); + } + } - //TODO - Need to combine this form with code below for groupCreate - public function groupCreateForm() { $this->set('title', _txt('pl.grouperlite.title.groupcreate')); $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); } - public function groupCreate() { - $name = urldecode($this->request->data['name']); - $set = urldecode($this->request->data['set']); - $descr = urldecode($this->request->data['description']); - // Debugger::dump($this->request->data); - $this->set('groupergroupadded', $this->GrouperGroup->createGroup($this->userId, $name, $set, $descr)); + //TODO - Finish this call + public function groupDelete() { + if(!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)){ + $this->Flash->set("Error in deleting group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupOwner')); + } else { + $this->Flash->set("Your Group has been deleted!", array('key' => 'success')); + return $this->redirect(array('action' => 'groupOwner')); + } + + $this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); } + /** * Process to join a group displayed on the "Optin" page * @@ -451,11 +484,11 @@ function isAuthorized() { $p['emaillistsmember'] = true; $p['emaillistsmanage'] = true; $p['emaillistsinfo'] = true; - $p['groupcreateform'] = true; $p['groupcreate'] = true; + $p['groupdelete'] = true; $p['joingroup'] = true; $p['leavegroup'] = true; - $p['groupcreatetemplateform'] = true; + $p['groupcreatetemplate'] = true; $this->set('permissions', $p); @@ -523,5 +556,7 @@ public function emaillistInfo() { 'enabled' => 'T', 'attributes' => array() )); + $this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url')); + } } diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 87d1de4..bea20de 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -395,20 +395,19 @@ public function getGrouperGroupDescription(array $queryData) { } /** - * Method used to create a new Group in Grouper via the Template method. + * Method used to CREATE a new Group in Grouper via the Template method. * * @param array $queryData Array of conditions and data adding new Grouper Group * @return bool True if added successfully * @throws GrouperLiteException * */ - public function createGroupFromTemplate(array $queryData) { + public function createGroupWithTemplate(array $queryData) { //Currently only supporting create group, need to test if update a group will work! $data = $queryData['data']; $userId = $queryData['userId']; - //Build request logic $inputFields = array(); foreach($data as $key => $value) { @@ -430,9 +429,56 @@ public function createGroupFromTemplate(array $queryData) { ) ); - echo json_encode($groupToSave); - exit(); - //TODO - take out exit and finish by running an example through + $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); + $connectionUrl = "{$this->config['fullUrl']}/gshTemplateExec"; + + try { + $results = $this->http->sendRequest('POST', $connectionUrl, json_encode($groupToSave)); + + if (isset($results['WsGshTemplateExecResult']['resultMetadata']['resultCode'])) { + if (stripos($results['WsGshTemplateExecResult']['resultMetadata']['resultCode'], "SUCCESS", 0) !== false) { + return true; + } + } + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + return false; + } + + /** + * Method used to DELETE a Group in Grouper via the Template method. + * + * @param array $queryData Array of conditions and data adding new Grouper Group + * @return bool True if deleted successfully + * @throws GrouperLiteException + * + */ + public function deleteGroupWithTemplate(array $queryData) { + + $workingGroupExt = $queryData['workingGroupExt']; + $userId = $queryData['userId']; + + $groupToDelete = array( + "WsRestGshTemplateExecRequest" => array( + "gshTemplateActAsSubjectLookup" => array( + "subjectSourceId" => "ldap", + "subjectId" => $userId + ), + "ownerStemLookup" => array( + "stemName" => "ref:incommon-collab" + ), + "ownerType" => "stem", + "configId" => "createWorkingGroup", + "inputs" => array( + array( + "name" => "gsh_input_workingGroupExtension", + "value" => $workingGroupExt + ) + ) + ) + ); $this->http->setHeader(array('Content-Type' => 'application/json', 'Accept' => 'application/json')); $connectionUrl = "{$this->config['fullUrl']}/gshTemplateExec"; @@ -453,7 +499,7 @@ public function createGroupFromTemplate(array $queryData) { } /** - * NOTE: This will probably changes once templates become available to use + * For creating/updating Ad-Hoc groups not using the Grouper Template format * * Create or Update a Group where User is Admin/Owner * @@ -462,15 +508,19 @@ public function createGroupFromTemplate(array $queryData) { * @throws GrouperLiteException */ public function createUpdateGroup(array $queryData) { - //TODO - Need to add checking for missing ':' - //Currently only supporting create group, need to test if update a group will work! + //TODO Currently only supporting create group, need to test if update a group will work! - $groupName = $queryData['groupName']; - $stemName = $queryData['stemName']; + $groupName = htmlentities($queryData['name']); + $stemName = htmlentities($queryData['stem']); $userId = $queryData['userId']; - $groupDescription = $queryData['groupDescription']; + $groupDescription = htmlentities($queryData['description']); + $privileges = $queryData['privileges']; + + //Group name may be in "friendly" format, so need to do some small conversions before saving. + $newGroupName = ucfirst(strtolower($groupName)); + $newGroupName = str_replace(' ', '', $newGroupName); - $newGroupToSave = $stemName . $groupName; + $newGroupToSave = "$stemName:$newGroupName"; //Build request logic $groupToSave = array( @@ -482,7 +532,8 @@ public function createUpdateGroup(array $queryData) { array( "wsGroup" => array( "description" => $groupDescription, - "name" => $newGroupToSave + "name" => $newGroupToSave, + "displayExtension" => $groupName ), "wsGroupLookup" => array( "groupName" => $groupDescription diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index e8d14e2..e4f5995 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -47,6 +47,7 @@ class GrouperGroup extends GrouperLiteAppModel /** @var string Group whose members can create Groups via Template process*/ private $templateCreationGroup = 'ref:workinggroupadmins'; + /** * Verifies if user is an owner/admin of a group and then stores results in Session. * Session variable is reset on Group Creation and Group Deletion @@ -84,6 +85,7 @@ public function isUserOwner(string $userId) { } } + /** * Used to instantiate API class * @@ -413,7 +415,7 @@ public function isTemplateUser(string $userId) { * @throws GrouperLiteException * */ - public function createGroupFromTemplate(string $userId, array $groupData) { + public function createGroupWithTemplate(string $userId, array $groupData) { $this->initApi(); try { @@ -437,7 +439,7 @@ public function createGroupFromTemplate(string $userId, array $groupData) { // Reset Session variable that shows if User is an owner or not $this->resetUserOwner(); - return $this->grouperAPI->createGroupFromTemplate($args); + return $this->grouperAPI->createGroupWithTemplate($args); } catch (Exception $e) { CakeLog::write('error', __METHOD__ . ': An error occurred'); @@ -447,26 +449,49 @@ public function createGroupFromTemplate(string $userId, array $groupData) { } /** - * Creates a new Grouper Group + * Delete a Grouper Group using the Template methodology in Grouper + * + * @param string $userId Id of User + * @param array $groupData Data needed to delete a Grouper Group via Template + * @return bool True if successfully deleted record + * @throws GrouperLiteException + * + */ + public function deleteGroupWithTemplate(string $userId, array $groupData) { + $this->initApi(); + + try { + $args = array(); + $args['userId'] = $userId; + $args['workingGroupExt'] = $groupData['workingGroupExt']; + + // Reset Session variable that shows if User is an owner or not + $this->resetUserOwner(); + + return $this->grouperAPI->deleteGroupWithTemplate($args); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + + } + + /** + * Creates/Updates a new Grouper Group not Template related * * @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 + * @param array $data Data from form to Save in Grouper as a Group * @return bool True if saved | False if already created * @throws GrouperLiteException * */ - public function createGroup(string $userId, string $groupName, string $stemName, string $groupDesc) { + public function createUpdateGroup(string $userId, array $data) { $this->initApi(); try { - $args = array(); - $args['groupType'] = 'Optins'; + $args = $data; $args['userId'] = $userId; - $args['groupName'] = $groupName; - $args['stemName'] = $stemName; - $args['groupDescription'] = $groupDesc; // Reset Session variable that shows if User is an owner or not $this->resetUserOwner(); diff --git a/View/GrouperGroups/emaillistinfo.ctp b/View/GrouperGroups/emaillistinfo.ctp index 61f6e35..daa4379 100644 --- a/View/GrouperGroups/emaillistinfo.ctp +++ b/View/GrouperGroups/emaillistinfo.ctp @@ -1,7 +1,7 @@ extend('/GrouperGroups/base'); ?> extend('/GrouperGroups/base'); +$this->Html->addCrumb('Create a Group'); + +$model = $this->name; +?> +
+
+
+
+
+
Stems coming in are: Id=stem
+ +
Value= Display=
+ + + Form->create(false, array( + 'url' => array('controller' => 'groupergroups', 'action' => 'groupcreate') + )); ?> + plugin)) { + if (file_exists(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc")) { + include(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc"); + } elseif (file_exists(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc")) { + include(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc"); + } + } else { + include(APP . "View/" . $model . "/groupfields.inc"); + } + ?> + Form->end(); ?> +
+
+
+
\ No newline at end of file diff --git a/View/GrouperGroups/groupcreateform.ctp b/View/GrouperGroups/groupcreateform.ctp deleted file mode 100644 index c633d0f..0000000 --- a/View/GrouperGroups/groupcreateform.ctp +++ /dev/null @@ -1,30 +0,0 @@ -extend('/GrouperGroups/base'); -$this->Html->addCrumb('Create a Group'); - -$model = $this->name; -?> -
-
-
-
-
- Form->create(false, array( - 'url' => array('controller' => 'groupergroups', 'action' => 'groupcreate') - )); ?> - plugin)) { - if (file_exists(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc")) { - include(APP . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc"); - } elseif (file_exists(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc")) { - include(LOCAL . "Plugin/" . $this->plugin . "/View/" . $model . "/groupfields.inc"); - } - } else { - include(APP . "View/" . $model . "/groupfields.inc"); - } - ?> - Form->end(); ?> -
-
-
-
\ No newline at end of file diff --git a/View/GrouperGroups/groupcreatetemplateform.ctp b/View/GrouperGroups/groupcreatetemplate.ctp similarity index 96% rename from View/GrouperGroups/groupcreatetemplateform.ctp rename to View/GrouperGroups/groupcreatetemplate.ctp index a0b2e9c..c7db590 100644 --- a/View/GrouperGroups/groupcreatetemplateform.ctp +++ b/View/GrouperGroups/groupcreatetemplate.ctp @@ -10,7 +10,7 @@ $model = $this->name;
Form->create(false, array( - 'url' => array('controller' => 'groupergroups', 'action' => 'groupcreatetemplateform') + 'url' => array('controller' => 'groupergroups', 'action' => 'groupcreatetemplate') )); ?> plugin)) { diff --git a/View/GrouperGroups/groupfields.inc b/View/GrouperGroups/groupfields.inc index f0b6322..ceb7111 100644 --- a/View/GrouperGroups/groupfields.inc +++ b/View/GrouperGroups/groupfields.inc @@ -1,5 +1,5 @@