Skip to content

Commit

Permalink
Fix comparing threshold as an integer
Browse files Browse the repository at this point in the history
report_bug_threshold may be an integer or an array, but a check to
see if an access level is "greater than" its value, was assuming
that this threshold was an integer value.

A new function is created to get an integer representation of a
threshold, as the minimum integer value defined in the threshold.

Fixes: #21579
  • Loading branch information
cproensa committed Aug 4, 2016
1 parent de31cb6 commit ce3608b
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion bug_update_page.php
Expand Up @@ -285,7 +285,7 @@
# Do not allow the bug's reporter to edit the Reporter field
# when limit_reporters is ON
if( ON == config_get( 'limit_reporters' )
&& !access_has_project_level( config_get( 'report_bug_threshold', null, null, $t_bug->project_id ) + 1, $t_bug->project_id )
&& !access_has_project_level( access_threshold_min_level( config_get( 'report_bug_threshold', null, null, $t_bug->project_id ) ) + 1, $t_bug->project_id )
) {
echo string_attribute( user_get_name( $t_bug->reporter_id ) );
} else {
Expand Down
29 changes: 24 additions & 5 deletions core/access_api.php
Expand Up @@ -414,13 +414,10 @@ function access_has_bug_level( $p_access_level, $p_bug_id, $p_user_id = null ) {
static $s_thresholds = array();
if( !isset( $s_thresholds[$t_project_id] ) ) {
$t_report_bug_threshold = config_get( 'report_bug_threshold', null, $p_user_id, $t_project_id );
if( !is_array( $t_report_bug_threshold ) ) {
$s_thresholds[$t_project_id] = $t_report_bug_threshold + 1;
} else if( empty( $t_report_bug_threshold ) ) {
if( empty( $t_report_bug_threshold ) ) {
$s_thresholds[$t_project_id] = NOBODY;
} else {
sort( $t_report_bug_threshold );
$s_thresholds[$t_project_id] = $t_report_bug_threshold[0] + 1;
$s_thresholds[$t_project_id] = access_threshold_min_level( $t_report_bug_threshold ) + 1;
}
}
if( !access_compare_level( $t_access_level, $s_thresholds[$t_project_id] ) ) {
Expand Down Expand Up @@ -709,3 +706,25 @@ function access_level_get_string( $p_access_level ) {
}
return $t_access_level_string;
}

/**
* Return the minimum access level, as integer, that matches the threshold.
* $p_threshold may be a single value, or an array. If it is a single
* value, returns that number. If it is an array, return the value of the
* smallest element
* @param integer|array $p_threshold Access threshold
* @return integer Integer value for an access level.
*/
function access_threshold_min_level( $p_threshold ) {
if( is_array( $p_threshold ) ) {
if( empty( $p_threshold ) ) {
return NOBODY;
} else {
sort( $p_threshold );
return( reset( $p_threshold ) );
}
} else {
return $p_threshold;
}

}
4 changes: 2 additions & 2 deletions core/filter_api.php
Expand Up @@ -1236,7 +1236,7 @@ function filter_get_bug_rows( &$p_page_number, &$p_per_page, &$p_page_count, &$p

foreach( $t_project_ids as $t_pid ) {
# limit reporters to visible projects
if( ( ON === $t_limit_reporters ) && ( !access_has_project_level( config_get( 'report_bug_threshold', null, $t_user_id, $t_pid ) + 1, $t_pid, $t_user_id ) ) ) {
if( ( ON === $t_limit_reporters ) && ( !access_has_project_level( access_threshold_min_level( config_get( 'report_bug_threshold', null, $t_user_id, $t_pid ) ) + 1, $t_pid, $t_user_id ) ) ) {
array_push( $t_limited_projects, '({bug}.project_id=' . $t_pid . ' AND ({bug}.reporter_id=' . $t_user_id . ') )' );
} else {
$t_access_required_to_view_private_bugs = config_get( 'private_bug_threshold', null, null, $t_pid );
Expand Down Expand Up @@ -3560,7 +3560,7 @@ function print_filter_reporter_id() {
# @@@ thraxisp - access_has_project_level checks greater than or equal to,
# this assumed that there aren't any holes above REPORTER where the limit would apply
#
if( ( ON === config_get( 'limit_reporters' ) ) && ( !access_has_project_level( config_get( 'report_bug_threshold' ) + 1 ) ) ) {
if( ( ON === config_get( 'limit_reporters' ) ) && ( !access_has_project_level( access_threshold_min_level( config_get( 'report_bug_threshold' ) ) + 1 ) ) ) {
$t_id = auth_get_current_user_id();
$t_username = user_get_field( $t_id, 'username' );
$t_realname = user_get_field( $t_id, 'realname' );
Expand Down

0 comments on commit ce3608b

Please sign in to comment.