@@ -412,37 +412,44 @@ function access_has_bug_level( $p_access_level, $p_bug_id, $p_user_id = null ) {
412
412
}
413
413
414
414
$ t_project_id = bug_get_field ( $ p_bug_id , 'project_id ' );
415
+ $ t_bug_is_user_reporter = bug_is_user_reporter ( $ p_bug_id , $ p_user_id );
416
+ $ t_access_level = access_get_project_level ( $ t_project_id , $ p_user_id );
415
417
416
418
# check limit_Reporter (Issue #4769)
417
419
# reporters can view just issues they reported
418
420
$ t_limit_reporters = config_get ( 'limit_reporters ' , null , $ p_user_id , $ t_project_id );
419
- $ t_report_bug_threshold = config_get ( 'report_bug_threshold ' , null , $ p_user_id , $ t_project_id );
420
- if ( !is_array ( $ t_report_bug_threshold ) ) {
421
- $ t_report_bug_threshold = array ( $ t_report_bug_threshold );
422
- }
423
- if ( $ t_limit_reporters && !bug_is_user_reporter ( $ p_bug_id , $ p_user_id ) ) {
424
- $ t_has_access = false ;
425
- foreach ( $ t_report_bug_threshold as $ t_threshold ) {
426
- if ( access_has_project_level ( $ t_threshold + 1 , $ t_project_id , $ p_user_id ) ) {
427
- $ t_has_access = true ;
428
- break ;
421
+ if ( $ t_limit_reporters && !$ t_bug_is_user_reporter ) {
422
+ # Here we only need to check that the current user has an access level
423
+ # higher than the lowest needed to report issues (report_bug_threshold).
424
+ # To improve performance, esp. when processing for several projects, we
425
+ # build a static array holding that threshold for each project
426
+ static $ s_thresholds = array ();
427
+ if ( !isset ( $ s_thresholds [$ t_project_id ] ) ) {
428
+ $ t_report_bug_threshold = config_get ( 'report_bug_threshold ' , null , $ p_user_id , $ t_project_id );
429
+ if ( !is_array ( $ t_report_bug_threshold ) ) {
430
+ $ s_thresholds [$ t_project_id ] = $ t_report_bug_threshold ;
431
+ } else if ( empty ( $ t_report_bug_threshold ) ) {
432
+ $ s_thresholds [$ t_project_id ] = NOBODY ;
433
+ } else {
434
+ sort ( $ t_report_bug_threshold );
435
+ $ s_thresholds [$ t_project_id ] = $ t_report_bug_threshold [0 ];
429
436
}
430
437
}
431
- if ( !$ t_has_access ) {
438
+
439
+ if ( !access_compare_level ( $ s_thresholds [$ t_project_id ], $ t_access_level ) ) {
432
440
return false ;
433
441
}
434
442
}
435
443
436
444
# If the bug is private and the user is not the reporter, then
437
445
# they must also have higher access than private_bug_threshold
438
- if ( bug_get_field ( $ p_bug_id , 'view_state ' ) == VS_PRIVATE && !bug_is_user_reporter ( $ p_bug_id , $ p_user_id ) ) {
439
- $ t_access_level = access_get_project_level ( $ t_project_id , $ p_user_id );
446
+ if ( !$ t_bug_is_user_reporter && bug_get_field ( $ p_bug_id , 'view_state ' ) == VS_PRIVATE ) {
440
447
$ t_private_bug_threshold = config_get ( 'private_bug_threshold ' , null , $ p_user_id , $ t_project_id );
441
448
return access_compare_level ( $ t_access_level , $ t_private_bug_threshold )
442
- && access_compare_level ( $ t_access_level , $ p_access_level );
449
+ && access_compare_level ( $ t_access_level , $ p_access_level );
443
450
}
444
451
445
- return access_has_project_level ( $ p_access_level , $ t_project_id , $ p_user_id );
452
+ return access_compare_level ( $ p_access_level , $ t_access_level );
446
453
}
447
454
448
455
/**
0 commit comments