View Issue Details

IDProjectCategoryView StatusLast Update
0010592mantisbtapi soappublic2010-02-22 14:34
Reportercbasset Assigned Torombert  
PrioritynormalSeveritymajorReproducibilityalways
Status closedResolutionfixed 
Product Version1.1.6 
Target Version1.2.0Fixed in Version1.2.0 
Summary0010592: mc_enum functions doesn't take customization into account
Description

When a customization of mantis standard field possible values has been done by override of default global variable in file config_inc.php, soap api function that lists the possible values doesn't take customization into account.

Steps To Reproduce

in config_inc.php insert the following line:
$g_priority_enum_string = '10:not set,20:low,30:normal,40:high,60:immediate'; // Remove urgent priority

call the api method
mc_enum_priorities

The result is standard mantis possible values not taking customization into account:

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns="http://futureware.biz/mantisconnect">
<SOAP-ENV:Body>
<ns1:mc_enum_prioritiesResponse xmlns:ns1="http://futureware.biz/mantisconnect">
<return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType="tns:ObjectRef[6]">
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">10</id>
<name xsi:type="xsd:string">not set</name>
</item>
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">20</id>
<name xsi:type="xsd:string">low</name>
</item>
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">30</id>
<name xsi:type="xsd:string">normal</name>
</item>
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">40</id>
<name xsi:type="xsd:string">high</name>
</item>
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">50</id>
<name xsi:type="xsd:string">urgent</name>
</item>
<item xsi:type="tns:ObjectRef">
<id xsi:type="xsd:integer">60</id>
<name xsi:type="xsd:string">immediate</name>
</item>
</return>
</ns1:mc_enum_prioritiesResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

TagsNo tags attached.
Attached Files
0001-Fixes-10592-mc_enum-functions-doesn-t-take-customiza.patch (9,624 bytes)   
From bbf23fa80ed72a8c7c710eaa1bffbc91c7e39427 Mon Sep 17 00:00:00 2001
From: Robert Munteanu <robert.munteanu@gmail.com>
Date: Tue, 27 Oct 2009 18:36:58 +0200
Subject: [PATCH] Fixes #10592: mc_enum functions doesn't take customization into account

The mc_enum_xxx functions have been updated to return the keys according
to the customised values, while the names remain the translated ones.

mc_enum_get has not been updated, as it returns a raw enum string, not
an ObjectRefArray.

Unfortunately no new tests can be added since we don't control the
customisation settings on the mantis installation on a per-test
basis.
---
 api/soap/mc_enum_api.php |  130 ++++++++++++++++++++++++++++++++++-----------
 1 files changed, 98 insertions(+), 32 deletions(-)

