Authentication Sources Manager Ext JS Migration Complete

This commit is contained in:
Enrique Ponce de Leon
2011-02-14 19:29:28 +00:00
parent 3a851208da
commit 8f5603cb6d
7 changed files with 534 additions and 4 deletions

View File

@@ -91,7 +91,7 @@ class RBAC
function initRBAC () {
if ( is_null($this->userObj ) ) {
require_once ( "classes/model/RbacUsers.php" );
$this->userObj = new RbacUsers;
$this->userObj = new RbacUsers();
}
if ( is_null($this->systemObj ) ) {
@@ -858,6 +858,22 @@ class RBAC
return $this->authSourcesObj->getAllAuthSources();
}
/**
* this function gets all authentication source
* Authentication Sources based at parameters
*
* @access public
* @author Enrique Ponce de Leon <enrique@colosa.com>
* @param int $start offset value to paging grid
* @param int $limit limit value to paging grid
* @param string $filter value to search or filter select
* @return $this->authSourcesObj->getAuthenticationSources()
*/
function getAuthenticationSources($start,$limit,$filter='') {
return $this->authSourcesObj->getAuthenticationSources($start,$limit,$filter);
}
/**
* this function gets all authentication source
* Authentication Sources
@@ -911,6 +927,19 @@ class RBAC
$this->authSourcesObj->remove($sUID);
}
/**
* this function gets all users by authentication source
*
* @access public
* @param void
* @return $this->userObj->getAllUsersByAuthSource()
*/
function getAllUsersByAuthSource(){
return $this->userObj->getAllUsersByAuthSource();
}
/**
* this function searchs users
*

View File

@@ -136,4 +136,29 @@ class AuthenticationSource extends BaseAuthenticationSource {
throw($oError);
}
}
//Added By Enrique Ponce de Leon <enrique@colosa.com>
//Gets Criteria to fill grid of authentication source
function getAuthenticationSources($start,$limit,$filter=''){
$oCriteria = new Criteria('rbac');
$oCriteria->addSelectColumn('COUNT(*) AS CNT');
$oCriteria->add(AuthenticationSourcePeer::AUTH_SOURCE_UID,'',Criteria::NOT_EQUAL);
if ($filter!=''){
$oCriteria->add(AuthenticationSourcePeer::AUTH_SOURCE_NAME,'%'.$filter.'%',Criteria::LIKE);
}
$oCriteria2 = new Criteria('rbac');
$oCriteria2->addSelectColumn('*');
$oCriteria2->add(AuthenticationSourcePeer::AUTH_SOURCE_UID,'',Criteria::NOT_EQUAL);
if ($filter!=''){
$oCriteria2->add(AuthenticationSourcePeer::AUTH_SOURCE_NAME,'%'.$filter.'%',Criteria::LIKE);
}
$oCriteria2->setLimit($limit);
$oCriteria2->setOffset($start);
$result = array();
$result['COUNTER'] = $oCriteria;
$result['LIST'] = $oCriteria2;
return $result;
}
} // AuthenticationSource

View File

@@ -210,4 +210,23 @@ class RbacUsers extends BaseRbacUsers {
$this->delete();
}
//Added by Qennix at Feb 14th, 2011
//Gets an associative array with total users by authentication sources
function getAllUsersByAuthSource(){
$oCriteria = new Criteria('rbac');
$oCriteria->addSelectColumn(RbacUsersPeer::UID_AUTH_SOURCE);
$oCriteria->addSelectColumn('COUNT(*) AS CNT');
$oCriteria->add(RbacUsersPeer::USR_STATUS,'CLOSED',Criteria::NOT_EQUAL);
$oCriteria->addGroupByColumn(RbacUsersPeer::UID_AUTH_SOURCE);
$oDataset = RbacUsersPeer::doSelectRS($oCriteria);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$aAuth = Array();
while ($oDataset->next()){
$row = $oDataset->getRow();
$aAuth[$row['UID_AUTH_SOURCE']] = $row['CNT'];
}
return $aAuth;
}
} // Users

View File

@@ -30,7 +30,7 @@ try {
die;
}
switch ($_POST['action']) {
switch ($_REQUEST['action']) {
case 'searchUsers':
G::LoadThirdParty('pear/json','class.json');
require_once 'classes/model/Users.php';
@@ -91,6 +91,63 @@ try {
}
G::RenderPage('publish', 'raw');
break;
case 'authSourcesList':
require_once PATH_RBAC.'model/AuthenticationSource.php';
global $RBAC;
G::LoadClass('configuration');
$co = new Configurations();
$config = $co->getConfiguration('authSourcesList', 'pageSize','',$_SESSION['USER_LOGGED']);
$limit_size = isset($config['pageSize']) ? $config['pageSize'] : 20;
$start = isset($_REQUEST['start']) ? $_REQUEST['start'] : 0;
$limit = isset($_REQUEST['limit']) ? $_REQUEST['limit'] : $limit_size;
$filter = isset($_REQUEST['textFilter']) ? $_REQUEST['textFilter'] : '';
$Criterias = $RBAC->getAuthenticationSources($start, $limit, $filter);
$Dat = AuthenticationSourcePeer::doSelectRS($Criterias['COUNTER']);
$Dat->setFetchmode(ResultSet::FETCHMODE_ASSOC);
$Dat->next();
$row = $Dat->getRow();
$total_sources = $row['CNT'];
$oDataset = AuthenticationSourcePeer::doSelectRS($Criterias['LIST']);
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
global $RBAC;
$auth = $RBAC->getAllUsersByAuthSource();
$aSources = Array();
while ($oDataset->next()){
$aSources[] = $oDataset->getRow();
$index = sizeof($aSources)-1;
$aSources[$index]['CURRENT_USERS'] = isset($auth[$aSources[$index]['AUTH_SOURCE_UID']]) ? $auth[$aSources[$index]['AUTH_SOURCE_UID']] : 0;
}
echo '{sources: '.G::json_encode($aSources).', total_sources: '.$total_sources.'}';
break;
case 'canDeleteAuthSource':
//echo 'llego';
//require_once PATH_RBAC.'model/RbacUsers.php';
try{
$authUID = $_POST['auth_uid'];
global $RBAC;
$aAuth = $RBAC->getAllUsersByAuthSource();
$response = isset($aAuth[$authUID]) ? 'false' : 'true';
echo '{success: '.$response.'}';
}catch(Exception $ex){
echo '{success: false, error: '.$ex->getMessage().'}';
}
break;
case 'deleteAuthSource':
try{
global $RBAC;
$RBAC->removeAuthSource($_POST['auth_uid']);
echo '{success: true}';
}catch(Exception $ex){
echo '{success: false, error: '.$ex->getMessage().'}';
}
break;
}
}
catch ( Exception $e ) {

View File

@@ -30,11 +30,22 @@ if ($RBAC->userCanAccess('PM_SETUP_ADVANCE') != 1) {
die;
}
G::LoadClass('configuration');
$c = new Configurations();
$configPage = $c->getConfiguration('authSourcesList', 'pageSize','',$_SESSION['USER_LOGGED']);
$Config['pageSize'] = isset($configPage['pageSize']) ? $configPage['pageSize'] : 20;
$G_MAIN_MENU = 'processmaker';
$G_SUB_MENU = 'users';
$G_ID_MENU_SELECTED = 'USERS';
$G_ID_SUB_MENU_SELECTED = 'AUTH_SOURCES';
$G_PUBLISH = new Publisher;
$G_PUBLISH->AddContent('propeltable', 'paged-table', 'authSources/authSources_List', $RBAC->getAllAuthSources(), '', '');
G::RenderPage('publish','blank');
$oHeadPublisher =& headPublisher::getSingleton();
$oHeadPublisher->addExtJsScript('authSources/authSourcesList', false); //adding a javascript file .js
$oHeadPublisher->addContent('authSources/authSourcesList'); //adding a html file .html.
$oHeadPublisher->assign('FORMATS',$c->getFormats());
$oHeadPublisher->assign('CONFIG', $Config);
G::RenderPage('publish', 'extJs');
?>

View File

@@ -0,0 +1,3 @@
<div style="padding: 15px">
<div id="list-panel"></div>
</div>

View File

@@ -0,0 +1,386 @@
/*
* @author: Qennix
* Feb 11st, 2011
*/
new Ext.KeyMap(document, [
{
key: Ext.EventObject.F5,
fn: function(keycode, e) {
if (! e.ctrlKey) {
if (Ext.isIE) {
// IE6 doesn't allow cancellation of the F5 key, so trick it into
// thinking some other key was pressed (backspace in this case)
e.browserEvent.keyCode = 8;
}
e.stopEvent();
document.location = document.location;
}else{
Ext.Msg.alert('Refresh', 'You clicked: CTRL-F5');
}
}
},
{
key: Ext.EventObject.DELETE,
fn: function(k,e){
iGrid = Ext.getCmp('infoGrid');
rowSelected = iGrid.getSelectionModel().getSelected();
if (rowSelected){
DeleteAuthSource();
}
}
},
{
key: Ext.EventObject.F2,
fn: function(k,e){
iGrid = Ext.getCmp('infoGrid');
rowSelected = iGrid.getSelectionModel().getSelected();
if (rowSelected){
EditAuthSource();
}
}
}
]);
var store;
var cmodel;
var infoGrid;
var viewport;
var smodel;
var newButton;
var editButton;
var deleteButton;
var usersButton;
var permissionsButton;
var searchButton;
var serachText;
var newForm;
var comboStatusStore;
var editForm;
var contextMenu;
var w;
Ext.onReady(function(){
Ext.QuickTips.init();
pageSize = parseInt(CONFIG.pageSize);
newButton = new Ext.Action({
text: _('ID_NEW'),
iconCls: 'button_menu_ext ss_sprite ss_add',
handler: NewAuthSource
});
editButton = new Ext.Action({
text: _('ID_EDIT'),
iconCls: 'button_menu_ext ss_sprite ss_pencil',
handler: EditAuthSource,
disabled: true
});
deleteButton = new Ext.Action({
text: _('ID_DELETE'),
iconCls: 'button_menu_ext ss_sprite ss_delete',
handler: DeleteAuthSource,
disabled: true
});
usersButton = new Ext.Action({
text: _('ID_IMPORT_USERS'),
iconCls: 'button_menu_ext ss_sprite ss_user_add',
handler: ImportUsers,
disabled: true
});
searchButton = new Ext.Action({
text: _('ID_SEARCH'),
handler: DoSearch
});
contextMenu = new Ext.menu.Menu({
items: [editButton, deleteButton,'-',usersButton]
});
searchText = new Ext.form.TextField ({
id: 'searchText',
ctCls:'pm_search_text_field',
allowBlank: true,
width: 150,
emptyText: _('ID_ENTER_SEARCH_TERM'),//'enter search term',
listeners: {
specialkey: function(f,e){
if (e.getKey() == e.ENTER) {
DoSearch();
}
},
focus: function(f,e) {
var row = infoGrid.getSelectionModel().getSelected();
infoGrid.getSelectionModel().deselectRow(infoGrid.getStore().indexOf(row));
}
}
});
clearTextButton = new Ext.Action({
text: 'X',
ctCls:'pm_search_x_button',
handler: GridByDefault
});
smodel = new Ext.grid.RowSelectionModel({
singleSelect: true,
listeners:{
rowselect: function(sm){
editButton.enable();
deleteButton.enable();
usersButton.enable();
},
rowdeselect: function(sm){
editButton.disable();
deleteButton.disable();
usersButton.disable();
}
}
});
store = new Ext.data.GroupingStore( {
proxy : new Ext.data.HttpProxy({
url: 'authSources_Ajax?action=authSourcesList'
}),
reader : new Ext.data.JsonReader( {
root: 'sources',
totalProperty: 'total_sources',
fields : [
{name : 'AUTH_SOURCE_UID'},
{name : 'AUTH_SOURCE_NAME'},
{name : 'AUTH_SOURCE_PROVIDER'},
{name : 'AUTH_SOURCE_SERVER_NAME'},
{name : 'AUTH_SOURCE_PORT'},
{name : 'AUTH_SOURCE_ENABLED_TLS'},
{name : 'AUTH_SOURCE_VERSION'},
{name : 'AUTH_SOURCE_BASE_DN'},
{name : 'AUTH_ANONYMOUS'},
{name : 'AUTH_SOURCE_SEARCH_USER'},
{name : 'AUTH_SOURCE_ATTRIBUTES'},
{name : 'AUTH_SOURCE_OBJECT_CLASSES'},
{name : 'CURRENT_USERS', type:'int'}
]
})
});
cmodel = new Ext.grid.ColumnModel({
defaults: {
width: 50,
sortable: true
},
columns: [
{id:'AUTH_SOURCE_UID', dataIndex: 'AUTH_SOURCE_UID', hidden:true, hideable:false},
{header: _('ID_NAME'), dataIndex: 'AUTH_SOURCE_NAME', width: 200, hidden:false, align:'left'},
{header: _('ID_PROVIDER'), dataIndex: 'AUTH_SOURCE_PROVIDER', width: 120, hidden: false, align: 'center'},
{header: _('ID_SERVER_NAME'), dataIndex: 'AUTH_SOURCE_SERVER_NAME', width: 180, hidden: false, align: 'center'},
{header: _('ID_PORT'), dataIndex: 'AUTH_SOURCE_PORT', width: 60, hidden: false, align: 'center'},
{header: _('ID_ENABLED_TLS'), dataIndex: 'AUTH_SOURCE_ENABLED_TLS', width: 90, hidden: false, align: 'center', renderer: show_enabled},
{header: _('ID_CURRENT_USERS'), dataIndex: 'CURRENT_USERS', width: 90, hidden: false, align: 'center'}
]
});
storePageSize = new Ext.data.SimpleStore({
fields: ['size'],
data: [['20'],['30'],['40'],['50'],['100']],
autoLoad: true
});
comboPageSize = new Ext.form.ComboBox({
typeAhead : false,
mode : 'local',
triggerAction : 'all',
store: storePageSize,
valueField: 'size',
displayField: 'size',
width: 50,
editable: false,
listeners:{
select: function(c,d,i){
UpdatePageConfig(d.data['size']);
bbarpaging.pageSize = parseInt(d.data['size']);
bbarpaging.moveFirst();
}
}
});
comboPageSize.setValue(pageSize);
bbarpaging = new Ext.PagingToolbar({
pageSize: pageSize,
store: store,
displayInfo: true,
displayMsg: _('ID_GRID_PAGE_DISPLAYING_AUTHENTICATION_MESSAGE') + '&nbsp; &nbsp; ',
emptyMsg: _('ID_GRID_PAGE_NO_AUTHENTICATION_MESSAGE'),
items: ['-',_('ID_PAGE_SIZE')+':',comboPageSize]
});
infoGrid = new Ext.grid.GridPanel({
region: 'center',
layout: 'fit',
id: 'infoGrid',
height:100,
autoWidth : true,
stateful : true,
stateId : 'grid',
enableColumnResize: true,
enableHdMenu: true,
frame:false,
//iconCls:'icon-grid',
columnLines: false,
viewConfig: {
forceFit:true
},
title : _('ID_AUTH_SOURCES'),
store: store,
cm: cmodel,
sm: smodel,
tbar: [newButton, '-', editButton, deleteButton,'-',usersButton, {xtype: 'tbfill'}, searchText,clearTextButton,searchButton],
bbar: bbarpaging,
listeners: {
rowdblclick: EditAuthSource,
render: function(){
this.loadMask = new Ext.LoadMask(this.body, {msg:_('ID_LOADING_GRID')});
}
},
view: new Ext.grid.GroupingView({
forceFit:true,
groupTextTpl: '{text}'
})
});
infoGrid.on('rowcontextmenu',
function (grid, rowIndex, evt) {
var sm = grid.getSelectionModel();
sm.selectRow(rowIndex, sm.isSelected(rowIndex));
},
this
);
infoGrid.on('contextmenu',
function (evt) {
evt.preventDefault();
},
this
);
infoGrid.addListener('rowcontextmenu',onMessageContextMenu,this);
infoGrid.store.load();
viewport = new Ext.Viewport({
layout: 'fit',
autoScroll: false,
items: [
infoGrid
]
});
});
//Funtion Handles Context Menu Opening
onMessageContextMenu = function (grid, rowIndex, e) {
e.stopEvent();
var coords = e.getXY();
contextMenu.showAt([coords[0], coords[1]]);
};
//Do Nothing Function
DoNothing = function(){};
//Load Grid By Default
GridByDefault = function(){
searchText.reset();
infoGrid.store.load();
};
//Do Search Function
DoSearch = function(){
infoGrid.store.load({params: {textFilter: searchText.getValue()}});
};
//Update Page Size Configuration
UpdatePageConfig = function(pageSize){
Ext.Ajax.request({
url: 'processCategory_Ajax',
params: {action:'updatePageSize', size: pageSize}
});
};
//Render Function Enabled TLS
show_enabled = function(v){
return (v==0) ? _('ID_DISABLED') : _('ID_ENABLED');
};
//New AuthSource Action
NewAuthSource = function(){
location.href = 'authSources_SelectType';
};
//Edit AuthSource Action
EditAuthSource = function(){
var rowSelected = infoGrid.getSelectionModel().getSelected();
if (rowSelected){
location.href = 'authSources_Edit?sUID=' +rowSelected.data.AUTH_SOURCE_UID;
}
};
//Delete AuthSource Action
DeleteAuthSource = function(){
var rowSelected = infoGrid.getSelectionModel().getSelected();
if (rowSelected){
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'authSources_Ajax',
params: {action: 'canDeleteAuthSource', auth_uid: rowSelected.data.AUTH_SOURCE_UID},
success: function(r,o){
viewport.getEl().unmask();
response = Ext.util.JSON.decode(r.responseText);
if (response.success){
Ext.Msg.confirm(_('ID_CONFIRM'),_('ID_CONFIRM_DELETE_AUTHENTICATION'),function(btn,text){
if (btn=='yes'){
viewport.getEl().mask(_('ID_PROCESSING'));
Ext.Ajax.request({
url: 'authSources_Ajax',
params: {action: 'deleteAuthSource', auth_uid : rowSelected.data.AUTH_SOURCE_UID},
success: function(r,o){
viewport.getEl().unmask();
resp = Ext.util.JSON.decode(r.responseText);
if (resp.success){
PMExt.notify(_('ID_AUTH_SOURCES'),_('ID_AUTHENTICATION_SUCCESS_DELETE'));
}else{
PMExt.error(_('ID_AUTH_SOURCES'),resp.error);
}
DoSearch();
editButton.disable();
deleteButton.disable();
usersButton.disable();
},
failure: function(r,o){
viewport.getEl().unmask();
}
});
}
});
}else{
PMExt.error(_('ID_AUTH_SOURCES'),_('ID_MSG_CANNOT_DELETE_AUTHENTICATION'));
}
},
failure: function(r,o){
viewport.getEl().unmask();
}
});
}
};
//Import Users Action
ImportUsers = function(){
var rowSelected = infoGrid.getSelectionModel().getSelected();
if (rowSelected){
location.href = 'authSources_SearchUsers?sUID=' +rowSelected.data.AUTH_SOURCE_UID;
}
};