Skip to content

Commit

Permalink
Port - #8591 (duplicate #8639): Error in api/soap/mc_filter_api.php#m…
Browse files Browse the repository at this point in the history
…c_filter_get()

git-svn-id: http://mantisbt.svn.sourceforge.net/svnroot/mantisbt/trunk@5330 f5dc347c-c33d-0410-90a0-b07cc1902cb9
  • Loading branch information
planser committed Jun 6, 2008
1 parent 400582a commit 1cb2fd6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
47 changes: 47 additions & 0 deletions api/soap/mc_api.php
Expand Up @@ -288,6 +288,53 @@ function mci_category_get_all_rows( $p_project_id, $p_user_id ) {
return $cat_arr;
}

/**
* Basically this is a copy of core/filter_api.php#filter_db_get_available_queries().
* The only difference is that the result of this function is not an array of filter
* names but an array of filter structures.
*/
function mci_filter_db_get_available_queries( $p_project_id = null, $p_user_id = null ) {
$t_filters_table = db_get_table( 'mantis_filters_table' );
$t_overall_query_arr = array();

if ( null === $p_project_id ) {
$t_project_id = helper_get_current_project();
} else {
$t_project_id = db_prepare_int( $p_project_id );
}

if ( null === $p_user_id ) {
$t_user_id = auth_get_current_user_id();
} else {
$t_user_id = db_prepare_int( $p_user_id );
}

# If the user doesn't have access rights to stored queries, just return
if ( !access_has_project_level( config_get( 'stored_query_use_threshold' ) ) ) {
return $t_overall_query_arr;
}

# Get the list of available queries. By sorting such that public queries are
# first, we can override any query that has the same name as a private query
# with that private one
$query = "SELECT * FROM $t_filters_table
WHERE (project_id='$t_project_id'
OR project_id='0')
AND name!=''
ORDER BY is_public DESC, name ASC";
$result = db_query( $query );
$query_count = db_num_rows( $result );

for ( $i = 0; $i < $query_count; $i++ ) {
$row = db_fetch_array( $result );
if ( ( $row['user_id'] == $t_user_id ) || db_prepare_bool( $row['is_public'] ) ) {
$t_overall_query_arr[$row['name']] = $row;
}
}

return array_values( $t_overall_query_arr );
}

#########################################
# SECURITY NOTE: these globals are initialized here to prevent them
# being spoofed if register_globals is turned on
Expand Down
2 changes: 1 addition & 1 deletion api/soap/mc_filter_api.php
Expand Up @@ -27,7 +27,7 @@ function mc_filter_get( $p_username, $p_password, $p_project_id ) {
return new soap_fault( 'Client', '', 'Access Denied' );
}
$t_result = array();
foreach( filter_db_get_available_queries( $p_project_id, $t_user_id ) as $t_filter_row ) {
foreach( mci_filter_db_get_available_queries( $p_project_id, $t_user_id ) as $t_filter_row ) {
$t_filter = array();
$t_filter['id'] = $t_filter_row['id'];
$t_filter['owner'] = mci_account_get_array_by_id( $t_filter_row['user_id'] );
Expand Down

0 comments on commit 1cb2fd6

Please sign in to comment.