diff --git a/api/soap/mc_enum_api.php b/api/soap/mc_enum_api.php
index 8d980ae..09c344d 100644
--- a/api/soap/mc_enum_api.php
+++ b/api/soap/mc_enum_api.php
@@ -14,7 +14,11 @@
  * @return Array  The requested enumeration
  */
 function mc_enum_status( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'status' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'status' );
 }
 
 /**
@@ -25,7 +29,11 @@ function mc_enum_status( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_priorities( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'priority' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'priority' );
 }
 
 /**
@@ -36,7 +44,11 @@ function mc_enum_priorities( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_severities( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'severity' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'severity' );
 }
 
 /**
@@ -47,7 +59,11 @@ function mc_enum_severities( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_reproducibilities( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'reproducibility' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'reproducibility' );
 }
 
 /**
@@ -58,7 +74,11 @@ function mc_enum_reproducibilities( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_projections( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'projection' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'projection' );
 }
 
 /**
@@ -69,7 +89,11 @@ function mc_enum_projections( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_etas( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'eta' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'eta' );
 }
 
 /**
@@ -80,7 +104,11 @@ function mc_enum_etas( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_resolutions( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'resolution' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'resolution' );
 }
 
 /**
@@ -91,7 +119,11 @@ function mc_enum_resolutions( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_access_levels( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'access_levels' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'access_levels' );
 }
 
 /**
@@ -102,7 +134,11 @@ function mc_enum_access_levels( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_project_status( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'project_status' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'project_status' );
 }
 
 /**
@@ -113,7 +149,11 @@ function mc_enum_project_status( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_project_view_states( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'project_view_state' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'project_view_state' );
 }
 
 /**
@@ -124,7 +164,11 @@ function mc_enum_project_view_states( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_view_states( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'view_state' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'view_state' );
 }
 
 /**
@@ -135,7 +179,11 @@ function mc_enum_view_states( $p_username, $p_password ) {
  * @return Array  The requested enumeration
  */
 function mc_enum_custom_field_types( $p_username, $p_password ) {
-	return mci_explode_to_objectref( mc_enum_get( $p_username, $p_password, 'custom_field_type' ) );
+	if ( !mci_validate_enum_access( $p_username, $p_password ) ) {
+		return new soap_fault( 'Client', '', 'Access Denied' );
+	}
+	
+	return mci_explode_to_objectref( 'custom_field_type' );
 }
 
 /**
@@ -147,11 +195,7 @@ function mc_enum_custom_field_types( $p_username, $p_password ) {
  * @return string  The requested enumeration.
  */
 function mc_enum_get( $p_username, $p_password, $p_enumeration ) {
-	$t_user_id = mci_check_login( $p_username, $p_password );
-	if( $t_user_id === false ) {
-		return new soap_fault( 'Client', '', 'Access Denied' );
-	}
-	if( !mci_has_readonly_access( $t_user_id ) ) {
+	if ( ! mci_validate_enum_access($p_username, $p_password)) {
 		return new soap_fault( 'Client', '', 'Access Denied' );
 	}
 	$t_lang = mci_get_user_lang( $t_user_id );
@@ -159,32 +203,54 @@ function mc_enum_get( $p_username, $p_password, $p_enumeration ) {
 }
 
 /**
- * Explode a configuration enumeration string into an array structure that can
+ * Explode a configuration enumeration name into an array structure that can
  * be safely converted into an ObjectRef structure.
- *
- * @param string $p_config_enum_string  The string to convert
+ * 
+ * @param string $p_enumeration_name  The name of the enumeration to convert
  * @return Array  The converted enumeration
  */
-function mci_explode_to_objectref( $p_config_enum_string ) {
-	if( get_class( (object) $p_config_enum_string ) == 'soap_fault' ) {
-		return $p_config_enum_string;
-	}
+function mci_explode_to_objectref( $p_enumeration_name ) {
 	
-	$t_result = array();
-
-	$t_assoc_array = MantisEnum::getAssocArrayIndexedByValues( $p_config_enum_string );
+	$t_config_var_name = $p_enumeration_name . '_enum_string';
+	$t_config_var_value = config_get( $t_config_var_name );
+	$t_translated_values = lang_get( $t_config_var_name );
 
-	foreach ( $t_assoc_array as $t_id => $t_name ) {
+	$t_enum_values = MantisEnum::getValues( $t_config_var_value );
+	
+	$t_result = array();
+	
+	foreach ( $t_enum_values as $t_key ) {
+		$t_translated = MantisEnum::getLocalizedLabel( $t_config_var_value, $t_translated_values, $t_key );
+		
 		$t_result[] = array(
-			'id' => $t_id,
-			'name' => $t_name,
+			'id' => $t_key,
+			'name' => $t_translated,
 		);
 	}
-
 	return $t_result;
 }
 
 /**
+ * Validates that the user has access to the enumeration values
+ * 
+ * @param string $p_username
+ * @param string $p_password
+ * @return boolean true if the user has access, false otherwise
+ */
+function mci_validate_enum_access($p_username, $p_password) {
+	
+	$t_user_id = mci_check_login( $p_username, $p_password );
+	if( $t_user_id === false ) {
+		return false;
+	}
+	if( !mci_has_readonly_access( $t_user_id ) ) {
+		return false;
+	}
+	
+	return true;
+}
+
+/**
  * Get a localized enumeration element.
  *
  * @param integer $p_enum_id  The id of the enumeration element to retrieve.
@@ -240,7 +306,7 @@ function mci_get_enum_id_from_objectref( $p_enum, $p_object_ref ) {
 		} else {
 			$t_default_id = config_get( 'default_bug_' . $p_enum, 0 );
 			if( $t_default_id == 0 ) {
-				$t_array = mci_explode_to_objectref( $t_enum );
+				$t_array = mci_explode_to_objectref( $p_enum );
 				$t_id = (int) $t_array[0]['id'];
 			} else {
 				$t_id = $t_default_id;
-- 
1.6.4.2

Activities

rombert

rombert

2009-10-27 12:42

reporter   ~0023412

@vboctor : can you please review this patch for me? I'm not 100% sure I'm doing the right thing and whether it should land in master-1.2.x besides master.

Thanks.

vboctor

vboctor

2009-10-27 13:04

manager   ~0023414

The patch is incorrect. The patch should do the following:

  1. Return the ids in the $g_xxxx_enum.
  2. With the labels in the $s_xxxx_enum.

This will return the localized labels while using the $g_xxxx_enum as the master copy.

From memory, the MantisEnum class had a method to do that. We should make sure to utilize it here.

rombert

rombert

2009-10-27 19:37

reporter   ~0023418

@vboctor - I've updated the patch, please have a look.

Thanks.

vboctor

vboctor

2009-10-27 19:49

manager   ~0023419

Looks right to me. Thanks.

vboctor

vboctor

2009-10-27 20:59

manager   ~0023421

Should this be resolved now?

rombert

rombert

2009-10-28 04:03

reporter   ~0023438

@vboctor: yes, forgot to resolve.

Thanks.

Related Changesets

MantisBT: master-1.2.x 8faebae6

2009-10-27 12:36

rombert


Details Diff
Fixes 0010592: mc_enum functions doesn't take customization into account

The mc_enum_xxx functions have been updated to return the customised
keys, while the names remain the translated ones.

mc_enum_get has not been updated, as it returns a raw enum string, not
an ObjectRefArray.

Unfortunately no new tests can be added since we don't control the
customisation settings on the mantis installation on a per-test
basis.

- split functionality from mc_issue_get
- explode_bla_bla now takes a enumeration name
- localized labels are properly used
Affected Issues
0010592
mod - api/soap/mc_enum_api.php Diff File

MantisBT: master 834c8ed7

2009-10-27 12:36

rombert


Details Diff
Fixes 0010592: mc_enum functions doesn't take customization into account

The mc_enum_xxx functions have been updated to return the customised
keys, while the names remain the translated ones.

mc_enum_get has not been updated, as it returns a raw enum string, not
an ObjectRefArray.

Unfortunately no new tests can be added since we don't control the
customisation settings on the mantis installation on a per-test
basis.

- split functionality from mc_issue_get
- explode_bla_bla now takes a enumeration name
- localized labels are properly used
Affected Issues
0010592
mod - api/soap/mc_enum_api.php Diff File