Commit 5ced54a6 authored by Romain Therville's avatar Romain Therville 🐭

Merge branch 'issue#126' into 'master'

Merge branch issue#126 with master

See merge request !57
parents 68b81722 8148ac2a
......@@ -1150,7 +1150,8 @@ INSERT INTO `be_users` (`uid`, `pid`, `tstamp`, `username`, `password`, `admin`,
INSERT INTO `fe_groups` (`uid`, `pid`, `tstamp`, `crdate`, `cruser_id`, `title`, `hidden`, `lockToDomain`, `deleted`, `description`, `subgroup`, `TSconfig`, `tx_extbase_type`, `felogin_redirectPid`) VALUES
(1, 5, 1381241108, 1381241108, 1, 'ng6_admin', 0, '', 0, '', '', '', '0', '');
INSERT INTO `fe_groups` (`uid`, `pid`, `tstamp`, `crdate`, `cruser_id`, `title`, `hidden`, `lockToDomain`, `deleted`, `description`, `subgroup`, `TSconfig`, `tx_extbase_type`, `felogin_redirectPid`) VALUES
(2, 5, 1381241108, 1381241108, 1, 'ng6_superadmin', 0, '', 0, '', '', '', '0', '');
INSERT INTO `fe_rights` (`fe_user_id`, `project_id`, `right_id`) VALUES
(1, 1, 2);
......@@ -1212,25 +1213,25 @@ INSERT INTO `tx_nG6_project` (`uid`, `pid`, `tstamp`, `crdate`, `cruser_id`, `de
--
-- Structure de la vue `tx_nG6_view_project_analyze`
--
CREATE ALGORITHM=UNDEFINED DEFINER=`typo3`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_analyze` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_analyze`.`uid` AS `analyze_id`,`tx_nG6_analyze`.`storage_size` AS `storage_size`,`tx_nG6_analyze`.`purged_size` AS `purged_size`,`tx_nG6_analyze`.`data_state` AS `state`,`tx_nG6_analyze`.`retention_date` AS `retention_date`,`tx_nG6_analyze`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_analyze`.`hidden` AS `hidden` from ((`tx_nG6_project` join `tx_nG6_project_analyze` on((`tx_nG6_project_analyze`.`project_id` = `tx_nG6_project`.`uid`))) join `tx_nG6_analyze` on((`tx_nG6_project_analyze`.`analyze_id` = `tx_nG6_analyze`.`uid`)));
CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_analyze` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_analyze`.`uid` AS `analyze_id`,`tx_nG6_analyze`.`storage_size` AS `storage_size`,`tx_nG6_analyze`.`purged_size` AS `purged_size`,`tx_nG6_analyze`.`data_state` AS `state`,`tx_nG6_analyze`.`retention_date` AS `retention_date`,`tx_nG6_analyze`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_analyze`.`hidden` AS `hidden` from ((`tx_nG6_project` join `tx_nG6_project_analyze` on((`tx_nG6_project_analyze`.`project_id` = `tx_nG6_project`.`uid`))) join `tx_nG6_analyze` on((`tx_nG6_project_analyze`.`analyze_id` = `tx_nG6_analyze`.`uid`)));
--
-- Structure de la vue `tx_nG6_view_project_run`
--
CREATE ALGORITHM=UNDEFINED DEFINER=`typo3`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_run` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_run`.`uid` AS `run_id`,`tx_nG6_run`.`storage_size` AS `storage_size`,`tx_nG6_run`.`purged_size` AS `purged_size`,`tx_nG6_run`.`data_state` AS `state`,`tx_nG6_run`.`retention_date` AS `retention_date`,`tx_nG6_run`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_run`.`hidden` AS `hidden` from ((`tx_nG6_run` join `tx_nG6_project_run` on((`tx_nG6_project_run`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_project` on((`tx_nG6_project`.`uid` = `tx_nG6_project_run`.`project_id`)));
CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_run` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_run`.`uid` AS `run_id`,`tx_nG6_run`.`storage_size` AS `storage_size`,`tx_nG6_run`.`purged_size` AS `purged_size`,`tx_nG6_run`.`data_state` AS `state`,`tx_nG6_run`.`retention_date` AS `retention_date`,`tx_nG6_run`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_run`.`hidden` AS `hidden` from ((`tx_nG6_run` join `tx_nG6_project_run` on((`tx_nG6_project_run`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_project` on((`tx_nG6_project`.`uid` = `tx_nG6_project_run`.`project_id`)));
--
-- Structure de la vue `tx_nG6_view_project_run_analyze`
--
CREATE ALGORITHM=UNDEFINED DEFINER=`typo3`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_run_analyze` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_analyze`.`uid` AS `analyze_id`,`tx_nG6_analyze`.`storage_size` AS `storage_size`,`tx_nG6_analyze`.`purged_size` AS `purged_size`,`tx_nG6_analyze`.`data_state` AS `state`,`tx_nG6_analyze`.`retention_date` AS `retention_date`,`tx_nG6_analyze`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_analyze`.`hidden` AS `hidden` from ((((`tx_nG6_run` join `tx_nG6_project_run` on((`tx_nG6_project_run`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_project` on((`tx_nG6_project`.`uid` = `tx_nG6_project_run`.`project_id`))) join `tx_nG6_run_analyze` on((`tx_nG6_run_analyze`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_analyze` on((`tx_nG6_run_analyze`.`analyze_id` = `tx_nG6_analyze`.`uid`)));
CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_run_analyze` AS select `tx_nG6_project`.`uid` AS `project_id`,`tx_nG6_project`.`name` AS `project_name`,`tx_nG6_analyze`.`uid` AS `analyze_id`,`tx_nG6_analyze`.`storage_size` AS `storage_size`,`tx_nG6_analyze`.`purged_size` AS `purged_size`,`tx_nG6_analyze`.`data_state` AS `state`,`tx_nG6_analyze`.`retention_date` AS `retention_date`,`tx_nG6_analyze`.`purge_demand_id` AS `purge_demand_id`, `tx_nG6_analyze`.`hidden` AS `hidden` from ((((`tx_nG6_run` join `tx_nG6_project_run` on((`tx_nG6_project_run`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_project` on((`tx_nG6_project`.`uid` = `tx_nG6_project_run`.`project_id`))) join `tx_nG6_run_analyze` on((`tx_nG6_run_analyze`.`run_id` = `tx_nG6_run`.`uid`))) join `tx_nG6_analyze` on((`tx_nG6_run_analyze`.`analyze_id` = `tx_nG6_analyze`.`uid`)));
--
-- Structure de la vue `tx_nG6_view_project_user`
--
CREATE ALGORITHM=UNDEFINED DEFINER=`typo3`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_user` AS select `tx_nG6_project`.`uid` AS `project_id`,`fe_users`.`uid` AS `user_id`, `fe_users`.`username` AS `user_name`,`fe_users`.`email` AS `email`,`fe_users`.`usergroup` AS `user_group`,`fe_rights_levels`.`right_level_label` AS `right_level_label`,`fe_groups`.`title` AS `user_group_title` from ((((`tx_nG6_project` join `fe_rights` on((`fe_rights`.`project_id` = `tx_nG6_project`.`uid`))) join `fe_users` on((`fe_rights`.`fe_user_id` = `fe_users`.`uid`))) join `fe_groups` on((`fe_users`.`usergroup` = `fe_groups`.`uid`))) join `fe_rights_levels` on((`fe_rights_levels`.`right_level_id` = `fe_rights`.`right_id`)));
CREATE ALGORITHM=UNDEFINED DEFINER=`ng6`@`localhost` SQL SECURITY DEFINER VIEW `tx_nG6_view_project_user` AS select `tx_nG6_project`.`uid` AS `project_id`,`fe_users`.`uid` AS `user_id`, `fe_users`.`username` AS `user_name`,`fe_users`.`email` AS `email`,`fe_users`.`usergroup` AS `user_group`,`fe_rights_levels`.`right_level_label` AS `right_level_label`,`fe_groups`.`title` AS `user_group_title` from ((((`tx_nG6_project` join `fe_rights` on((`fe_rights`.`project_id` = `tx_nG6_project`.`uid`))) join `fe_users` on((`fe_rights`.`fe_user_id` = `fe_users`.`uid`))) join `fe_groups` on((`fe_users`.`usergroup` = `fe_groups`.`uid`))) join `fe_rights_levels` on((`fe_rights_levels`.`right_level_id` = `fe_rights`.`right_id`)));
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
......
......@@ -632,6 +632,15 @@ class tx_nG6_eid {
$userids = explode(',', $userids);
tx_nG6_db::remove_from_ng6_admin($userids);
}
else if ( $type == 'add_to_ng6_superadmin'){
$userid = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userid'));
tx_nG6_db::add_to_ng6_superadmin($userid);
}
else if ( $type == 'delete_from_ng6_superadmin'){
$userids = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('userids'));
$userids = explode(',', $userids);
tx_nG6_db::remove_from_ng6_superadmin($userids);
}
else if($type == 'update_user'){
$email = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('email'));
$first_name = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::_GP('first_name'));
......
......@@ -1086,6 +1086,45 @@ INNER JOIN fe_groups ON fe_groups.uid = fe_users.usergroup',
}
return $projects;
}
/**
* Select all project for the superadmin
*
* @param string $user_id the user id
* @return table with all projects
*/
static function select_superadmin_projects() {
$projects = array();
$queryParts = array(
'SELECT' => 'tx_nG6_project.uid AS project_id, '.
'tx_nG6_project.name AS project_name, '.
'tx_nG6_project.description AS project_description, '.
'tx_nG6_project.public AS project_public, '.
'tx_nG6_project.crdate AS project_crdate, '.
'tx_nG6_project.hidden AS project_hidden ',
'FROM' => 'tx_nG6_project',
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$project_id = $row['project_id'];
if (!isset ($projects['project_'.$project_id])) {
$projects['project_'.$project_id] = array(
'id' => $project_id,
'name' => $row['project_name'],
'hidden' => $row['project_hidden'],
'date' => $row['project_crdate'],
'public' => $row['project_public'],
'description' => $row['project_description']);
}
}
return $projects;
}
/**
* Select a run from the database
......@@ -3424,6 +3463,130 @@ static function get_project_runs($project_id, $orderby='', $limit='') {
return $res_tab;
}
/**
* Returns true if the user belongs to the ng6 superadmin group
*
* @param string $user_id The user id
* @param unknown $user_id
*/
static function is_user_ng6_superadmin($user_id){
$is_ng6_superadmin = false;
if( $user_id != null){
$usergroup = null;
$queryParts = Array(
'SELECT' => 'fe_users.usergroup',
'FROM' => 'fe_users',
'WHERE' => 'fe_users.uid='.$user_id,
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$usergroup = $res_row['usergroup'];
}
$groups = explode ( ',', $usergroup) ;
$superadmin_group_id = tx_nG6_db::get_superadmin_group_id();
if (in_array($superadmin_group_id, $groups)){
$is_ng6_superadmin = true;
}
}
return $is_ng6_superadmin;
}
/**
* Returns the id of the ng6 superadmin group
*
*
*/
static function get_superadmin_group_id(){
$queryParts = array(
'SELECT' => 'uid',
'FROM' => 'fe_groups',
'WHERE' => "fe_groups.title='ng6_superadmin'",
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => ''
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$superadmin_group_id = NULL;
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$superadmin_group_id = $row['uid'];
}
return $superadmin_group_id;
}
/**
* Returns the list of ng6_superadmin users
*/
static function get_ng6_superadmin_users(){
$ng6_superadmin_users = null;
$queryParts = Array(
'SELECT' => 'fe_users.uid, fe_users.username, fe_users.first_name, fe_users.last_name, fe_users.email',
'FROM' => 'fe_users',
'WHERE' => '',
'GROUPBY' => '',
'ORDERBY' => '',
'LIMIT' => '',
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
if (tx_nG6_db::is_user_ng6_superadmin($res_row['uid'])){
$ng6_superadmin_users[ ] = array(
'id' => $res_row['uid'],
'username' => $res_row['username'],
'first_name' => $res_row['first_name'],
'last_name' => $res_row['last_name'],
'email' => $res_row['email']
);
}
}
return $ng6_superadmin_users;
}
/**
* Add an existing user to the ng6_superadmin group
* @param unknown $userid
*/
static function add_to_ng6_superadmin( $userid ){
$user_info = tx_nG6_db::get_user_informations($userid);
$pieces = explode(",", $user_info['usergroup']);
$superadmin_group_id = tx_nG6_db::get_superadmin_group_id();
if (!in_array($superadmin_group_id, $pieces)) {
$pieces [] = $superadmin_group_id;
$group = implode(",", $pieces);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery ('fe_users', 'fe_users.uid='.$userid, array('fe_users.usergroup' => $group));
}
}
/**
* Remove an user from the ng6_superadmin group
* @param unknown $userids
*/
static function remove_from_ng6_superadmin( $userids ){
$superadmin_group_id = tx_nG6_db::get_superadmin_group_id();
foreach ($userids as $userid){
$user_info = tx_nG6_db::get_user_informations($userid);
$pieces = explode(",", $user_info['usergroup']);
if (in_array($superadmin_group_id, $pieces)){
unset($pieces[array_search($superadmin_group_id,$pieces)]);
$group = implode(",", $pieces);
$GLOBALS['TYPO3_DB']->exec_UPDATEquery ('fe_users', 'fe_users.uid='.$userid, array('fe_users.usergroup' => $group));
}
}
}
/*
* DB integrity functions
*------------------------------------------------------------*/
......
......@@ -138,6 +138,8 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
$projects = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$single_project_display = false;
// If a single element
......@@ -145,10 +147,18 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id'])) {
$projects = array('project_'.$this->piVars['project_id'] => tx_nG6_db::select_project($this->piVars['project_id']));
$single_project_display = true ;
}elseif( $is_current_user_superadmin ){
$projects = array('project_'.$this->piVars['project_id'] => tx_nG6_db::select_project($this->piVars['project_id']));
$single_project_display = true ;
}
} else {
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.uid DESC');
//$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
if( $is_current_user_superadmin ){
$projects = tx_nG6_db::select_superadmin_projects();
}else{
$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.uid DESC');
//$projects = tx_nG6_db::select_all_user_projects($user_id, 'tx_nG6_project.name');
}
}
// If there is no project the user can access
......@@ -170,6 +180,11 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
// project member ?
$projects[$project_id]['is_member'] = tx_nG6_db::is_project_member($GLOBALS['TSFE']->fe_user->user['uid'], $project_values['id']);
//If the user is a superadmin, we set its rights to admin on each project
if( $is_current_user_superadmin ){
$projects[$project_id]['is_admin'] = true;
}
$project_ids .= $project_values['id'].",";
$projects[$project_id]['href'] = $this->pi_list_linkSingle($project_values['name'],$project_values['id'],1, array('project_id'=>$project_values['id']));
}
......@@ -184,7 +199,7 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
$smarty->assign('pid', $this->conf['userpidList']);
$smarty->assign('server_url', $this->conf['server_url']);
$smarty->assign('single_project_display', $single_project_display);
$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) ? true : false);
$smarty->assign('is_ng6_admin', tx_nG6_db::is_ng6_administrator($user_id) || tx_nG6_db::is_user_ng6_superadmin($user_id) ? true : false);
// If it's a single project, add runs and analysis information
if ($single_project_display) {
......@@ -201,6 +216,11 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
$project_runs = tx_nG6_db::get_project_runs($projects[key($projects)]['id']);
foreach($project_runs as $run_id => $run_values) {
$project_runs[$run_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'run', $run_values['id']);
if( $is_current_user_superadmin ){
$project_runs[$run_id]['is_admin'] = 1;
}
$project_runs[$run_id]['href'] = $this->pi_list_linkSingle($run_values['name'],$run_values['id'],1, array('run_id'=>$run_values['id'], 'project_id'=>$run_values['project_id']));
}
$smarty->assign('project_runs', $project_runs);
......@@ -209,6 +229,11 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
// Add some information to the table
foreach($project_analysis as $analysis_id => $analysis_values) {
$project_analysis[$analysis_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']);
if( $is_current_user_superadmin ){
$project_analysis[$analysis_id]['is_admin'] = 1;
}
$project_analysis[$analysis_id]['href'] = $this->pi_list_linkSingle($analysis_values['name'],$analysis_values['id'],1, array('analyze_id'=>$analysis_values['id'], 'project_id'=>$this->piVars['project_id']));
}
$smarty->assign('h_analysis', tx_nG6_utils::trace_hierarchy($project_analysis));
......@@ -242,11 +267,12 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
$runs = array();
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$single_run_display = false;
// If a single element
if ($this->piVars['run_id']) {
if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id'])) {
if (tx_nG6_db::user_is_authorized($user_id, $this->piVars['project_id'], $this->piVars['run_id']) || $is_current_user_superadmin ) {
$runs = array('run_'.$this->piVars['run_id'] => tx_nG6_db::select_run($this->piVars['run_id']));
$single_run_display = true;
}
......@@ -266,7 +292,7 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
// Add some information to the table
$run_ids = "";
foreach($runs as $run_id => $run_values) {
if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) ) {
if (tx_nG6_db::is_administrator($user_id, 'run', $run_values['id']) || $is_current_user_superadmin ) {
$runs[$run_id]['is_admin'] = true;
} else {
$runs[$run_id]['is_admin'] = false;
......@@ -299,6 +325,9 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
// Add some information to the table
foreach($run_analysis as $analysis_id => $analysis_values) {
$run_analysis[$analysis_id]['is_admin'] = tx_nG6_db::is_administrator($GLOBALS['TSFE']->fe_user->user['uid'], 'analyze', $analysis_values['id']);
if($is_current_user_superadmin){
$run_analysis[$analysis_id]['is_admin'] = 1;
}
if ($this->piVars['project_id']) {
$run_analysis[$analysis_id]['href'] = $this->pi_list_linkSingle($analysis_values['name'],$analysis_values['id'],1, array('analyze_id'=>$analysis_values['id'], 'project_id'=>$this->piVars['project_id'], 'run_id'=>$this->piVars['run_id']));
} else {
......@@ -321,6 +350,7 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
function pi_analyze_view() {
if (!$GLOBALS['TSFE']->loginUser) { $user_id = null; }
else { $user_id = $GLOBALS['TSFE']->fe_user->user['uid']; }
$is_current_user_superadmin = tx_nG6_db::is_user_ng6_superadmin($user_id);
$smarty = new Smarty();
$smarty->setTemplateDir(\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('nG6').'/pi1/analyzes');
......@@ -336,7 +366,9 @@ class tx_nG6_pi1 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
// is project admin
$is_project_admin = tx_nG6_db::is_project_administrator($GLOBALS['TSFE']->fe_user->user['uid'], $analyse['project_id']);
if (tx_nG6_db::user_is_authorized($user_id, $analyse['project_id'], $this->piVars['run_id'])) {
if( $is_current_user_superadmin ){ $is_project_admin = 1; }
if (tx_nG6_db::user_is_authorized($user_id, $analyse['project_id'], $this->piVars['run_id']) || $is_current_user_superadmin ) {
if ($is_project_admin || $analyse['hidden'] == "0") {
// Handle old fashion
......
......@@ -266,8 +266,59 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
</tfoot>
</table>
</div>
</div>
{if $is_current_user_superadmin}
<div id="superadmin_users">
<p></br>This table allows you to manage every ng6 superadmin</p>
<table class="table table-striped table-bordered dataTable" id="superadmin_users_data_table">
<thead>
<tr>
<th><center></th>
<th>Login</th>
<th>Last name</th>
<th>First name</th>
<th>Email</th>
</tr>
</thead>
<tbody>
{foreach from=$ng6_superadmin_users key=c_user_id item=user_values}
{* highlight user personnal line *}
{assign var="emphasis" value=""}
{if $user_values.id==$user_id}
{assign var="emphasis" value="tx-nG6-pi1-line-emphasis"}
{/if}
<tr id="tr_user_{$user_values.id}" class="{$emphasis}">
{if $user_values.id == $user_id }
<td></td>
{else}
<td><center><input type="checkbox" id="chk_user_{$user_values.id}" value="user_{$user_values.id}" /></center></td>
{/if}
<td>{$user_values.username}</td>
<td>{$user_values.last_name}</td>
<td>{$user_values.first_name}</td>
<td>{$user_values.email}</td>
</tr>
{/foreach}
</tbody>
<tfoot>
<tr>
<th align="left" colspan="8">
With selection :
<div class="btn-group">
<button id="add_superadmin" type="button" class="btn btn-sm btn-default" ><i class="glyphicon glyphicon-plus"></i> add user</button>
<button id="del_superadmin" type="button" class="btn multipleu-selection-btn btn-sm btn-default"><i class="glyphicon glyphicon-minus"></i> delete user</button>
</div>
</th>
</tr>
</tfoot>
</table>
</div>
{/if}
</div>
<div class="tab-pane fade" id="wf_monitoring"></div>
<div class="tab-pane fade" id="project_data_management">
<div id="purge_menu" class="clearfix">
......
......@@ -96,6 +96,10 @@ class tx_nG6_pi6 extends \TYPO3\CMS\Frontend\Plugin\AbstractPlugin {
$distribution = tx_nG6_db::select_projects_repartition('create_user', 'title');
$smarty->assign('distribution', $distribution);
$smarty->assign('ng6_admin_users', tx_nG6_db::get_ng6_admin_users() );
$smarty->assign('ng6_superadmin_users', tx_nG6_db::get_ng6_superadmin_users() );
$smarty->assign('is_current_user_superadmin', tx_nG6_db::is_user_ng6_superadmin($GLOBALS['TSFE']->fe_user->user['uid']) );
$smarty->assign('ng6_purge_delay',$this->conf['delay_purge']);
return $smarty->fetch('administration_view.tpl');
......
......@@ -327,6 +327,171 @@ $(function () {
});
});
/****************************************
*
* SUPERADMINS MANAGEMENT
*
***************************************/
$('#add_superadmin').click(function(){
$("#modal-label-tmpl").html("Add a new ng6 superadmin user");
var add_ng6_superadmin = [
'<div id="error_message" class="alert alert-danger"><button class="close" data-dismiss="alert" type="button">x</button></div>',
'<div class="tx-nG6-pi1-add-new">Seek the user using the autocompletion fields<br /> <br /> ',
' <form class="form-horizontal" id="new_ng6_superadmin_user">',
' <input type="hidden" id="userid_val" name="userid_val" />',
' <input type="hidden" id="added_userid_val" name="added_userid_val" />',
' <div class="form-group">',
' <label class="col-sm-offset-3 col-sm-2 control-label">Login</label>',
' <div class="col-sm-7">',
' <input type="text" id="username_val" class="form-control typeahead" name="username_val" placeholder="Login"/>',
' </div>',
' </div>',
' <div class="form-group">',
' <label class="col-sm-offset-3 col-sm-2 control-label">Last name</label>',
' <div class="col-sm-7">',
' <input type="text" id="last_name_val" class="form-control typeahead" name="last_name_val" placeholder="Last name"/> ',
' </div>',
' </div>',
' <div class="form-group">',
' <label class="col-sm-offset-3 col-sm-2 control-label">First name</label>',
' <div class="col-sm-7">',
' <input type="text" id="first_name_val" class="form-control typeahead" name="first_name_val" placeholder="First name"/>',
' </div>',
' </div>',
' </form>',
'</div>'].join('');
$("#modal-body-tmpl").html(add_ng6_superadmin);
$("#modal-foot-tmpl").html('<button class="btn btn-default" id="raz_form"><i class="glyphicon glyphicon-repeat"></i> Clear form</a>' +
'<button class="btn btn-default" data-dismiss="modal" aria-hidden="true"><i class="glyphicon glyphicon-remove"></i> Close</button>' +
'<button id="modal-btn-addng6superadmin" class="btn btn-primary"><i class="glyphicon glyphicon-user"></i> Add</button>');
$("#ng6modal").modal().ready(function() {
$("#error_message").hide();
$('.typeahead').each(function(){
var $this = $(this);
$this.on('typeahead:selected', function(typeahead, item){
$("#new_member div.control-group").removeClass("error");
$(".btn-danger").removeClass("btn-danger");
$(".glyphicon-wrench").removeClass("icon-white");
$("#last_name_val").val(item.last_name);
$("#first_name_val").val(item.first_name);
$("#username_val").val(item.username);
$("#userid_val").val(item.uid);
lock_fields(1);
});
$this.typeahead({
minLength: 2,
autoselect: true
},{
displayKey : 'value',
source : function(query, process){
var gender = $this.attr("id").split("_val")[0];
$.ajax({
url: "index.php?eID=tx_nG6&type=autocomplete&gender="+gender+ "&name_start=" + query,
dataType: 'json',
success: function (users) {
var data = new Array();
for (index in users) {
users[index]['value'] = users[index][gender];
data.push(users[index]);
}
process(data);
}
});
}
});
});
// empty the form
$("#raz_form").click(function(){
$("#last_name_val").val("");
$("#first_name_val").val("");
$("#username_val").val("");
$("#userid_val").val("");
lock_fields(0); // unlock fields
$(".btn-danger").removeClass("btn-danger");
$(".glyphicon-wrench").removeClass("icon-white");
$("#error_message").hide();
});
// lock/unlock fields when autocomplete
function lock_fields(order){
// lock fields
if(order == 1){
$("#username_val").attr('disabled', 'disabled');
$("#last_name_val").attr('disabled', 'disabled');
$("#first_name_val").attr('disabled', 'disabled');
$('.group_typeahead').each(function(){
$(this).css('background-color','');
});
} else if(order == 0){
$("#username_val").removeAttr('disabled');
$("#last_name_val").removeAttr('disabled');
$("#first_name_val").removeAttr('disabled');
}
}
if($("#username_val").attr('disabled') != 'disabled'){
$("#new_ng6_superadmin_user").validate({
rules: {
first_name_val: { required: true },
last_name_val: { required: true },
username_val: { required: true },
},
messages: {
first_name_val: null,
last_name_val: null,
username_val: null,
},
submitHandler: function(form) {
var val_url = "index.php?eID=tx_nG6&type=add_to_ng6_superadmin";
val_url += "&userid=" + $("#userid_val").val();
$.ajax({
url: val_url,
success: function(val) {
$("#ng6modal").modal('hide');
set_active_tab('admin_management');
}
});
}
});
}
});
$("#modal-btn-addng6superadmin").click( function() {
$("#new_ng6_superadmin_user").submit();
});
});
$('#del_superadmin').click(function(){
$("#modal-label-tmpl").html("Delete");
$("#modal-body-tmpl").html("Are you sure you want to delete this user from superadmin group?");
$("#modal-foot-tmpl").html('<button class="btn btn-default" data-dismiss="modal" aria-hidden="true">No</button>' +
'<button id="modal-btn-yes" class="btn btn-primary">Yes</button>');
$("#ng6modal").modal();
$("#modal-btn-yes").click( function() {
var val_url = "index.php?eID=tx_nG6&type=delete_from_ng6_superadmin";
val_url += "&userids=" ;
var arr = [];
$(':checked[id^=chk_user]').each(function(i){
arr.push( $(this).val().split("_" , 2)[1] );
});
val_url += arr.join(',');
$.ajax({
url: val_url,
success: function(val) {
$("#ng6modal").modal('hide');
set_active_tab('admin_management');
}
});
});
});
/****************************************
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment