Skip to content

Commit

Permalink
Changes to support Optin completed
Browse files Browse the repository at this point in the history
  • Loading branch information
axel committed Feb 1, 2021
1 parent 0a73b09 commit a4cb71f
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 88 deletions.
125 changes: 73 additions & 52 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,17 @@ public function beforeFilter() {
}
} else {
if (!isset($this->passedArgs['glid'])) {
//If user goes directly to GrouperLite url, will be sent to main index since they did not choose an
//If user links directly to GrouperLite url, will be redirected to main index to choose an
//appropriate Dashboard Widget.
return $this->redirect('/');
}
$this->setConnection();
}
}

/**
* Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php
*/
private function setConnection() {
$this->Session->write('Plugin.Grouper.id', $this->passedArgs['glid']);

Expand All @@ -45,18 +48,17 @@ private function setConnection() {
$this->Session->write('Plugin.Grouper.pass', $connectionInfo['CoGrouperLite']['connPass']);
}

/**
* No true Index page, so sent to default page of Optin
*
* @return CakeResponse Redirect to Optin page
*/
public function index() {
return $this->redirect(
array('controller' => 'GrouperGroups', 'action' => 'groupoptin')
);
}

public function groupUser() {
//TODO - Not being used, can delete?
$this->set('title', _txt('pl.grouperlite.title.root'));

$this->set('groupergroupsmember', $this->GrouperGroup->optinGroups($this->userId));
}

public function groupInfo() {
$name = urldecode($this->request->query['groupname']);
Expand All @@ -80,8 +82,8 @@ public function groupOwner() {
}

/**
* Returns all Groups that the User is a member of in Grouper.
* This includes Optin groups that the User joined
* Returns all Groups that the User is a member of in Grouper
* This includes self-joined Optin Groups, as well as required Groups User cannot leave
*
*/
public function groupMember() {
Expand All @@ -102,6 +104,9 @@ public function groupMember() {
}
}

/**
* Display all Groups a User can Join
*/
public function groupOptin() {
$this->set('title', _txt('pl.grouperlite.title.groupoptin'));

Expand All @@ -127,45 +132,6 @@ public function groupOptin() {
}
}

public function emailListsOptin() {
$this->set('title', _txt('pl.grouperlite.title.emaillists'));
// mock data
$this->set('group', array(
'member' => true,
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T'
));
}

public function emailListsManaged() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged'));
// mock data
$this->set('group', array(
'member' => true,
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T'
));
}

public function emailListInfo() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsinfo'));
// mock data
$this->set('groupergroupsdetail', array(
'member' => true,
'uuid' => 'abc123xyz789',
'displayExtension' => 'email-list-1',
'extension' => 'email-list-1',
'displayName' => 'Email List 1',
'typeOfGroup' => 'list',
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T',
'attributes' => array()
));
}

//TODO - Need to combine this form with code below for groupCreate
public function groupCreateForm() {
$this->set('title', _txt('pl.grouperlite.title.groupcreate'));
Expand All @@ -180,31 +146,47 @@ public function groupCreate() {
$this->set('groupergroupadded', $this->GrouperGroup->createGroup($this->userId, $name, $set, $descr));
}

/**
* Process to join a group displayed on the "Optin" page
*
* @return CakeResponse Redirect back to "Optin" page
*/
public function joinGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

if($this->GrouperGroup->joinGroup($this->userId, $name)) {
$this->Flash->success(_txt('pl.grouperlite.message.flash.join-group-success'));
} else {
$this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-failed'));
}
return $this->redirect(array('action' => 'groupoptin'));

} else {
$this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-error'));
}
$this->Flash->error(_txt('pl.grouperlite.message.flash.join-group-error'));

return $this->redirect(array('action' => 'groupoptin'));
}

/**
* Process to leave a group displayed on the "Member Of" page
*
* @return CakeResponse Redirect back to "Member Of" page
*/
public function leaveGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

if($this->GrouperGroup->leaveGroup($this->userId, $name)) {
$this->Flash->success(_txt('pl.grouperlite.message.flash.leave-group-success'));
} else {
$this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-failed'));
}
return $this->redirect(array('action' => 'groupoptin'));
} else {
$this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-error'));
}
$this->Flash->error(_txt('pl.grouperlite.message.flash.leave-group-error'));

return $this->redirect(array('action' => 'groupmember'));
}

/**
Expand Down Expand Up @@ -250,4 +232,43 @@ function isAuthorized() {
return ($p[$this->action]);
}

public function emailListsOptin() {
$this->set('title', _txt('pl.grouperlite.title.emaillists'));
// mock data
$this->set('group', array(
'member' => true,
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T'
));
}

public function emailListsManaged() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsmanaged'));
// mock data
$this->set('group', array(
'member' => true,
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T'
));
}

public function emailListInfo() {
$this->set('title', _txt('pl.grouperlite.title.emaillistsinfo'));
// mock data
$this->set('groupergroupsdetail', array(
'member' => true,
'uuid' => 'abc123xyz789',
'displayExtension' => 'email-list-1',
'extension' => 'email-list-1',
'displayName' => 'Email List 1',
'typeOfGroup' => 'list',
'name' => 'Email List 1',
'description' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.',
'enabled' => 'T',
'attributes' => array()
));
}

}
88 changes: 52 additions & 36 deletions Model/GrouperGroup.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
class GrouperGroup extends GrouperLiteAppModel
{
//TODO - Add input validation, possibly???

/** @var string $name used by CakePHP for locating model */
public $name = "GrouperGroup";

