Skip to content

Commit

Permalink
Merge branch 'develop' of bitbucket.org:unicon/comanagework into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Feb 12, 2021
2 parents 7bf402c + f899562 commit a01c927
Show file tree
Hide file tree
Showing 9 changed files with 447 additions and 268 deletions.
179 changes: 136 additions & 43 deletions Controller/GrouperGroupsController.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,51 @@
<?php
/**
* COmanage Registry Grouper Lite Widget Groups Controller
*
* Portions licensed to the University Corporation for Advanced Internet
* Development, Inc. ("UCAID") under one or more contributor license agreements.
* See the NOTICE file distributed with this work for additional information
* regarding copyright ownership.
*
* UCAID licenses this file to you under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* @link http://www.internet2.edu/comanage COmanage Project
* @package registry-plugin
* @since COmanage Registry v3.2.0
* @license Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
*/

App::uses('Validator', 'Vendor/cakephp/Validation');
App::uses('CoGrouperLite', 'GrouperLite.Model/');


/**
* Class GrouperGroupsController
* Main Class for Grouper Lite functionality
*
*/
class GrouperGroupsController extends GrouperLiteAppController
{
public $helpers = array('Html', 'Form', 'Flash');
public $components = array('Flash');

public $name = 'GrouperGroups';

/**
* Overrides parent beforeFilter to verify that Session contains the correct API settings.
*
* @return CakeResponse|void|null
*
*/
public function beforeFilter() {
parent::beforeFilter();

Expand Down Expand Up @@ -59,27 +94,58 @@ public function index() {
);
}


/**
* Display of Grouper Group Information, such as Group Properties, Members and Attributes
*
*/
public function groupInfo() {
$name = urldecode($this->request->query['groupname']);

$details = $this->GrouperGroup->groupDescriptions($name);

$this->set('groupname', $name);
$this->set('title', _txt('pl.grouperlite.title.groupinfo'));
$this->set('groupergroupsdetail', $details[0]);

$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
try {
$details = $this->GrouperGroup->groupDescriptions($name);
$this->set('groupergroupsdetail', $details[0]);

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

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

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

if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('groupergroupsowner', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOwner'));
$this->set('searchcriteria', $searchCriteria);

try {
$this->set('groupergroupsowner', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOwner'));

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

$this->set('groupergroupsowner', array());
$this->Flash->set(_txt('pl.grouperlite.message.flash.owner-group-failed'), array('key' => 'error'));
return;
}
} else {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
try {
$this->set('groupergroupsowner', $this->GrouperGroup->ownerGroups($this->userId));
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));

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

}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
}
Expand All @@ -91,22 +157,34 @@ public function groupOwner() {
*/
public function groupMember() {
$this->set('title', _txt('pl.grouperlite.title.groupmember'));
try {
if (isset($this->request->data['search'])){
$searchCriteria = urldecode($this->request->data['search']);

if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('searchcriteria', $searchCriteria);

try {
$this->set('groupergroupmemberships', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupMember'));
$this->set('searchcriteria', $searchCriteria);
} else {

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

$this->Flash->set("Your Search Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
return;
}
} else {
try {
$this->set('groupergroupmemberships', $this->GrouperGroup->filteredMemberOfGroups($this->userId));

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

$this->Flash->set("Your Member Group cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
return;
}
} catch (Exception $e) {
CakeLog::write('error',
'GrouperLite Controller - groupMember: ' . var_export($e->getMessage(), true));
$this->Flash->set("Your Membership Groups cannot be found currently, please try again later.", array('key' => 'error'));
$this->set('groupergroupmemberships', array());
}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));

}

/**
Expand All @@ -115,24 +193,29 @@ public function groupMember() {
public function groupOptin() {
$this->set('title', _txt('pl.grouperlite.title.groupoptin'));

if (isset($this->request->data['search'])){
if (isset($this->request->data['search'])) {
$searchCriteria = urldecode($this->request->data['search']);
$this->set('groupergroupoptin', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOptin'));
$this->set('searchcriteria', $searchCriteria);

try {
$this->set('groupergroupoptin', $this->GrouperGroup->getSearchedGroups($this->userId, $searchCriteria, 'groupOptin'));

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

$this->Flash->set("Your Optin Group Search cannot be found, please try again later.", array('key' => 'error'));
$this->set('groupergroupoptin', array());
return;
}
} else {
try {
$optin = $this->GrouperGroup->optinGroups($this->userId);
if (isset($optin['errorMessage'])){
$this->Flash->set('Some error', array('key' => 'error'));
$this->set('groupergroupoptin', array());
} else {
$this->set('groupergroupoptin', $optin);
}
$this->set('groupergroupoptin', $this->GrouperGroup->optinGroups($this->userId));

} catch (Exception $e) {
CakeLog::write('error', 'GrouperLite Controller: Seeing is believing');
$this->Flash->set($e->getMessage(), array('key' => 'error'));
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$this->Flash->set("An error occurred with the Optin Groups, please try again later.", array('key' => 'error'));
$this->set('groupergroupoptin', array());
return;
}
}
$this->set('isuserowner', $this->GrouperGroup->isUserOwner($this->userId));
Expand Down Expand Up @@ -161,10 +244,15 @@ public function joinGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

if($this->GrouperGroup->joinGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-failed'), array('key' => 'error'));
try {
if ($this->GrouperGroup->joinGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-failed'), array('key' => 'error'));
}
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.join-group-error'), array('key' => 'error'));
}

} else {
Expand All @@ -183,11 +271,17 @@ public function leaveGroup() {
if ($this->request->is('post')) {
$name = $this->request->data['GroupName'];

if($this->GrouperGroup->leaveGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-failed'), array('key' => 'error'));
try {
if ($this->GrouperGroup->leaveGroup($this->userId, $name)) {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-success'), array('key' => 'success'));
} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-failed'), array('key' => 'error'));
}
} catch (Exception $e) {
CakeLog::write('error', __METHOD__ . ': ' . var_export($e->getMessage(), true));
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error'));
}

} else {
$this->Flash->set(_txt('pl.grouperlite.message.flash.leave-group-error'), array('key' => 'error'));
}
Expand All @@ -203,14 +297,14 @@ public function leaveGroup() {
* - precondition: Session.Auth holds data used for authz decisions
* - postcondition: $permissions set with calculated permissions
*
* @since COmanage Registry v3.2.0
* @return Array Permissions
* @since COmanage Registry v3.2.0
*/
function isAuthorized() {
$roles = $this->Role->calculateCMRoles();

//Need to pull in UserID for access to Grouper
if($this->Session->check('Auth.User.username')) {
if ($this->Session->check('Auth.User.username')) {
$this->userId = $this->Session->read('Auth.User.username');
}

Expand Down Expand Up @@ -276,5 +370,4 @@ public function emailListInfo() {
'attributes' => array()
));
}

}
Loading

0 comments on commit a01c927

Please sign in to comment.