Skip to content

Commit

Permalink
Merged feature/ICPCO-26 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Mar 11, 2021
2 parents c37da77 + a47c55c commit e9741dc
Show file tree
Hide file tree
Showing 4 changed files with 294 additions and 1 deletion.
20 changes: 20 additions & 0 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,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'));
Expand Down Expand Up @@ -436,6 +455,7 @@ function isAuthorized() {
$p['groupcreate'] = true;
$p['joingroup'] = true;
$p['leavegroup'] = true;
$p['groupcreatetemplateform'] = true;

$this->set('permissions', $p);

Expand Down
60 changes: 59 additions & 1 deletion Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
42 changes: 42 additions & 0 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
173 changes: 173 additions & 0 deletions View/GrouperGroups/groupcreatetemplateform.ctp
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
<?php
$this->extend('/GrouperGroups/base');
$this->Html->addCrumb('Create a Template Group');

?>
<hr />
<div class="mt-4">
<div class="row">
<div class="col-lg-9 col-xs-12 col-xl-6">
<div class="create-group">
<?php echo $this->Form->create(false, array(
'url' => array('controller' => 'groupergroups', 'action' => 'groupcreatetemplateform')
)); ?>

<fieldset id="form" class="">
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Working Group Extension", array(
'for' => 'gsh_input_workingGroupExtension',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->input('gsh_input_workingGroupExtension', array(
'label' => false,
'class' => 'form-control',
'required' => true,
'maxlength' => '62',
'id' => 'gsh_input_workingGroupExtension'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Working Group Display Extension", array(
'for' => 'gsh_input_workingGroupDisplayExtension',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->input('gsh_input_workingGroupDisplayExtension', array(
'label' => false,
'class' => 'form-control',
'maxlength' => '62',
'id' => 'gsh_input_workingGroupDisplayExtension'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Working Group Description", array(
'for' => 'gsh_input_workingGroupDescription',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->input('gsh_input_workingGroupDescription', array(
'label' => false,
'class' => 'form-control',
'maxlength' => '62',
'id' => 'gsh_input_workingGroupDescription'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Enable Sympa for Group?", array(
'for' => 'gsh_input_isSympa',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->checkbox('gsh_input_isSympa', array(
'label' => false,
'class' => 'form-control',
'id' => 'gsh_input_isSympa'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Sympa Domain", array(
'for' => 'gsh_input_sympaDomain',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->radio(
'gsh_input_sympaDomain',
array(
'internet2' => 'internet2',
'incommon' => 'incommon'),
array(
'label' => false,
'class' => 'form-control',
'legend' => false,
'id' => 'gsh_input_sympaDomain'
)
); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Is Sympa Moderated?", array(
'for' => 'gsh_input_isSympaModerated',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->checkbox('gsh_input_isSympaModerated', array(
'label' => false,
'class' => 'form-control',
'id' => 'gsh_input_isSympaModerated'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Is Group Optin?", array(
'for' => 'gsh_input_isOptin',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->checkbox('gsh_input_isOptin', array(
'label' => false,
'class' => 'form-control',
'id' => 'gsh_input_isOptin'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Days for Attestation", array(
'for' => 'gsh_input_attestationDays',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->input('gsh_input_attestationDays', array(
'label' => false,
'class' => 'form-control',
'type' => 'number',
'default' => '30',
'min' => '30',
'max' => '365',
'id' => 'gsh_input_attestationDays'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Add Confluence?", array(
'for' => 'gsh_input_isConfluence',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->checkbox('gsh_input_isConfluence', array(
'label' => false,
'class' => 'form-control',
'id' => 'gsh_input_isConfluence'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-light">
<?php echo $this->Form->label(false, "Add Jira?", array(
'for' => 'gsh_input_isJira',
'class' => "col-sm-3 col-form-label"
)); ?>
<div class="col-sm-9">
<?php echo $this->Form->checkbox('gsh_input_isJira', array(
'label' => false,
'class' => 'form-control',
'id' => 'gsh_input_isJira'
)); ?>
</div>
</div>
<div class="form-group row py-2 bg-lighter">
<div class="col-sm-9 offset-sm-3">
<?php echo $this->Form->button(_txt('pl.grouperlite.form.group.action.save'), array(
'type' => 'submit',
'class' => 'btn btn-grouper btn-primary btn-lg btn-raised'
)); ?>
</div>
</div>
</fieldset>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>

0 comments on commit e9741dc

Please sign in to comment.