Skip to content

Commit

Permalink
change for InCommon
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Sep 24, 2021
1 parent 48af698 commit 5196571
Show file tree
Hide file tree
Showing 4 changed files with 376 additions and 300 deletions.
233 changes: 118 additions & 115 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,10 @@ public function membersInGroup() {

try {
$details = $this->GrouperGroup->membersInGroup($scope);
// $this->set('membersingroup', $details);

} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

// $this->set('membersingroup', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.group-detail-members-failed'), array('key' => 'error'));
}

Expand Down Expand Up @@ -197,7 +195,7 @@ public function groupOwner() {

$data = $this->Paginator->paginate('GrouperGroup', $scope);

$finalData = $this->breakoutGroups($data);
$finalData = $this->breakoutGroups($data, 'admin');

$this->set('groupsowners', $finalData['adHocGroups']);
$this->set('wgowners', $finalData['workingGroups']);
Expand All @@ -215,7 +213,7 @@ public function groupOwner() {

$data = $this->Paginator->paginate('GrouperGroup', $scope);

$finalData = $this->breakoutGroups($data);
$finalData = $this->breakoutGroups($data, 'admin');

$this->set('groupsowners', $finalData['adHocGroups']);
$this->set('wgowners', $finalData['workingGroups']);
Expand All @@ -234,78 +232,6 @@ public function groupOwner() {
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}

/**
* Breakout Working Groups from AdHoc Groups for display purposes in UI.
*
* @param array $recordSet
* @param string $type
* @return array[]
*
*/
public function breakoutGroups(array $recordSet, $type='basic') {
//TODO - May move this logic down into the GrouperGroup model file, once all is agreed upon.
$wgData = array();
$notWGData = array();
foreach($recordSet as $record) {
if(isset($record['WGName'])) {
$wgData[] = $record;
} else {
$notWGData[] = $record;
}
}

if ($type == 'basic') {
//Need to surface Optout flag to top level of a Working Group
foreach($wgData as &$wgRec) {
$subCount = 0;
foreach($wgRec['Groups'] as $rec){
if(isset($rec['optOut'])) {
$wgRec['optOut'] = true;
$wgRec['workingGroupId'] = $rec['name'];
$wgRec['workingDesc'] = $this->hackDescription($rec['description']);
}
//Capturing record for incommon-collab since deleting a few lines below.
if ($rec['WGApp'] == 'incommon-collab') {
$recToDelete = $subCount;
}
$subCount += 1;
}
//Removing record with name of incommon-collab since means nothing to the user.
unset($wgRec['Groups'][$recToDelete]);
}
} elseif ($type == 'optin') {
foreach($wgData as &$wgRec) {
$wgRec['workingGroupId'] = $wgRec['Groups'][0]['name'];
$wgRec['workingDesc'] = $this->hackDescription($wgRec['Groups'][0]['description']);
unset($wgRec['Groups']);
}
}


return array(
'adHocGroups' => $notWGData,
'workingGroups' => $wgData
);
}

/**
* Eliminating canned description added by Grouper on creation of a WG in Grouper
*
* @param $description
* @return string
*
*/
private function hackDescription($description) {

//Verify description has period in it.
if(strpos($description, ".") === false) {
return $description;
}

$newString = substr($description, strpos($description, ".") + 1);
return trim($newString);

}

/**
* Returns all Groups that the User is a member of in Grouper
Expand Down Expand Up @@ -419,7 +345,7 @@ public function groupOptin() {
$data = $this->Paginator->paginate('GrouperGroup', $scope);
//$this->set('groupoptin', $data);

$finalData = $this->breakoutGroups($data,'optin');
$finalData = $this->breakoutGroups($data, 'optin');

$this->set('groupoptins', $finalData['adHocGroups']);
$this->set('wgoptins', $finalData['workingGroups']);
Expand All @@ -445,8 +371,8 @@ public function groupOptin() {
*
*/
public function groupCreateTemplate() {
if ($this->request->is('post')){
if(!$this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data)){
if ($this->request->is('post')) {
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 {
Expand All @@ -462,18 +388,18 @@ public function groupCreateTemplate() {
*
*/
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'));
}
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)){
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 {
Expand All @@ -488,13 +414,13 @@ public function groupCreate() {

//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'));
}
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));
}
Expand Down Expand Up @@ -614,30 +540,14 @@ function isAuthorized() {
return ($p[$this->action]);
}

private function getUserId($id) {
$args = array();
$args['conditions']['Identifier.co_person_id'] = $id;
$args['conditions']['Identifier.type'] = 'I2CollabPN';
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active;
$args['contain'] = false;

$Identifier = new Identifier();
$grouper_identifier = $Identifier->find('first', $args);

return $grouper_identifier['Identifier']['identifier'];
}

//##############################################################################################################
//TODO - Need to finish off the email list pages, once we get direction from I2
//##############################################################################################################
public function emaillistsOptin() {
$this->set('title', _txt('pl.grouperlite.title.emaillists-join'));

//Set initial settings for pagination
$scope = [
'userId' => $this->userId,
'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']),
'limit' => (isset($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']),
];

try {
Expand All @@ -658,15 +568,18 @@ public function emaillistsOptin() {
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}

public function emaillistsMember()
{
//##############################################################################################################
//TODO - Need to finish off the email list pages, once we get direction from I2
//##############################################################################################################

public function emaillistsMember() {
$this->set('title', _txt('pl.grouperlite.title.emaillists-member'));

//Set initial settings for pagination
$scope = [
'userId' => $this->userId,
'page' => (isset($this->passedArgs['page']) ? $this->passedArgs['page']: $this->paginate['page']),
'limit' => (isset($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']),
];

try {
Expand All @@ -688,7 +601,6 @@ public function emaillistsMember()
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}


public function emaillistsManage() {
$this->set('title', _txt('pl.grouperlite.title.emaillists-manage'));
// mock data
Expand Down Expand Up @@ -723,4 +635,95 @@ public function emaillistInfo() {
$this->set('grouperbaseurl', $this->Session->read('Plugin.Grouper.Api.url'));

}

private function getUserId($id) {
$args = array();
$args['conditions']['Identifier.co_person_id'] = $id;
$args['conditions']['Identifier.type'] = 'I2CollabPN';
$args['conditions']['Identifier.status'] = SuspendableStatusEnum::Active;
$args['contain'] = false;

$Identifier = new Identifier();
$grouper_identifier = $Identifier->find('first', $args);

return $grouper_identifier['Identifier']['identifier'];
}

/**
* Breakout Working Groups from AdHoc Groups for display purposes in UI.
*
* @param array $recordSet
* @param string $type 'basic' = view in Member page, 'admin' = view in Admin page, 'optin' = View in Optin page
* @return array[]
*
*/
private function breakoutGroups(array $recordSet, $type = 'basic') {
//TODO - May move this logic down into the GrouperGroup model file, once all is agreed upon.
$wgData = array();
$notWGData = array();
//Parse out the Working Groups from the Ad-hoc groups
foreach ($recordSet as $record) {
if (isset($record['WGName'])) {
$wgData[] = $record;
} else {
$notWGData[] = $record;
}
}

if ($type == 'basic' || $type == 'admin') {
//Need to surface Optout flag to top level of a Working Group
foreach ($wgData as &$wgRec) {
$subCount = 0;
foreach ($wgRec['Groups'] as $rec) {
if (isset($rec['optOut'])) {
$wgRec['optOut'] = true;
$wgRec['workingGroupId'] = $rec['name'];
$wgRec['workingDesc'] = $this->hackDescription($rec['description']);
}
//Capturing record for incommon-collab since deleting a few lines below.
if ($rec['WGApp'] == 'incommon-collab') {
$recToDelete = $subCount;
if ($type == 'basic') {
//Removing record with stem of 'incommon-collab' since displaying on groups Member page,
// will show on Admin page
unset($wgRec['Groups'][$recToDelete]);
}
}
$subCount += 1;
}

}
} elseif ($type == 'optin') {
//Working Groups that will show up on the Optin Page
foreach ($wgData as &$wgRec) {
$wgRec['workingGroupId'] = $wgRec['Groups'][0]['name'];
$wgRec['workingDesc'] = $this->hackDescription($wgRec['Groups'][0]['description']);
unset($wgRec['Groups']);
}
}

return array(
'adHocGroups' => $notWGData,
'workingGroups' => $wgData
);
}

/**
* Eliminating canned description added by Grouper on creation of a WG in Grouper
*
* @param $description
* @return string
*
*/
private function hackDescription($description) {

//Verify description has period in it.
if (strpos($description, ".") === false) {
return $description;
}

$newString = substr($description, strpos($description, ".") + 1);
return trim($newString);

}
}
Loading

0 comments on commit 5196571

Please sign in to comment.