Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/pr/835'
Browse files Browse the repository at this point in the history
  • Loading branch information
vboctor committed Aug 5, 2016
2 parents 14ee7b3 + 002b4f7 commit 98b03fd
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 31 deletions.
2 changes: 1 addition & 1 deletion bug_update_page.php
Expand Up @@ -292,7 +292,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
12 changes: 7 additions & 5 deletions changelog_page.php
Expand Up @@ -238,9 +238,6 @@ function print_project_header_changelog( $p_project_name ) {
$t_project_name = project_get_field( $t_project_id, 'name' );
$t_can_view_private = access_has_project_level( config_get( 'private_bug_threshold' ), $t_project_id );

$t_limit_reporters = config_get( 'limit_reporters' );
$t_user_access_level_is_reporter = ( config_get( 'report_bug_threshold', null, null, $t_project_id ) == access_get_project_level( $t_project_id ) );

$t_resolved = config_get( 'bug_resolved_status_threshold' );

# grab version info for later use
Expand All @@ -251,6 +248,10 @@ function print_project_header_changelog( $p_project_name ) {

$t_project_header_printed = false;

$t_limit_reporters = config_get( 'limit_reporters' );
$t_report_bug_threshold = config_get( 'report_bug_threshold', null, null, $t_project_id );
$t_access_limit_reporters_applies = !access_has_project_level( access_threshold_min_level( $t_report_bug_threshold ) + 1, $t_project_id );

foreach( $t_version_rows as $t_version_row ) {
$t_version_header_printed = false;

Expand Down Expand Up @@ -290,8 +291,9 @@ function print_project_header_changelog( $p_project_name ) {

# check limit_Reporter (Issue #4770)
# reporters can view just issues they reported
if( ON === $t_limit_reporters && $t_user_access_level_is_reporter &&
!bug_is_user_reporter( $t_row['id'], $t_user_id )) {
if( ON == $t_limit_reporters
&& $t_access_limit_reporters_applies
&& !bug_is_user_reporter( $t_row['id'], $t_user_id ) ) {
continue;
}

Expand Down
29 changes: 24 additions & 5 deletions core/access_api.php
Expand Up @@ -421,13 +421,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 @@ -716,3 +713,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 @@ -1237,7 +1237,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 @@ -3586,7 +3586,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
10 changes: 7 additions & 3 deletions manage_config_workflow_page.php
Expand Up @@ -359,7 +359,8 @@ function access_row() {

$t_file_new = config_get_global( 'report_bug_threshold' );
$t_global_new = config_get( 'report_bug_threshold', null, ALL_USERS, ALL_PROJECTS );
$t_project_new = config_get( 'report_bug_threshold' );
$t_report_bug_threshold = config_get( 'report_bug_threshold' );
$t_project_new = access_threshold_min_level( $t_report_bug_threshold );

$t_file_set = config_get_global( 'set_status_threshold' );
$t_global_set = config_get( 'set_status_threshold', null, ALL_USERS, ALL_PROJECTS );
Expand All @@ -376,8 +377,11 @@ function access_row() {
# 'NEW' status
$t_level_project = $t_project_new;

$t_can_change = ( $g_access >= config_get_access( 'report_bug_threshold' ) );
$t_color = set_color_override( $t_file_new, $t_global_new, $t_project_new );
# If report_bug_threshold is an array (instead of an integer value), the input is not editable
# because it must be configured in manage_config_work_threshold_page.
$t_can_change = ( $g_access >= config_get_access( 'report_bug_threshold' ) )
&& !is_array( $t_report_bug_threshold );
$t_color = set_color_override( $t_file_new, $t_global_new, $t_report_bug_threshold );
set_overrides( 'report_bug_threshold', $t_can_change, $t_color );
} else {
# Other statuses
Expand Down
34 changes: 19 additions & 15 deletions manage_config_workflow_set.php
Expand Up @@ -84,7 +84,8 @@ function config_get_access_parent( $p_project, $p_option ) {
}


$t_can_change_level = min( config_get_access( 'notify_flags' ), config_get_access( 'default_notify_flags' ) );
$t_can_change_level = min( config_get_access( 'status_enum_workflow' ), config_get_access( 'report_bug_threshold' ), config_get_access( 'set_status_threshold' )
, config_get_access( 'bug_submit_status' ), config_get_access( 'bug_resolved_status_threshold' ), config_get_access( 'bug_reopen_status' ) );
access_ensure_project_level( $t_can_change_level );

$t_redirect_url = 'manage_config_workflow_page.php';
Expand Down Expand Up @@ -187,7 +188,7 @@ function config_get_access_parent( $p_project, $p_option ) {
}

# process the access level changes
if( config_get_access( 'set_status_threshold' ) <= $t_access ) {
if( min( config_get_access( 'set_status_threshold' ), config_get_access( 'report_bug_threshold' ) ) <= $t_access ) {
# get changes to access level to change these values
$f_access = gpc_get( 'status_access' );
$t_access_parent = config_get_access_parent( $t_project, 'set_status_threshold' );
Expand All @@ -199,16 +200,16 @@ function config_get_access_parent( $p_project, $p_option ) {
$t_bug_submit_status = config_get( 'bug_submit_status' );
foreach( $t_enum_status as $t_status => $t_status_label ) {
if( !isset( $t_set_parent[$t_status] ) ) {
if( $t_bug_submit_status == $t_status ) {
if( $t_bug_submit_status == $t_status && config_get_access( 'report_bug_threshold' ) <= $t_access ) {
$t_set_parent[$t_status] = config_get_parent( $t_project, 'report_bug_threshold' );
} else {
} elseif( config_get_access( 'set_status_threshold' ) <= $t_access ) {
$t_set_parent[$t_status] = config_get_parent( $t_project, 'update_bug_status_threshold' );
}
}
if( !isset( $t_set_current[$t_status] ) ) {
if( $t_bug_submit_status == $t_status ) {
if( $t_bug_submit_status == $t_status && config_get_access( 'report_bug_threshold' ) <= $t_access ) {
$t_set_current[$t_status] = config_get( 'report_bug_threshold' );
} else {
} elseif( config_get_access( 'set_status_threshold' ) <= $t_access ) {
$t_set_current[$t_status] = config_get( 'update_bug_status_threshold' );
}
}
Expand All @@ -217,17 +218,20 @@ function config_get_access_parent( $p_project, $p_option ) {
# walk through the status labels to set the status threshold
$t_set_new = array();
foreach( $t_enum_status as $t_status_id => $t_status_label ) {
$f_level = gpc_get_int( 'access_change_' . $t_status_id );
if( config_get( 'bug_submit_status' ) == $t_status_id ) {
if( $f_level != $t_set_parent[$t_status_id] ) {
config_set( 'report_bug_threshold', (int)$f_level, ALL_USERS, $t_project, $f_access );
$f_level = gpc_get_int( 'access_change_' . $t_status_id, -1 );
# Only process those inputs that exists, since not all access_change_<status> may have been editable.
if( $f_level > -1 ) {
if( config_get( 'bug_submit_status' ) == $t_status_id ) {
if( $f_level != $t_set_parent[$t_status_id] ) {
config_set( 'report_bug_threshold', (int)$f_level, ALL_USERS, $t_project, $f_access );
} else {
config_delete( 'report_bug_threshold', ALL_USERS, $t_project );
}
unset( $t_set_parent[$t_status_id] );
unset( $t_set_current[$t_status_id] );
} else {
config_delete( 'report_bug_threshold', ALL_USERS, $t_project );
$t_set_new[$t_status_id] = $f_level;
}
unset( $t_set_parent[$t_status_id] );
unset( $t_set_current[$t_status_id] );
} else {
$t_set_new[$t_status_id] = $f_level;
}
}

Expand Down

0 comments on commit 98b03fd

Please sign in to comment.