From ef32cb919059f7abf14b873653c68261c0fb3521 Mon Sep 17 00:00:00 2001 From: Roland Becker Date: Tue, 28 Aug 2018 14:40:14 +0200 Subject: [PATCH] Code and performance enhancements Issue #24696 --- core/bug_group_action_api.php | 75 +++++++++++++++++------------------ 1 file changed, 37 insertions(+), 38 deletions(-) diff --git a/core/bug_group_action_api.php b/core/bug_group_action_api.php index 64325f9121..f60cb29e65 100644 --- a/core/bug_group_action_api.php +++ b/core/bug_group_action_api.php @@ -212,11 +212,16 @@ function bug_group_action_get_commands( array $p_project_ids = null ) { $p_project_ids = array( ALL_PROJECTS ); } + $t_user_id = auth_get_current_user_id(); + $t_commands = array(); foreach( $p_project_ids as $t_project_id ) { + $t_update_bug_allowed = access_has_project_level( config_get( 'update_bug_threshold', null, $t_user_id, $t_project_id ), $t_project_id ); + $t_update_bug_status_allowed = access_has_project_level( config_get( 'update_bug_status_threshold', null, $t_user_id, $t_project_id ), $t_project_id ); + if( !isset( $t_commands['MOVE'] ) && - access_has_project_level( config_get( 'move_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'move_bug_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['MOVE'] = lang_get( 'actiongroup_menu_move' ); } @@ -226,107 +231,101 @@ function bug_group_action_get_commands( array $p_project_ids = null ) { } if( !isset( $t_commands['ASSIGN'] ) && - access_has_project_level( config_get( 'update_bug_assign_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'update_bug_assign_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['ASSIGN'] = lang_get( 'actiongroup_menu_assign' ); } - if( !isset( $t_commands['CLOSE'] ) && - access_has_project_level( config_get( 'update_bug_status_threshold', null, null, $t_project_id ), $t_project_id ) && - ( access_has_project_level( access_get_status_threshold( config_get( 'bug_closed_status_threshold', null, null, $t_project_id ), $t_project_id ), $t_project_id ) || - access_has_project_level( config_get( 'allow_reporter_close', null, null, $t_project_id ), $t_project_id ) ) ) { + if( !isset( $t_commands['CLOSE'] ) && $t_update_bug_status_allowed && + ( access_has_project_level( access_get_status_threshold( config_get( 'bug_closed_status_threshold', null, $t_user_id, $t_project_id ), $t_project_id ), $t_project_id ) || + access_has_project_level( config_get( 'allow_reporter_close', null, $t_user_id, $t_project_id ), $t_project_id ) ) ) { $t_commands['CLOSE'] = lang_get( 'actiongroup_menu_close' ); } if( !isset( $t_commands['DELETE'] ) && - access_has_project_level( config_get( 'delete_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'delete_bug_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['DELETE'] = lang_get( 'actiongroup_menu_delete' ); } - if( !isset( $t_commands['RESOLVE'] ) && - access_has_project_level( config_get( 'update_bug_status_threshold', null, null, $t_project_id ), $t_project_id ) && - access_has_project_level( access_get_status_threshold( config_get( 'bug_resolved_status_threshold', null, null, $t_project_id ), $t_project_id ), $t_project_id ) ) { + if( !isset( $t_commands['RESOLVE'] ) && $t_update_bug_status_allowed && + access_has_project_level( access_get_status_threshold( config_get( 'bug_resolved_status_threshold', null, $t_user_id, $t_project_id ), $t_project_id ), $t_project_id ) ) { $t_commands['RESOLVE'] = lang_get( 'actiongroup_menu_resolve' ); } if( !isset( $t_commands['SET_STICKY'] ) && - access_has_project_level( config_get( 'set_bug_sticky_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'set_bug_sticky_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['SET_STICKY'] = lang_get( 'actiongroup_menu_set_sticky' ); } - if( !isset( $t_commands['UP_PRIOR'] ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + if( !isset( $t_commands['UP_PRIOR'] ) && $t_update_bug_allowed ) { $t_commands['UP_PRIOR'] = lang_get( 'actiongroup_menu_update_priority' ); } - if( !isset( $t_commands['EXT_UPDATE_SEVERITY'] ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + if( !isset( $t_commands['EXT_UPDATE_SEVERITY'] ) && $t_update_bug_allowed ) { $t_commands['EXT_UPDATE_SEVERITY'] = lang_get( 'actiongroup_menu_update_severity' ); } - if( !isset( $t_commands['UP_STATUS'] ) && - access_has_project_level( config_get( 'update_bug_status_threshold', null, null, $t_project_id ), $t_project_id ) ) { + if( !isset( $t_commands['UP_STATUS'] ) && $t_update_bug_status_allowed ) { $t_commands['UP_STATUS'] = lang_get( 'actiongroup_menu_update_status' ); } - if( !isset( $t_commands['UP_CATEGORY'] ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + if( !isset( $t_commands['UP_CATEGORY'] ) && $t_update_bug_allowed ) { $t_commands['UP_CATEGORY'] = lang_get( 'actiongroup_menu_update_category' ); } if( !isset( $t_commands['VIEW_STATUS'] ) && - access_has_project_level( config_get( 'change_view_status_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'change_view_status_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['VIEW_STATUS'] = lang_get( 'actiongroup_menu_update_view_status' ); } if( !isset( $t_commands['EXT_UPDATE_PRODUCT_BUILD'] ) && - config_get( 'enable_product_build', null, null, $t_project_id ) == ON && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + config_get( 'enable_product_build', null, $t_user_id, $t_project_id ) == ON && + $t_update_bug_allowed ) { $t_commands['EXT_UPDATE_PRODUCT_BUILD'] = lang_get( 'actiongroup_menu_update_product_build' ); } if( !isset( $t_commands['EXT_ADD_NOTE'] ) && - access_has_project_level( config_get( 'add_bugnote_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'add_bugnote_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['EXT_ADD_NOTE'] = lang_get( 'actiongroup_menu_add_note' ); } if( !isset( $t_commands['EXT_ATTACH_TAGS'] ) && - access_has_project_level( config_get( 'tag_attach_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'tag_attach_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['EXT_ATTACH_TAGS'] = lang_get( 'actiongroup_menu_attach_tags' ); } if( !isset( $t_commands['UP_DUE_DATE'] ) && - access_has_project_level( config_get( 'due_date_update_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'due_date_update_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['UP_DUE_DATE'] = lang_get( 'actiongroup_menu_update_due_date' ); } if( !isset( $t_commands['UP_PRODUCT_VERSION'] ) && - version_should_show_product_version( $t_project_id ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + version_should_show_product_version( $t_project_id ) && $t_update_bug_allowed ) { $t_commands['UP_PRODUCT_VERSION'] = lang_get( 'actiongroup_menu_update_product_version' ); } if( !isset( $t_commands['UP_FIXED_IN_VERSION'] ) && - version_should_show_product_version( $t_project_id ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { + version_should_show_product_version( $t_project_id ) && $t_update_bug_allowed ) { $t_commands['UP_FIXED_IN_VERSION'] = lang_get( 'actiongroup_menu_update_fixed_in_version' ); } if( !isset( $t_commands['UP_TARGET_VERSION'] ) && version_should_show_product_version( $t_project_id ) && - access_has_project_level( config_get( 'roadmap_update_threshold', null, null, $t_project_id ), $t_project_id ) ) { + access_has_project_level( config_get( 'roadmap_update_threshold', null, $t_user_id, $t_project_id ), $t_project_id ) ) { $t_commands['UP_TARGET_VERSION'] = lang_get( 'actiongroup_menu_update_target_version' ); } - $t_custom_field_ids = custom_field_get_linked_ids( $t_project_id ); - foreach( $t_custom_field_ids as $t_custom_field_id ) { - if( custom_field_has_write_access_to_project( $t_custom_field_id, $t_project_id ) && - access_has_project_level( config_get( 'update_bug_threshold', null, null, $t_project_id ), $t_project_id ) ) { - $t_custom_field_def = custom_field_get_definition( $t_custom_field_id ); - $t_command_id = 'custom_field_' . $t_custom_field_id; - $t_command_caption = sprintf( lang_get( 'actiongroup_menu_update_field' ), lang_get_defaulted( $t_custom_field_def['name'] ) ); - $t_commands[$t_command_id] = string_display( $t_command_caption ); + if ( $t_update_bug_allowed ) { + $t_custom_field_ids = custom_field_get_linked_ids( $t_project_id ); + foreach( $t_custom_field_ids as $t_custom_field_id ) { + if( custom_field_has_write_access_to_project( $t_custom_field_id, $t_project_id ) ) { + $t_custom_field_def = custom_field_get_definition( $t_custom_field_id ); + $t_command_id = 'custom_field_' . $t_custom_field_id; + $t_command_caption = sprintf( lang_get( 'actiongroup_menu_update_field' ), lang_get_defaulted( $t_custom_field_def['name'] ) ); + $t_commands[$t_command_id] = string_display( $t_command_caption ); + } } } + } $t_custom_group_actions = config_get( 'custom_group_actions' );