View Issue Details

IDProjectCategoryView StatusLast Update
0017073mantisbtotherpublic2014-12-05 18:33
Reporteraavagyan Assigned Todregad  
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product Version1.2.17 
Target Version1.2.18Fixed in Version1.2.18 
Summary0017073: Incorrect $specific_where
Description

I run into problem while using $specific_where variable for my plugin. If user has access to only one project (or if there is only one project in bug tracker), $specific_where contains wrong value. It is used in number of places in Mantis - so this touches not only my plugin.

$specific_where is helper_project_specific_where() [helper_api.php]
This one is calling user_get_all_accessible_projects() [user_api.php] and have:

...
if( 0 == count( $t_project_ids ) ) {
$t_project_filter = ' 1<>1';
} else if( 1 == count( $t_project_ids ) ) {
$t_project_filter = ' project_id=' . $t_project_ids[0];
} else {
$t_project_filter = ' project_id IN (' . join( ',', $t_project_ids ) . ')';
}
...

Please look on this line:
$t_project_filter = ' project_id=' . $t_project_ids[0];

It assumes that the project is first element in array. Now lets look at user_get_all_accessible_projects(). In the case of "All projects", thee following code works:

...

Create a combined array where key = value

$t_project_ids = array_combine( $t_topprojects, $t_topprojects );
...

Then function returns $t_project_ids. Thus if "the only" project_id is, for example, 3 then key is also 3 and $t_project_ids[0] is naturally empty. As effect "} else if( 1 == count( $t_project_ids ) ) {" condition from above will work, but $t_project_filter will contain something like "project_id=" -> value is missing at the end.

TagsNo tags attached.

Activities

aavagyan

aavagyan

2014-03-08 18:35

reporter   ~0039633

To emphasize on point from above. The problem is present only when passing

$project_id = ALL_PROJECTS

dregad

dregad

2014-03-10 06:02

developer   ~0039640

Hello, and thanks for the bug report.

Can you kindly test with the following fix, I have no time to do it at the moment


diff --git a/core/helper_api.php b/core/helper_api.php
index 65efd1d..8579212 100644
--- a/core/helper_api.php
+++ b/core/helper_api.php
@@ -385,7 +385,7 @@ function helper_project_specific_where( $p_project_id, $p_user_id = null ) {
if( 0 == count( $t_project_ids ) ) {
$t_project_filter = ' 1<>1';
} else if( 1 == count( $t_project_ids ) ) {

  • $t_project_filter = ' project_id=' . $t_project_ids[0];
  • $t_project_filter = ' project_id=' . reset( $t_project_ids );
    } else {
    $t_project_filter = ' project_id IN (' . join( ',', $t_project_ids ) . ')';
    }
aavagyan

aavagyan

2014-03-10 08:09

reporter   ~0039642

Yes, it solves the problem, thanks!

Related Changesets

MantisBT: master-1.2.x 85e471e9

2014-03-11 08:24

dregad


Details Diff
Incorrect project-specific where clause

If user has access to only one project (or if there is only one project
in bug tracker), helper_project_specific_where() function returned an
incorrect where clause when $project_id == ALL_PROJECTS.

Fixes 0017073
Affected Issues
0017073
mod - core/helper_api.php Diff File

MantisBT: master c0ad6521

2014-03-11 08:24

dregad


Details Diff
Incorrect project-specific where clause

If user has access to only one project (or if there is only one project
in bug tracker), helper_project_specific_where() function returned an
incorrect where clause when $project_id == ALL_PROJECTS.

Fixes 0017073
Affected Issues
0017073
mod - core/helper_api.php Diff File