Skip to content

Commit

Permalink
Merged feature/ICPCO-113 into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Mar 24, 2021
2 parents 642fc1d + 6f1ef7a commit 2b2abc2
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 79 deletions.
63 changes: 49 additions & 14 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
}

/**
Expand Down Expand Up @@ -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'])) {
Expand Down Expand Up @@ -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
*
Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -523,5 +556,7 @@ public function emaillistInfo() {
'enabled' => 'T',
'attributes' => array()
));
$this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url'));

}
}
79 changes: 65 additions & 14 deletions Lib/GrouperApiAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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";
Expand All @@ -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
*
Expand All @@ -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(
Expand All @@ -482,7 +532,8 @@ public function createUpdateGroup(array $queryData) {
array(
"wsGroup" => array(
"description" => $groupDescription,
"name" => $newGroupToSave
"name" => $newGroupToSave,
"displayExtension" => $groupName
),
"wsGroupLookup" => array(
"groupName" => $groupDescription
Expand Down
49 changes: 37 additions & 12 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -84,6 +85,7 @@ public function isUserOwner(string $userId) {
}
}


/**
* Used to instantiate API class
*
Expand Down Expand Up @@ -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 {
Expand All @@ -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');
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions View/GrouperGroups/emaillistinfo.ctp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php $this->extend('/GrouperGroups/base'); ?>
<?php
$baseUrl = 'https://grouper.staging.at.internet2.edu/grouper/';
$path = 'grouperUi/app/UiV2Main.index';
$baseUrl = $grouperbaseurl;
$path = '/grouper/grouperUi/app/UiV2Main.index';
$groupOperation = '?operation=UiV2Group.viewGroup&groupId=';
$groupUrlBase = $baseUrl . $path . $groupOperation;
$attrOperation = '?operation=UiV2AttributeDefName.viewAttributeDefName&attributeDefNameId=';
Expand Down
36 changes: 35 additions & 1 deletion View/GrouperGroups/groupcreate.ctp
Original file line number Diff line number Diff line change
@@ -1 +1,35 @@
Group Created!
<?php
$this->extend('/GrouperGroups/base');
$this->Html->addCrumb('Create a Group');

$model = $this->name;
?>
<hr />
<div class="mt-4">
<div class="row">
<div class="col-lg-9 col-xs-12 col-xl-6">
<div class="create-group">
<div>Stems coming in are: Id=stem</div>
<?php foreach($grouperstems as $grouperstem) : ?>
<div>Value=<?php echo $grouperstem['name'] ?> Display=<?php echo $grouperstem['displayName'] ?></div>
<?php endforeach; ?>

<?php echo $this->Form->create(false, array(
'url' => array('controller' => 'groupergroups', 'action' => 'groupcreate')
)); ?>
<?php
if (!empty($this->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");
}
?>
<?php echo $this->Form->end(); ?>
</div>
</div>
</div>
</div>
Loading

0 comments on commit 2b2abc2

Please sign in to comment.