Expand All @@ -59,22 +59,12 @@ private function initApi() {
}
}


private function memberOfGroups($userId) {
$this->initApi();

$args = array();
$args['conditions']['userId'] = $userId;

return $this->grouperAPI->getGrouperMemberOfGroups($args);
}

/**
* Return all Groups that a User belongs to in Grouper.
* Will also compare against Optin Groups to determine if User given option to Optout of the Group
* Will also add Optin Groups and flag them as joined so can display Optout option in UI.
*
* @param string $userId Id of User
* @return array Records of Groups in Grouper that the User belongs to
* @return array Records of Groups from Grouper that the User belongs to
* @throws GrouperLiteException
*
*/
Expand Down Expand Up @@ -103,6 +93,22 @@ public function filteredMemberOfGroups(string $userId) {
return $this->getFriendlyName($memberOfGroups);
}

/**
* Internal process used by other functions to fetch Groups the User is a member of
*
* @param string $userId Id of User
* @return array Records of Groups from Grouper that the User belongs to
* @throws GrouperLiteException
*
*/
private function memberOfGroups(string $userId) {

$args = array();
$args['conditions']['userId'] = $userId;

return $this->grouperAPI->getGrouperMemberOfGroups($args);
}

public function groupDescriptions($groupName) {
$this->initApi();

Expand All @@ -120,7 +126,16 @@ public function groupDescriptions($groupName) {
return $groupDescription;
}

public function leaveGroup($userId, $groupName) {
/**
* Process for User to Leave a Group
*
* @param string $userId Id of User
* @param string $groupName Name of Group Leaving
* @return bool True|False
* @throws GrouperLiteException
*
*/
public function leaveGroup(string $userId, string $groupName) {
$this->initApi();

$args = array();
Expand All @@ -131,7 +146,16 @@ public function leaveGroup($userId, $groupName) {
return $this->grouperAPI->grouperGroupLeaveOrJoin($args);
}

public function joinGroup($userId, $groupName) {
/**
* Process for User to Join a Group
*
* @param string $userId Id of User
* @param string $groupName Name of Group Leaving
* @return bool True|False
* @throws GrouperLiteException
*
*/
public function joinGroup(string $userId, string $groupName) {
$this->initApi();

$args = array();
Expand All @@ -156,9 +180,9 @@ public function ownerGroups($userId) {
}

/**
* Get all Groups with Optin attribute set
* Will Match up with Groups User is a member of to determine which Optin groups the user is
* already a member of.
* Display all Groups the User can JOIN
* Get all Groups with Optin attribute set and display ones User can join.
* Will Match up with Groups User is already a member of to determine which Optin groups to not display
*
* @param string $userId Id of user
* @return array Listing of Optin groups available in Grouper
Expand All @@ -172,25 +196,20 @@ public function optinGroups(string $userId) {

$joinOrLeave = $this->grouperAPI->getOptinGroups($args);
$userGroups = $this->memberOfGroups($userId);
if(isset($joinOrLeave['errorMessage'])){
return $joinOrLeave;
}

//See if Optin group match any of the groups belong to already.
foreach ($joinOrLeave as &$groupsJoL) {
foreach ($userGroups as $key => $value) {
$groupsJoL['member'] = false;
if ($groupsJoL['name'] == $value['name']) {
//See if Optin group match any of the groups user already belongs to.
foreach ($joinOrLeave as $key => $value) {
foreach ($userGroups as $userGroup) {
if ($value['name'] == $userGroup['name']) {
//Match!!
$groupsJoL['member'] = true;
//I am removing entry for faster processing of loop
unset($userGroups[$key]);
//Removing as already a member of.
unset($joinOrLeave[$key]);
break;
}
}
}
$groupsToOptin = $this->getFriendlyName($joinOrLeave);
return $groupsToOptin;

return $this->getFriendlyName($joinOrLeave);
}

public function createGroup($userId, $groupName, $stemName, $groupDesc) {
Expand All @@ -217,21 +236,19 @@ public function getOwnerStems($userId) {

/**
* Search for Groups/Lists related to Search term.
* Will import all records the user can see and then do search here rather than call Grouper WS Search
* Will import all records the user can see and then do search in this code rather than call Grouper WS Search
* functionality. This is due to the fact that the grouperName is autogenerated and this app needs to search
* attributes which the Grouper WS does not do.
*
* @param $userId
* @param $searchCriteria
* @param $page
* @return array
* @throws GrouperLiteException Captured in Controller
*/
public function getSearchedGroups($userId, $searchCriteria, $page) {
$this->initApi();

$args = array();
$args['conditions']['userId'] = $userId;

if($page == 'groupOptin') {
$pageResults = $this->optinGroups($userId);
} elseif ($page == 'groupOwner') {
Expand Down Expand Up @@ -263,7 +280,6 @@ public function getSearchedGroups($userId, $searchCriteria, $page) {
*
*/
private function getFriendlyName(array $groups) {
$this->initApi();

foreach ($groups as &$group) {
$group['friendlyName'] = $group['displayName'];
Expand Down

0 comments on commit a4cb71f

Please sign in to comment.