From a47c55ccd586aa2612256673b62f7e15d9fd80ee Mon Sep 17 00:00:00 2001 From: axman Date: Thu, 11 Mar 2021 09:00:01 -0700 Subject: [PATCH] hand over work to ux --- Controller/GrouperGroupsController.php | 20 ++ Lib/GrouperApiAccess.php | 60 +++++- Model/GrouperGroup.php | 42 +++++ .../GrouperGroups/groupcreatetemplateform.ctp | 173 ++++++++++++++++++ 4 files changed, 294 insertions(+), 1 deletion(-) create mode 100644 View/GrouperGroups/groupcreatetemplateform.ctp diff --git a/Controller/GrouperGroupsController.php b/Controller/GrouperGroupsController.php index 14f8685..a3f12c0 100644 --- a/Controller/GrouperGroupsController.php +++ b/Controller/GrouperGroupsController.php @@ -313,6 +313,25 @@ public function groupOptin() { $this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId)); } + /** + * Create a new Grouper Group via Grouper Template + * Note: This is tighly coupled code to requirements, so view is hardcoded to reflect current reqs. Will need + * to update when reqs change or are updated!!! + * + */ + public function groupCreateTemplateForm() { + if ($this->request->is('post')){ + if(!$this->GrouperGroup->createGroupFromTemplate($this->userId, $this->request->data)){ + $this->Flash->set("Error in creating group!", array('key' => 'error')); + return $this->redirect(array('action' => 'groupoptin')); + } + } + //TODO - not sure if will be able to edit via Templates, so will need to fix once known. + $this->set('title', _txt('pl.grouperlite.title.groupcreate')); + //$this->set('grouperstems', $this->GrouperGroup->getOwnedStems($this->userId)); + } + + //TODO - Need to combine this form with code below for groupCreate public function groupCreateForm() { $this->set('title', _txt('pl.grouperlite.title.groupcreate')); @@ -420,6 +439,7 @@ function isAuthorized() { $p['groupcreate'] = true; $p['joingroup'] = true; $p['leavegroup'] = true; + $p['groupcreatetemplateform'] = true; $this->set('permissions', $p); diff --git a/Lib/GrouperApiAccess.php b/Lib/GrouperApiAccess.php index 7fa0ff4..041ac1a 100644 --- a/Lib/GrouperApiAccess.php +++ b/Lib/GrouperApiAccess.php @@ -417,12 +417,70 @@ public function getGrouperGroupDescription(array $queryData) { return array(); } + /** + * 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) { + //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) { + $inputFields[] = array('name' => $key, 'value' => $value); + } + + $groupToSave = array( + "WsRestGshTemplateExecRequest" => array( + "gshTemplateActAsSubjectLookup" => array( + "subjectSourceId" => "ldap", + "subjectId" => $userId + ), + "ownerStemLookup" => array( + "stemName" => "ref:incommon-collab" + ), + "ownerType" => "stem", + "configId" => "createNewWorkingGroup", + "inputs" => $inputFields + ) + ); + + 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; + } + /** * NOTE: This will probably changes once templates become available to use * * Create or Update a Group where User is Admin/Owner * - * @param array $queryData Array of conditions for querying + * @param array $queryData Array of conditions and data adding new Grouper Group * @return bool True if added or updated successful * @throws GrouperLiteException */ diff --git a/Model/GrouperGroup.php b/Model/GrouperGroup.php index 1ef04ee..b5fa597 100644 --- a/Model/GrouperGroup.php +++ b/Model/GrouperGroup.php @@ -395,6 +395,48 @@ public function optinGroups(array $conditions) { } } + /** + * Create a new Grouper Group using the Template methodology in Grouper + * + * @param string $userId Id of User + * @param array $groupData Data needed to create new Grouper Group via Template + * @return bool True if successfully created record + * @throws GrouperLiteException + * + */ + public function createGroupFromTemplate(string $userId, array $groupData) { + $this->initApi(); + + try { + //Need to massage incoming data to meet Grouper Template requirements + $fields = array( + 'gsh_input_isSympa', + 'gsh_input_isSympaModerated', + 'gsh_input_isOptin', + 'gsh_input_isConfluence', + 'gsh_input_isJira' + ); + // Template does not except true/false, so convert to string and send that way + foreach($fields as $field) { + ($groupData[$field] == '0') ? $groupData[$field] = 'false' : $groupData[$field] = 'true'; + } + + $args = array(); + $args['userId'] = $userId; + $args['data'] = $groupData; + + // Reset Session variable that shows if User is an owner or not + $this->resetUserOwner(); + + return $this->grouperAPI->createGroupFromTemplate($args); + + } catch (Exception $e) { + CakeLog::write('error', __METHOD__ . ': An error occurred'); + throw $e; + } + + } + /** * Creates a new Grouper Group * diff --git a/View/GrouperGroups/groupcreatetemplateform.ctp b/View/GrouperGroups/groupcreatetemplateform.ctp new file mode 100644 index 0000000..a4fb74d --- /dev/null +++ b/View/GrouperGroups/groupcreatetemplateform.ctp @@ -0,0 +1,173 @@ +extend('/GrouperGroups/base'); +$this->Html->addCrumb('Create a Template Group'); + +?> +
+
+
+
+
+ Form->create(false, array( + 'url' => array('controller' => 'groupergroups', 'action' => 'groupcreatetemplateform') + )); ?> + +
+
+ Form->label(false, "Working Group Extension", array( + 'for' => 'gsh_input_workingGroupExtension', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->input('gsh_input_workingGroupExtension', array( + 'label' => false, + 'class' => 'form-control', + 'required' => true, + 'maxlength' => '62', + 'id' => 'gsh_input_workingGroupExtension' + )); ?> +
+
+
+ Form->label(false, "Working Group Display Extension", array( + 'for' => 'gsh_input_workingGroupDisplayExtension', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->input('gsh_input_workingGroupDisplayExtension', array( + 'label' => false, + 'class' => 'form-control', + 'maxlength' => '62', + 'id' => 'gsh_input_workingGroupDisplayExtension' + )); ?> +
+
+
+ Form->label(false, "Working Group Description", array( + 'for' => 'gsh_input_workingGroupDescription', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->input('gsh_input_workingGroupDescription', array( + 'label' => false, + 'class' => 'form-control', + 'maxlength' => '62', + 'id' => 'gsh_input_workingGroupDescription' + )); ?> +
+
+
+ Form->label(false, "Enable Sympa for Group?", array( + 'for' => 'gsh_input_isSympa', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->checkbox('gsh_input_isSympa', array( + 'label' => false, + 'class' => 'form-control', + 'id' => 'gsh_input_isSympa' + )); ?> +
+
+
+ Form->label(false, "Sympa Domain", array( + 'for' => 'gsh_input_sympaDomain', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->radio( + 'gsh_input_sympaDomain', + array( + 'internet2' => 'internet2', + 'incommon' => 'incommon'), + array( + 'label' => false, + 'class' => 'form-control', + 'legend' => false, + 'id' => 'gsh_input_sympaDomain' + ) + ); ?> +
+
+
+ Form->label(false, "Is Sympa Moderated?", array( + 'for' => 'gsh_input_isSympaModerated', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->checkbox('gsh_input_isSympaModerated', array( + 'label' => false, + 'class' => 'form-control', + 'id' => 'gsh_input_isSympaModerated' + )); ?> +
+
+
+ Form->label(false, "Is Group Optin?", array( + 'for' => 'gsh_input_isOptin', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->checkbox('gsh_input_isOptin', array( + 'label' => false, + 'class' => 'form-control', + 'id' => 'gsh_input_isOptin' + )); ?> +
+
+
+ Form->label(false, "Days for Attestation", array( + 'for' => 'gsh_input_attestationDays', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->input('gsh_input_attestationDays', array( + 'label' => false, + 'class' => 'form-control', + 'type' => 'number', + 'default' => '30', + 'min' => '30', + 'max' => '365', + 'id' => 'gsh_input_attestationDays' + )); ?> +
+
+
+ Form->label(false, "Add Confluence?", array( + 'for' => 'gsh_input_isConfluence', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->checkbox('gsh_input_isConfluence', array( + 'label' => false, + 'class' => 'form-control', + 'id' => 'gsh_input_isConfluence' + )); ?> +
+
+
+ Form->label(false, "Add Jira?", array( + 'for' => 'gsh_input_isJira', + 'class' => "col-sm-3 col-form-label" + )); ?> +
+ Form->checkbox('gsh_input_isJira', array( + 'label' => false, + 'class' => 'form-control', + 'id' => 'gsh_input_isJira' + )); ?> +
+
+
+
+ Form->button(_txt('pl.grouperlite.form.group.action.save'), array( + 'type' => 'submit', + 'class' => 'btn btn-grouper btn-primary btn-lg btn-raised' + )); ?> +
+
+
+ Form->end(); ?> +
+
+
\ No newline at end of file