Commit c42d96d7 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix a bug with public project + change visitor for member

parent 6793542d
...@@ -91,7 +91,7 @@ class tx_nG6_db { ...@@ -91,7 +91,7 @@ class tx_nG6_db {
// Is the user allowed to see this project // Is the user allowed to see this project
$user_allowed = false; $user_allowed = false;
if ($row['project_hidden'] == 0) { if ($row['project_hidden'] == 0 || $row['project_public'] == 0) {
$user_allowed = true; $user_allowed = true;
} }
...@@ -142,6 +142,15 @@ class tx_nG6_db { ...@@ -142,6 +142,15 @@ class tx_nG6_db {
* @return hash table with all runs information * @return hash table with all runs information
*/ */
function get_project_runs($user_id, $project_id, $orderby='', $limit='') { function get_project_runs($user_id, $project_id, $orderby='', $limit='') {
// where clause
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
$where .= ' AND tx_nG6_project.uid='.$project_id;
// First select all runs from the database // First select all runs from the database
$queryParts = Array( $queryParts = Array(
'SELECT' => 'tx_nG6_run.uid AS run_id,'. 'SELECT' => 'tx_nG6_run.uid AS run_id,'.
...@@ -162,7 +171,7 @@ class tx_nG6_db { ...@@ -162,7 +171,7 @@ class tx_nG6_db {
'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '. 'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '.
'INNER JOIN tx_nG6_project_run ON tx_nG6_project.uid=tx_nG6_project_run.project_id '. 'INNER JOIN tx_nG6_project_run ON tx_nG6_project.uid=tx_nG6_project_run.project_id '.
'INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ', 'INNER JOIN tx_nG6_run ON tx_nG6_project_run.run_id=tx_nG6_run.uid ',
'WHERE' => 'tx_nG6_project.uid='.$project_id.' AND fe_rights.fe_user_id='.$user_id, 'WHERE' => $where,
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => $orderby, 'ORDERBY' => $orderby,
'LIMIT' => $limit 'LIMIT' => $limit
...@@ -209,7 +218,16 @@ class tx_nG6_db { ...@@ -209,7 +218,16 @@ class tx_nG6_db {
* @return hash table with all analysis information * @return hash table with all analysis information
*/ */
function get_project_analysis($user_id, $project_id, $orderby='', $limit='') { function get_project_analysis($user_id, $project_id, $orderby='', $limit='') {
// First select all analysis from the database
// where clause
if (!$GLOBALS['TSFE']->loginUser) {
$where = 'tx_nG6_project.public=0';
} else {
$where = 'fe_rights.fe_user_id='.$user_id;
}
$where .= ' AND tx_nG6_project.uid='.$project_id;
// First select all analysis from the database
$queryParts = array( $queryParts = array(
'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'. 'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
'tx_nG6_analyze.directory AS analyze_directory,'. 'tx_nG6_analyze.directory AS analyze_directory,'.
...@@ -226,7 +244,7 @@ class tx_nG6_db { ...@@ -226,7 +244,7 @@ class tx_nG6_db {
'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '. 'INNER JOIN tx_nG6_project ON fe_rights.project_id=tx_nG6_project.uid '.
'INNER JOIN tx_nG6_project_analyze ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id '. 'INNER JOIN tx_nG6_project_analyze ON tx_nG6_project.uid = tx_nG6_project_analyze.project_id '.
'INNER JOIN tx_nG6_analyze ON tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id ', 'INNER JOIN tx_nG6_analyze ON tx_nG6_analyze.uid=tx_nG6_project_analyze.analyze_id ',
'WHERE' => 'tx_nG6_project_analyze.project_id='.$project_id.' AND fe_rights.fe_user_id='.$user_id, 'WHERE' => $where,
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => $orderby, 'ORDERBY' => $orderby,
'LIMIT' => $limit 'LIMIT' => $limit
...@@ -1161,35 +1179,32 @@ class tx_nG6_db { ...@@ -1161,35 +1179,32 @@ class tx_nG6_db {
* @param int $user_id the user id * @param int $user_id the user id
*/ */
function get_user_right_on_project($user_id, $project_id) { function get_user_right_on_project($user_id, $project_id) {
$right = array(); $right_id = -1;
$queryParts = array( $queryParts = array(
'SELECT' => 'fe_rights_levels.right_level_id AS right_id, '. 'SELECT' => 'fe_rights.right_id AS right_id ',
'fe_rights_levels.right_level_label AS right_label ', 'FROM' => 'fe_rights',
'FROM' => 'fe_rights INNER JOIN fe_rights_levels ON fe_rights.right_id=fe_rights_levels.right_level_id ',
'WHERE' => 'fe_rights.fe_user_id='. $user_id .' AND fe_rights.project_id='.$project_id 'WHERE' => 'fe_rights.fe_user_id='. $user_id .' AND fe_rights.project_id='.$project_id
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$right['id'] = $row['right_id']; $right_id = $row['right_id'];
$right['label'] = $row['right_label']; }
} return $right_id;
return $right;
} }
/** /**
* Return true if the user is a visitor on the project * Return true if the user is a member on the project
* *
* @param int $user_id the user id * @param int $user_id the user id
* @param int $project_id ths project id * @param int $project_id ths project id
*/ */
function is_project_visitor($user_id, $project_id){ function is_project_member($user_id, $project_id){
$is_visitor = false; $is_member = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id); $right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'visitor') { if ($right == 0) {
$is_visitor = true; $is_member = true;
} }
return $is_visitor; return $is_member;
} }
/** /**
...@@ -1200,8 +1215,8 @@ class tx_nG6_db { ...@@ -1200,8 +1215,8 @@ class tx_nG6_db {
*/ */
function is_project_manager($user_id, $project_id){ function is_project_manager($user_id, $project_id){
$is_manager = false; $is_manager = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id); $right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'manager') { if ($right == 1) {
$is_manager = true; $is_manager = true;
} }
return $is_manager; return $is_manager;
...@@ -1215,66 +1230,66 @@ class tx_nG6_db { ...@@ -1215,66 +1230,66 @@ class tx_nG6_db {
*/ */
function is_project_administrator($user_id, $project_id){ function is_project_administrator($user_id, $project_id){
$is_admin = false; $is_admin = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id); $right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'administrator') { if ($right == 2) {
$is_admin = true; $is_admin = true;
} }
return $is_admin; return $is_admin;
} }
/* /*
* DB integrity functions * DB integrity functions
*------------------------------------------------------------*/ *------------------------------------------------------------*/
/** /**
* Check the integrity of 'fe_rights_levels' table. * Check the integrity of 'fe_rights_levels' table.
*/ */
function check_db_rights_level(){ function check_db_rights_level(){
$queryParts = Array( $queryParts = Array(
'SELECT' => 'fe_rights_levels.right_level_id, fe_rights_levels.right_level_label ', 'SELECT' => 'fe_rights_levels.right_level_id, fe_rights_levels.right_level_label ',
'FROM' => 'fe_rights_levels ', 'FROM' => 'fe_rights_levels ',
'WHERE' => '', 'WHERE' => '',
'GROUPBY' => '', 'GROUPBY' => '',
'ORDERBY' => '', 'ORDERBY' => '',
'LIMIT' => '', 'LIMIT' => '',
); );
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts); $res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
$res_tab = array(); $res_tab = array();
while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { while($res_row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$res_tab = array( $res_tab = array(
'id' => $res_row['right_level_id'], 'id' => $res_row['right_level_id'],
'label' => $res_row['right_level_label'] 'label' => $res_row['right_level_label']
); );
} }
// insert // insert
if( !in_array('visitor', array_values($res_tab)) ){ if( !in_array('member', array_values($res_tab)) ){
$insert_rows = Array( $insert_rows = Array(
'right_level_id' => 0, 'right_level_id' => 0,
'right_level_label' => 'visitor' 'right_level_label' => 'member'
); );
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows); $GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows);
} }
if( !in_array('manager', array_values($res_tab)) ){ if( !in_array('manager', array_values($res_tab)) ){
$insert_rows = Array( $insert_rows = Array(
'right_level_id' => 1, 'right_level_id' => 1,
'right_level_label' => 'manager' 'right_level_label' => 'manager'
); );
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows); $GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows);
} }
if( !in_array('administrator', array_values($res_tab)) ){ if( !in_array('administrator', array_values($res_tab)) ){
$insert_rows = Array( $insert_rows = Array(
'right_level_id' => 2, 'right_level_id' => 2,
'right_level_label' => 'administrator' 'right_level_label' => 'administrator'
); );
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows); $GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows);
} }
} }
} }
if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_db.php']) { if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_db.php']) {
......
...@@ -72,7 +72,7 @@ class tx_nG6_upgrade { ...@@ -72,7 +72,7 @@ class tx_nG6_upgrade {
// users in the current group // users in the current group
$group_users = tx_nG6_upgrade::get_all_users_in_group($current_group); $group_users = tx_nG6_upgrade::get_all_users_in_group($current_group);
// set current group users' right to "visitor" // set current group users' right to "member"
foreach($group_users as $id => $user_id){ foreach($group_users as $id => $user_id){
tx_nG6_upgrade::assign_right($user_id, $project_id, 0); tx_nG6_upgrade::assign_right($user_id, $project_id, 0);
} }
...@@ -107,7 +107,7 @@ class tx_nG6_upgrade { ...@@ -107,7 +107,7 @@ class tx_nG6_upgrade {
* *
* @param int $user_id the user id * @param int $user_id the user id
* @param int $project_id the project id * @param int $project_id the project id
* @param int $right the right id (0=visitor, 1=manager, 2=admininistrator) * @param int $right the right id (0=member, 1=manager, 2=admininistrator)
*/ */
function assign_right($user_id, $project_id, $right){ function assign_right($user_id, $project_id, $right){
$assign_right = Array( $assign_right = Array(
...@@ -195,4 +195,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/cla ...@@ -195,4 +195,4 @@ if (defined('TYPO3_MODE') && $TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/cla
include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_upgrade.php']); include_once($TYPO3_CONF_VARS[TYPO3_MODE]['XCLASS']['ext/nG6/class.tx_nG6_upgrade.php']);
} }
?> ?>
\ No newline at end of file
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