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 {
// Is the user allowed to see this project
$user_allowed = false;
if ($row['project_hidden'] == 0) {
if ($row['project_hidden'] == 0 || $row['project_public'] == 0) {
$user_allowed = true;
}
......@@ -142,6 +142,15 @@ class tx_nG6_db {
* @return hash table with all runs information
*/
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
$queryParts = Array(
'SELECT' => 'tx_nG6_run.uid AS run_id,'.
......@@ -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_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 ',
'WHERE' => 'tx_nG6_project.uid='.$project_id.' AND fe_rights.fe_user_id='.$user_id,
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
......@@ -209,6 +218,15 @@ class tx_nG6_db {
* @return hash table with all analysis information
*/
function get_project_analysis($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 analysis from the database
$queryParts = array(
'SELECT' => 'tx_nG6_analyze.uid AS analyze_id,'.
......@@ -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_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 ',
'WHERE' => 'tx_nG6_project_analyze.project_id='.$project_id.' AND fe_rights.fe_user_id='.$user_id,
'WHERE' => $where,
'GROUPBY' => '',
'ORDERBY' => $orderby,
'LIMIT' => $limit
......@@ -1161,35 +1179,32 @@ class tx_nG6_db {
* @param int $user_id the user id
*/
function get_user_right_on_project($user_id, $project_id) {
$right = array();
$right_id = -1;
$queryParts = array(
'SELECT' => 'fe_rights_levels.right_level_id AS right_id, '.
'fe_rights_levels.right_level_label AS right_label ',
'FROM' => 'fe_rights INNER JOIN fe_rights_levels ON fe_rights.right_id=fe_rights_levels.right_level_id ',
'SELECT' => 'fe_rights.right_id AS right_id ',
'FROM' => 'fe_rights',
'WHERE' => 'fe_rights.fe_user_id='. $user_id .' AND fe_rights.project_id='.$project_id
);
$res = $GLOBALS['TYPO3_DB']->exec_SELECT_queryArray($queryParts);
while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
$right['id'] = $row['right_id'];
$right['label'] = $row['right_label'];
$right_id = $row['right_id'];
}
return $right;
return $right_id;
}
/**
* 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 $project_id ths project id
*/
function is_project_visitor($user_id, $project_id){
$is_visitor = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'visitor') {
$is_visitor = true;
function is_project_member($user_id, $project_id){
$is_member = false;
$right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($right == 0) {
$is_member = true;
}
return $is_visitor;
return $is_member;
}
/**
......@@ -1200,8 +1215,8 @@ class tx_nG6_db {
*/
function is_project_manager($user_id, $project_id){
$is_manager = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'manager') {
$right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($right == 1) {
$is_manager = true;
}
return $is_manager;
......@@ -1215,14 +1230,15 @@ class tx_nG6_db {
*/
function is_project_administrator($user_id, $project_id){
$is_admin = false;
$rights = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($rights['label'] == 'administrator') {
$right = tx_nG6_db::get_user_right_on_project($user_id, $project_id);
if ($right == 2) {
$is_admin = true;
}
return $is_admin;
}
/*
* DB integrity functions
*------------------------------------------------------------*/
......@@ -1250,10 +1266,10 @@ class tx_nG6_db {
}
// insert
if( !in_array('visitor', array_values($res_tab)) ){
if( !in_array('member', array_values($res_tab)) ){
$insert_rows = Array(
'right_level_id' => 0,
'right_level_label' => 'visitor'
'right_level_label' => 'member'
);
$GLOBALS['TYPO3_DB']->exec_INSERTquery('fe_rights_levels', $insert_rows);
}
......@@ -1274,7 +1290,6 @@ class tx_nG6_db {
$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']) {
......
......@@ -72,7 +72,7 @@ class tx_nG6_upgrade {
// users in the 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){
tx_nG6_upgrade::assign_right($user_id, $project_id, 0);
}
......@@ -107,7 +107,7 @@ class tx_nG6_upgrade {
*
* @param int $user_id the user 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){
$assign_right = Array(
......
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