@@ -155,3 +155,139 @@ function bug_group_action_process( $p_action, $p_bug_id ) {
155155 $ t_function_name = 'action_ ' . $ p_action . '_process ' ;
156156 return $ t_function_name ( $ p_bug_id );
157157}
158+
159+ /**
160+ * Get a list of bug group actions available to the current user for one or
161+ * more projects.
162+ * @param array $p_projects An array containing one or more project IDs
163+ * @return null
164+ */
165+ function bug_group_action_get_commands ( $ p_project_ids = null ) {
166+ if ( $ p_project_ids === null || count ( $ p_project_ids ) == 0 ) {
167+ $ p_project_ids = array ( ALL_PROJECTS );
168+ }
169+
170+ $ t_commands = array ();
171+ foreach ( $ p_project_ids as $ t_project_id ) {
172+
173+ if ( !isset ( $ t_commands ['MOVE ' ] ) &&
174+ access_has_project_level ( config_get ( 'move_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
175+ $ t_commands ['MOVE ' ] = lang_get ( 'actiongroup_menu_move ' );
176+ }
177+
178+ if ( !isset ( $ t_commands ['COPY ' ] ) &&
179+ access_has_any_project ( config_get ( 'report_bug_threshold ' , null , null , $ t_project_id ) ) ) {
180+ $ t_commands ['COPY ' ] = lang_get ( 'actiongroup_menu_copy ' );
181+ }
182+
183+ if ( !isset ( $ t_commands ['ASSIGN ' ] ) &&
184+ access_has_project_level ( config_get ( 'update_bug_assign_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
185+ if ( ON == config_get ( 'auto_set_status_to_assigned ' , null , null , $ t_project_id ) &&
186+ access_has_project_level ( access_get_status_threshold ( config_get ( 'bug_assigned_status ' , null , null , $ t_project_id ), $ t_project_id ), $ t_project_id ) ) {
187+ $ t_commands ['ASSIGN ' ] = lang_get ( 'actiongroup_menu_assign ' );
188+ } else {
189+ $ t_commands ['ASSIGN ' ] = lang_get ( 'actiongroup_menu_assign ' );
190+ }
191+ }
192+
193+ if ( !isset ( $ t_commands ['CLOSE ' ] ) &&
194+ access_has_project_level ( config_get ( 'update_bug_status_threshold ' , null , null , $ t_project_id ), $ t_project_id ) &&
195+ ( 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 ) ||
196+ access_has_project_level ( config_get ( 'allow_reporter_close ' , null , null , $ t_project_id ), $ t_project_id ) ) ) {
197+ $ t_commands ['CLOSE ' ] = lang_get ( 'actiongroup_menu_close ' );
198+ }
199+
200+ if ( !isset ( $ t_commands ['DELETE ' ] ) &&
201+ access_has_project_level ( config_get ( 'delete_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
202+ $ t_commands ['DELETE ' ] = lang_get ( 'actiongroup_menu_delete ' );
203+ }
204+
205+ if ( !isset ( $ t_commands ['RESOLVE ' ] ) &&
206+ access_has_project_level ( config_get ( 'update_bug_status_threshold ' , null , null , $ t_project_id ), $ t_project_id ) &&
207+ 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 ) ) {
208+ $ t_commands ['RESOLVE ' ] = lang_get ( 'actiongroup_menu_resolve ' );
209+ }
210+
211+ if ( !isset ( $ t_commands ['SET_STICKY ' ] ) &&
212+ access_has_project_level ( config_get ( 'set_bug_sticky_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
213+ $ t_commands ['SET_STICKY ' ] = lang_get ( 'actiongroup_menu_set_sticky ' );
214+ }
215+
216+ if ( !isset ( $ t_commands ['UP_PRIOR ' ] ) &&
217+ access_has_project_level ( config_get ( 'update_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
218+ $ t_commands ['UP_PRIOR ' ] = lang_get ( 'actiongroup_menu_update_priority ' );
219+ }
220+
221+ if ( !isset ( $ t_commands ['EXT_UPDATE_SEVERITY ' ] ) &&
222+ access_has_project_level ( config_get ( 'update_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
223+ $ t_commands ['EXT_UPDATE_SEVERITY ' ] = lang_get ( 'actiongroup_menu_update_severity ' );
224+ }
225+
226+ if ( !isset ( $ t_commands ['UP_STATUS ' ] ) &&
227+ access_has_project_level ( config_get ( 'update_bug_status_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
228+ $ t_commands ['UP_STATUS ' ] = lang_get ( 'actiongroup_menu_update_status ' );
229+ }
230+
231+ if ( !isset ( $ t_commands ['UP_CATEGORY ' ] ) &&
232+ access_has_project_level ( config_get ( 'update_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
233+ $ t_commands ['UP_CATEGORY ' ] = lang_get ( 'actiongroup_menu_update_category ' );
234+ }
235+
236+ if ( !isset ( $ t_commands ['VIEW_STATUS ' ] ) &&
237+ access_has_project_level ( config_get ( 'change_view_status_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
238+ $ t_commands ['VIEW_STATUS ' ] = lang_get ( 'actiongroup_menu_update_view_status ' );
239+ }
240+
241+ if ( !isset ( $ t_commands ['EXT_UPDATE_PRODUCT_BUILD ' ] ) &&
242+ config_get ( 'enable_product_build ' , null , null , $ t_project_id ) == ON &&
243+ access_has_project_level ( config_get ( 'update_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
244+ $ t_commands ['EXT_UPDATE_PRODUCT_BUILD ' ] = lang_get ( 'actiongroup_menu_update_product_build ' );
245+ }
246+
247+ if ( !isset ( $ t_commands ['EXT_ADD_NOTE ' ] ) &&
248+ access_has_project_level ( config_get ( 'add_bugnote_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
249+ $ t_commands ['EXT_ADD_NOTE ' ] = lang_get ( 'actiongroup_menu_add_note ' );
250+ }
251+
252+ if ( !isset ( $ t_commands ['EXT_ATTACH_TAGS ' ] ) &&
253+ access_has_project_level ( config_get ( 'tag_attach_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
254+ $ t_commands ['EXT_ATTACH_TAGS ' ] = lang_get ( 'actiongroup_menu_attach_tags ' );
255+ }
256+
257+ if ( !isset ( $ t_commands ['UP_FIXED_IN_VERSION ' ] ) &&
258+ version_should_show_product_version ( $ t_project_id ) &&
259+ access_has_project_level ( config_get ( 'update_bug_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
260+ $ t_commands ['UP_FIXED_IN_VERSION ' ] = lang_get ( 'actiongroup_menu_update_fixed_in_version ' );
261+ }
262+
263+ if ( !isset ( $ t_commands ['UP_TARGET_VERSION ' ] ) &&
264+ version_should_show_product_version ( $ t_project_id ) &&
265+ access_has_project_level ( config_get ( 'roadmap_update_threshold ' , null , null , $ t_project_id ), $ t_project_id ) ) {
266+ $ t_commands ['UP_TARGET_VERSION ' ] = lang_get ( 'actiongroup_menu_update_target_version ' );
267+ }
268+
269+ $ t_custom_field_ids = custom_field_get_linked_ids ( $ t_project_id );
270+ foreach ( $ t_custom_field_ids as $ t_custom_field_id ) {
271+ if ( !custom_field_has_write_access_to_project ( $ t_custom_field_id , $ t_project_id ) ) {
272+ continue ;
273+ }
274+ $ t_custom_field_def = custom_field_get_definition ( $ t_custom_field_id );
275+ $ t_command_id = 'custom_field_ ' . $ t_custom_field_id ;
276+ $ t_command_caption = sprintf ( lang_get ( 'actiongroup_menu_update_field ' ), lang_get_defaulted ( $ t_custom_field_def ['name ' ] ) );
277+ $ t_commands [$ t_command_id ] = string_display ( $ t_command_caption );
278+ }
279+ }
280+
281+ $ t_custom_group_actions = config_get ( 'custom_group_actions ' );
282+
283+ foreach ( $ t_custom_group_actions as $ t_custom_group_action ) {
284+ # use label if provided to get the localized text, otherwise fallback to action name.
285+ if ( isset ( $ t_custom_group_action ['label ' ] ) ) {
286+ $ t_commands [$ t_custom_group_action ['action ' ]] = lang_get_defaulted ( $ t_custom_group_action ['label ' ] );
287+ } else {
288+ $ t_commands [$ t_custom_group_action ['action ' ]] = lang_get_defaulted ( $ t_custom_group_action ['action ' ] );
289+ }
290+ }
291+
292+ return $ t_commands ;
293+ }
0 commit comments