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