Skip to content

Commit

Permalink
Delete and Add members
Browse files Browse the repository at this point in the history
  • Loading branch information
Axel Stohn authored and Axel Stohn committed Mar 19, 2022
1 parent 0350dfd commit 707895b
Show file tree
Hide file tree
Showing 3 changed files with 397 additions and 306 deletions.
117 changes: 81 additions & 36 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class GrouperGroupsController extends GrouperLiteAppController
* @return CakeResponse|void|null
*
*/
public function beforeFilter() {
public function beforeFilter()
{
parent::beforeFilter();

//Need to find which plugin instance choosing, if more than one from cm_co_grouper_lites
Expand All @@ -82,7 +83,8 @@ public function beforeFilter() {
/**
* Adding Grouper Conn info to SESSION for use in Lib/GrouperApiAccess.php
*/
private function setConnection() {
private function setConnection()
{
$this->Session->write('Plugin.Grouper.Api.id', $this->passedArgs['glid']);

//Now get the setup Dasboard instance from db for connection info.
Expand All @@ -104,7 +106,8 @@ private function setConnection() {
*
* @return CakeResponse Redirect to MyMembership page
*/
public function index() {
public function index()
{
return $this->redirect(
array('controller' => 'grouper_groups', 'action' => 'groupmember')
);
Expand All @@ -116,15 +119,16 @@ public function index() {
* Called from all pages via AJAX call
*
*/
public function groupSubscribers() {
public function groupSubscribers()
{
$groupName = urldecode($this->request->query['groupname']);

if ($this->request->is('ajax')) {
$ajax = true;
$this->response->disableCache();
}

//Need to see if coming from AdHoc or from a WG (Working Group)
if (strpos($groupName, ':') === false ) {
if (strpos($groupName, ':') === false) {
$groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users';
} else {
$groupNameFormatted = $groupName;
Expand Down Expand Up @@ -153,16 +157,17 @@ public function groupSubscribers() {
* Called from all pages via AJAX call
*
*/
public function addSubscriber() {
public function addSubscriber()
{
$groupName = urldecode($this->request->query['group']);
$addUserId = urldecode($this->request->query['userId']);

if ($this->request->is('ajax')) {
$ajax = true;
$this->response->disableCache();
}

//Need to see if coming from AdHoc or from a WG (Working Group)
if (strpos($groupName, ':') === false ) {
if (strpos($groupName, ':') === false) {
$groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users';
} else {
$groupNameFormatted = $groupName;
Expand All @@ -175,33 +180,49 @@ public function addSubscriber() {
];

try {
$subscribers = $this->GrouperGroup->addMemberToGroup($scope, $this->userId);
$resultAdd = $this->GrouperGroup->addMemberToGroup($scope, $this->userId);

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

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

$this->set(compact('subscribers'));
$this->set('_serialize', 'subscribers');
if ($resultAdd == 'SUCCESS') {
// Do nothing
} elseif ($resultAdd == 'EXCEPTION') {
$this->response->type('json');
$this->response->statusCode(404);
$this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'EXCEPTION')));
$this->response->send();
} else {
$this->response->type('json');
$this->response->statusCode(401);
$this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'ERROR')));
$this->response->send();
}
$this->set(compact('resultAdd'));
$this->set('_serialize', 'resultAdd');

}

/**
* Remove a member from a group
* Called from all pages via AJAX call
*
*/
public function removeSubscriber() {
public function removeSubscriber()
{
$groupName = urldecode($this->request->query['group']);
$remUserId = urldecode($this->request->query['userId']);

if ($this->request->is('ajax')) {
$ajax = true;
$this->response->disableCache();
}

//Need to see if coming from AdHoc or from a WG (Working Group)
if (strpos($groupName, ':') === false ) {
if (strpos($groupName, ':') === false) {
$groupNameFormatted = 'ref:incommon-collab:' . $groupName . ':users';
} else {
$groupNameFormatted = $groupName;
Expand All @@ -214,22 +235,31 @@ public function removeSubscriber() {
];

try {
$subscribers = $this->GrouperGroup->removeMemberToGroup($scope, $this->userId);
$resultRemove = $this->GrouperGroup->removeMemberToGroup($scope, $this->userId);

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

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

$this->set(compact('subscribers'));
$this->set('_serialize', 'subscribers');
if ($resultRemove == 'SUCCESS') {
// Do nothing
} else {
$this->response->type('json');
$this->response->statusCode(404);
$this->response->body(json_encode(array('status' => 'ERROR', 'message' => 'ERROR')));
$this->response->send();
}
$this->set(compact('resultRemove'));
$this->set('_serialize', 'resultRemove');
}

/**
* Listing of all Grouper Groups owned/admin by User Or search those Grouper Groups
*/
public function groupOwner() {
public function groupOwner()
{
$this->set('title', _txt('pl.grouperlite.title.groupowner'));

//Set initial settings for pagination
Expand Down Expand Up @@ -301,7 +331,8 @@ public function groupOwner() {
* This includes self-joined Optin Groups, as well as required Groups User cannot leave
*
*/
public function groupMember() {
public function groupMember()
{
$this->set('title', _txt('pl.grouperlite.title.groupmember'));

//Set initial settings for pagination
Expand Down Expand Up @@ -371,7 +402,8 @@ public function groupMember() {
/**
* Display all Groups a User can Join
*/
public function groupOptin() {
public function groupOptin()
{
$this->set('title', _txt('pl.grouperlite.title.groupoptin'));


Expand Down Expand Up @@ -435,7 +467,7 @@ public function groupOptin() {
"defaultCollapse" => CakeSession::read('Plugin.Grouper.Api.defaultCollapse'),
"adHocHeading" => CakeSession::read('Plugin.Grouper.Api.adHocHeading'),
"wgHeading" => CakeSession::read('Plugin.Grouper.Api.wgHeading')
];
];
$this->set('config', $config);
}

Expand All @@ -447,7 +479,8 @@ public function groupOptin() {
* Editing via a template will not be supported in this version of the plugin - Bill Kaufman
*
*/
public function groupCreateTemplate() {
public function groupCreateTemplate()
{
if ($this->request->is('post')) {
try {
$status = $this->GrouperGroup->createGroupWithTemplate($this->userId, $this->request->data);
Expand All @@ -471,7 +504,8 @@ public function groupCreateTemplate() {
* Delete a Grouper Group via Grouper Template
* NOT USED IN CODE
*/
public function groupDeleteTemplate() {
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'));
Expand All @@ -481,12 +515,13 @@ public function groupDeleteTemplate() {
}

/**
* @return CakeResponse|void|null
* @deprecated
* NOT USED IN CODE
*
* @return CakeResponse|void|null
*/
public function groupCreate() {
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'));
Expand All @@ -505,7 +540,8 @@ public function groupCreate() {
* This method is currently not used.
* @return CakeResponse|null
*/
public function groupDelete() {
public function groupDelete()
{
if (!$this->GrouperGroup->deleteGroup($this->userId, $this->request->data)) {
$this->Flash->set("Error in deleting group!", array('key' => 'error'));
} else {
Expand All @@ -522,7 +558,8 @@ public function groupDelete() {
*
* @return CakeResponse Redirect back to "Optin" page
*/
public function joinGroup() {
public function joinGroup()
{
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

Expand All @@ -548,7 +585,8 @@ public function joinGroup() {
*
* @return CakeResponse Redirect back to "Member Of" page
*/
public function leaveGroup() {
public function leaveGroup()
{
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

Expand Down Expand Up @@ -581,7 +619,8 @@ public function leaveGroup() {
* @return Array Permissions
* @since COmanage Registry v3.2.0
*/
function isAuthorized() {
function isAuthorized()
{
$roles = $this->Role->calculateCMRoles();

//TODO - This is needed for my dev enviro since I do not log in via I2 IdP
Expand Down Expand Up @@ -632,7 +671,8 @@ function isAuthorized() {
return ($p[$this->action]);
}

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

//Set initial settings for pagination
Expand Down Expand Up @@ -687,7 +727,8 @@ public function emaillistsOptin() {
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}

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

//Set initial settings for pagination
Expand Down Expand Up @@ -742,7 +783,8 @@ public function emaillistsMember() {
$this->set('isTemplateUser', $this->GrouperGroup->isTemplateUser($this->userId));
}

public function emaillistsManage() {
public function emaillistsManage()
{
$this->set('title', _txt('pl.grouperlite.title.emaillists-manage'));
// mock data
$this->set('group', array(
Expand All @@ -758,7 +800,8 @@ public function emaillistsManage() {
}


private function getUserId($id) {
private function getUserId($id)
{
$args = array();
$args['conditions']['Identifier.co_person_id'] = $id;
$args['conditions']['Identifier.type'] = 'I2CollabPN';
Expand All @@ -779,7 +822,8 @@ private function getUserId($id) {
* @return array[]
*
*/
private function breakoutGroups(array $recordSet, $type = 'basic') {
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();
Expand Down Expand Up @@ -834,7 +878,8 @@ private function breakoutGroups(array $recordSet, $type = 'basic') {
* @return string
*
*/
private function hackDescription($description) {
private function hackDescription($description)
{
//Verify description has period in it.
if (strpos($description, ".") === false) {
return $description;
Expand Down
Loading

0 comments on commit 707895b

Please sign in to comment.