View Issue Details

IDProjectCategoryView StatusLast Update
0008663mantisbtsub-projectspublic2019-04-07 13:31
Reportersveyret Assigned To 
PrioritynormalSeverityminorReproducibilityalways
Status newResolutionopen 
Product Version1.0.8 
Summary0008663: Multiparent projects not prune in project list
Description

The error is in core/core_api.php, function user_get_accessible_projects. When a project has more than one parent, the prune part does not work properly. I made small changes between

$t_projects = array();

and

foreach ( $t_prune as $t_id ) {

Here is the new code:

for ( $i=0 ; $i < $row_count ; $i++ ) {
$row = db_fetch_array( $result );

if ( !isset ( $t_projects[ $row['id'] ] ) ) {
    $t_projects[ $row['id'] ] = array();
}

$t_projects[ $row['id'] ][] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];

}

prune out children where the parents are already listed. Make the list

first, then prune to avoid pruning a parent before the child is found.

t_prune = array();
foreach ( $t_projects as $t_id => $t_parent_list ) {
foreach ( $t_parent_list as $t_parent ) {
if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
if ( !in_array ( $t_id, $t_prune ) )
$t_prune[] = $t_id;
}
}
}

Hope this can help you.

Steps To Reproduce

Imagine we have 2 projects with a UI part and a engine part. We will have 4 mantis projects:

Proj1UI, Proj1Engine, Proj2UI, Proj2Engine.

We need to access these project in a vertical way (i.e. full project) but also, as they actually are modules of a big platform, in horizontal way (i.e. all UI or all engines). We then create 4 more projects:

Proj1, parent of Proj1UI and Proj1Engine.
Proj2, parent of Proj2UI and Proj2Engine.
UI, parent of Proj1UI and Proj2UI.
Engine, parent of Proj1Engine and Proj2Engine.

Now, if someone, for example, has rights on Proj1UI and UI, but not on Proj1, the project Proj1UI should be only displayed inside parent project UI. Actually, it may display twice (it depends on the order of the DB query result), once alone, and once inside the UI parent.

Tagspatch
Attached Files
user_api.patch (735 bytes)   
736c736,740
< 				$t_projects[ $row['id'] ] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
---
> 				if ( !isset ( $t_projects[ $row['id'] ] ) ) {
> 					$t_projects[ $row['id'] ] = array();
> 				}
> 
> 				$t_projects[ $row['id'] ][] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
742,744c746,751
< 			foreach ( $t_projects as $t_id => $t_parent ) {
< 				if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
< 					$t_prune[] = $t_id;
---
> 			foreach ( $t_projects as $t_id => $t_parent_list ) {
> 				foreach ( $t_parent_list as $t_parent ) {
> 					if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
> 						if ( !in_array ( $t_id, $t_prune ) )
> 							$t_prune[] = $t_id;
> 					}
user_api.patch (735 bytes)   
issue8663.patch (1,511 bytes)   
From afaec9f5f9c26df0d46ef0eaa7481f2e82cf6861 Mon Sep 17 00:00:00 2001
From: =?utf-8?q?St=82phane=20Veyret?= <sveyret@axway.com>
Date: Wed, 1 Jul 2009 09:57:23 +0200
Subject: [PATCH] Fix 0008663: Multiparent projects not prune in project list

---
 core/user_api.php |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)

diff --git a/core/user_api.php b/core/user_api.php
index 23dbb45..be17388 100644
--- a/core/user_api.php
+++ b/core/user_api.php
@@ -748,15 +748,22 @@
 			for ( $i=0 ; $i < $row_count ; $i++ ) {
 				$row = db_fetch_array( $result );
 
-				$t_projects[ $row['id'] ] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
+				if ( !isset ( $t_projects[ $row['id'] ] ) ) {
+					$t_projects[ $row['id'] ] = array();
+				}
+
+				$t_projects[ $row['id'] ][] = ( $row['parent_id'] === NULL ) ? 0 : $row['parent_id'];
 			}
 
 			# prune out children where the parents are already listed. Make the list
 			#  first, then prune to avoid pruning a parent before the child is found.
 			$t_prune = array();
-			foreach ( $t_projects as $t_id => $t_parent ) {
-				if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
-					$t_prune[] = $t_id;
+			foreach ( $t_projects as $t_id => $t_parent_list ) {
+				foreach ( $t_parent_list as $t_parent ) {
+					if ( ( $t_parent !== 0 ) && isset( $t_projects[$t_parent] ) ) {
+						if ( !in_array ( $t_id, $t_prune ) )
+							$t_prune[] = $t_id;
+					}
 				}
 			}
 			foreach ( $t_prune as $t_id ) {
-- 
1.6.3.2

issue8663.patch (1,511 bytes)   

Relationships

related to 0025641 new Refactor project hierarchy 

Activities

sveyret

sveyret

2008-07-04 03:50

reporter   ~0018297

This issue is still true in version 1.1.1, but the function is now in the file user_api.php.
I uploaded a diff file to patch user_api.php. This diff was made against the user_api.php of the Mantis 1.1.1 version.

sveyret

sveyret

2009-07-01 10:11

reporter   ~0022348

I added the patch for branch 1.1.x.

kivio.wanderley

kivio.wanderley

2010-12-23 08:30

reporter   ~0027682

I tried to use the code for my problem but it didn't work. If i have a project that has a parent and a grandparent, for example, the child project apperas on the list out of the tree projects.

Zonix

Zonix

2011-11-18 03:59

reporter   ~0030246

Thank you very much for finding a patch for this. The bug is still present in 1.2.8 and hit me with a similiar setup.