forked from mantisbt/mantisbt
-
Notifications
You must be signed in to change notification settings - Fork 1
/
bug_group_action_api.php
344 lines (296 loc) · 12.8 KB
/
bug_group_action_api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
<?php
# MantisBT - A PHP based bugtracking system
# MantisBT is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
#
# MantisBT is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
/**
* Bug Group Action API
*
* @package CoreAPI
* @subpackage BugGroupActionAPI
* @copyright Copyright 2000 - 2002 Kenzaburo Ito - [email protected]
* @copyright Copyright 2002 MantisBT Team - [email protected]
* @link http://www.mantisbt.org
*
* @uses bug_api.php
* @uses config_api.php
* @uses constant_inc.php
* @uses helper_api.php
* @uses html_api.php
* @uses lang_api.php
* @uses string_api.php
*/
require_api( 'bug_api.php' );
require_api( 'config_api.php' );
require_api( 'constant_inc.php' );
require_api( 'helper_api.php' );
require_api( 'html_api.php' );
require_api( 'lang_api.php' );
require_api( 'string_api.php' );
require_css( 'status_config.php' );
/**
* Initialise bug action group api
* @param string $p_action Custom action to run.
* @return void
*/
function bug_group_action_init( $p_action ) {
$t_valid_actions = bug_group_action_get_commands( current_user_get_accessible_projects() );
$t_action = strtoupper( $p_action );
if( !isset( $t_valid_actions[$t_action] ) &&
!isset( $t_valid_actions['EXT_' . $t_action] )
) {
trigger_error( ERROR_GENERIC, ERROR );
}
$t_include_file = config_get_global( 'absolute_path' ) . 'bug_actiongroup_' . $p_action . '_inc.php';
if( !file_exists( $t_include_file ) ) {
trigger_error( ERROR_GENERIC, ERROR );
} else {
require_once( $t_include_file );
}
}
/**
* Print the top part for the bug action group page.
* @return void
*/
function bug_group_action_print_top() {
layout_page_header();
layout_page_begin();
}
/**
* Print the bottom part for the bug action group page.
* @return void
*/
function bug_group_action_print_bottom() {
layout_page_end();
}
/**
* Print the list of selected issues and the legend for the status colors.
*
* @param array $p_bug_ids_array An array of issue ids.
* @return void
*/
function bug_group_action_print_bug_list( array $p_bug_ids_array ) {
echo '<tr>';
echo '<th class="category" colspan="2">';
echo lang_get( 'actiongroup_bugs' );
echo '</th>';
echo '</tr>';
foreach( $p_bug_ids_array as $t_bug_id ) {
# choose color based on status
$t_status_css = html_get_status_css_fg( bug_get_field( $t_bug_id, 'status' ), auth_get_current_user_id(), bug_get_field( $t_bug_id, 'project_id' ) );
$t_lead = '<i class="fa fa-square fa-status-box ' . $t_status_css . '"></i> ';
$t_lead .= ' ' . string_get_bug_view_link( $t_bug_id );
echo sprintf( "<tr> <td>%s</td> <td>%s</td> </tr>\n", $t_lead, string_attribute( bug_get_field( $t_bug_id, 'summary' ) ) );
}
}
/**
* Print a table listing the failed results following a group action.
*
* @param array $p_failed_ids List of failed results [bug_id => reason for failure]
*
* @return void
*/
function bug_group_action_print_results( array $p_failed_ids ) {
$t_format = "<tr>"
. "\n\t" . '<td width="50%%">%s' . lang_get( 'word_separator' ) . '%s</td>'
. "\n\t" . '<td>%s</td>'
. "\n</tr>\n";
$t_label = lang_get( 'label' );
echo '<div><br />', PHP_EOL;
echo '<div class="table-responsive">', PHP_EOL;
echo '<table class="table table-bordered table-condensed table-striped">', PHP_EOL;
foreach( $p_failed_ids as $t_id => $t_reason ) {
printf( $t_format,
sprintf( $t_label, string_get_bug_view_link( $t_id ) ),
string_display_line( bug_get_field( $t_id, 'summary' ) ),
$t_reason
);
}
echo '</table>', PHP_EOL;
echo '</div>', PHP_EOL;
print_link_button( 'view_all_bug_page.php', lang_get( 'proceed' ) );
echo '</div>', PHP_EOL;
}
/**
* Print the array of issue ids via hidden fields in the form to be passed on to
* the bug action group action page.
*
* @param array $p_bug_ids_array An array of issue ids.
* @return void
*/
function bug_group_action_print_hidden_fields( array $p_bug_ids_array ) {
foreach( $p_bug_ids_array as $t_bug_id ) {
echo '<input type="hidden" name="bug_arr[]" value="' . $t_bug_id . '" />' . "\n";
}
}
/**
* Prints the list of fields in the custom action form. These are the user inputs
* and the submit button. This ends up calling action_<action>_print_fields()
* from bug_actiongroup_<action>_inc.php
*
* @param string $p_action The custom action name without the "EXT_" prefix.
* @return void
*/
function bug_group_action_print_action_fields( $p_action ) {
$t_function_name = 'action_' . $p_action . '_print_fields';
$t_function_name();
}
/**
* Prints some title text for the custom action page. This ends up calling
* action_<action>_print_title() from bug_actiongroup_<action>_inc.php
*
* @param string $p_action The custom action name without the "EXT_" prefix.
* @return void
*/
function bug_group_action_print_title( $p_action ) {
$t_function_name = 'action_' . $p_action . '_print_title';
$t_function_name();
}
/**
* Validates the combination of an action and a bug. This ends up calling
* action_<action>_validate() from bug_actiongroup_<action>_inc.php
*
* @param string $p_action The custom action name without the "EXT_" prefix.
* @param integer $p_bug_id The id of the bug to validate the action on.
*
* @return boolean|array true if action can be applied or array of ( bug_id => reason for failure to validate )
*/
function bug_group_action_validate( $p_action, $p_bug_id ) {
$t_function_name = 'action_' . $p_action . '_validate';
return $t_function_name( $p_bug_id );
}
/**
* Executes an action on a bug. This ends up calling
* action_<action>_process() from bug_actiongroup_<action>_inc.php
*
* @param string $p_action The custom action name without the "EXT_" prefix.
* @param integer $p_bug_id The id of the bug to validate the action on.
* @return boolean|array Action can be applied., ( bug_id => reason for failure to process )
*/
function bug_group_action_process( $p_action, $p_bug_id ) {
$t_function_name = 'action_' . $p_action . '_process';
return $t_function_name( $p_bug_id );
}
/**
* Get a list of bug group actions available to the current user for one or
* more projects.
* @param array $p_project_ids An array containing one or more project IDs.
* @return array
*/
function bug_group_action_get_commands( array $p_project_ids = null ) {
if( $p_project_ids === null || count( $p_project_ids ) == 0 ) {
$p_project_ids = array( ALL_PROJECTS );
}
$t_user_id = auth_get_current_user_id();
$t_commands = array();
version_cache_array_rows( $p_project_ids );
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, $t_user_id, $t_project_id ), $t_project_id ) ) {
$t_commands['MOVE'] = lang_get( 'actiongroup_menu_move' );
}
if( !isset( $t_commands['COPY'] ) &&
access_has_any_project_level( 'report_bug_threshold' ) ) {
$t_commands['COPY'] = lang_get( 'actiongroup_menu_copy' );
}
if( !isset( $t_commands['ASSIGN'] ) &&
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'] ) && $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, $t_user_id, $t_project_id ), $t_project_id ) ) {
$t_commands['DELETE'] = lang_get( 'actiongroup_menu_delete' );
}
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, $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'] ) && $t_update_bug_allowed ) {
$t_commands['UP_PRIOR'] = lang_get( 'actiongroup_menu_update_priority' );
}
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'] ) && $t_update_bug_status_allowed ) {
$t_commands['UP_STATUS'] = lang_get( 'actiongroup_menu_update_status' );
}
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, $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, $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, $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, $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, $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 ) && $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 ) && $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, $t_user_id, $t_project_id ), $t_project_id ) ) {
$t_commands['UP_TARGET_VERSION'] = lang_get( 'actiongroup_menu_update_target_version' );
}
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_line( $t_command_caption );
}
}
}
}
$t_custom_group_actions = config_get( 'custom_group_actions' );
foreach( $t_custom_group_actions as $t_custom_group_action ) {
# use label if provided to get the localized text, otherwise fallback to action name.
if( isset( $t_custom_group_action['label'] ) ) {
$t_commands[$t_custom_group_action['action']] = lang_get_defaulted( $t_custom_group_action['label'] );
} else {
$t_commands[$t_custom_group_action['action']] = lang_get_defaulted( $t_custom_group_action['action'] );
}
}
return $t_commands;
}