aboutsummaryrefslogtreecommitdiffstats
path: root/editfields.cgi
diff options
context:
space:
mode:
authorlpsolit%gmail.com <>2008-02-06 22:15:34 +0000
committerlpsolit%gmail.com <>2008-02-06 22:15:34 +0000
commitd4f1fd5168130441b735497bac94810a3ccc34c3 (patch)
treed1992b4574056b6a3861028857729175fcfb2c55 /editfields.cgi
parent8474e73b2aed9342d7ffe12aaf40adf085fdc606 (diff)
downloadbugs-d4f1fd5168130441b735497bac94810a3ccc34c3.tar
bugs-d4f1fd5168130441b735497bac94810a3ccc34c3.tar.gz
bugs-d4f1fd5168130441b735497bac94810a3ccc34c3.tar.bz2
bugs-d4f1fd5168130441b735497bac94810a3ccc34c3.tar.xz
bugs-d4f1fd5168130441b735497bac94810a3ccc34c3.zip
Bug 349369: Allow unused custom fields to be deleted from editfields.cgi - Patch by Alex Eiser <aeiser@arc.nasa.gov> r/a=LpSolit
Diffstat (limited to 'editfields.cgi')
-rw-r--r--editfields.cgi43
1 files changed, 43 insertions, 0 deletions
diff --git a/editfields.cgi b/editfields.cgi
index 50564c190..138c6b729 100644
--- a/editfields.cgi
+++ b/editfields.cgi
@@ -117,6 +117,49 @@ elsif ($action eq 'update') {
$template->process('admin/custom_fields/list.html.tmpl', $vars)
|| ThrowTemplateError($template->error());
}
+elsif ($action eq 'del') {
+ my $name = $cgi->param('name');
+
+ # Validate field.
+ $name || ThrowUserError('field_missing_name');
+ # Custom field names must start with "cf_".
+ if ($name !~ /^cf_/) {
+ $name = 'cf_' . $name;
+ }
+ my $field = new Bugzilla::Field({'name' => $name});
+ $field || ThrowUserError('customfield_nonexistent', {'name' => $name});
+
+ $vars->{'field'} = $field;
+ $vars->{'token'} = issue_session_token('delete_field');
+
+ $template->process('admin/custom_fields/confirm-delete.html.tmpl', $vars)
+ || ThrowTemplateError($template->error());
+}
+elsif ($action eq 'delete') {
+ check_token_data($token, 'delete_field');
+ my $name = $cgi->param('name');
+
+ # Validate fields.
+ $name || ThrowUserError('field_missing_name');
+ # Custom field names must start with "cf_".
+ if ($name !~ /^cf_/) {
+ $name = 'cf_' . $name;
+ }
+ my $field = new Bugzilla::Field({'name' => $name});
+ $field || ThrowUserError('customfield_nonexistent', {'name' => $name});
+
+ # Calling remove_from_db will check if field can be deleted.
+ # If the field cannot be deleted, it will throw an error.
+ $field->remove_from_db();
+
+ $vars->{'field'} = $field;
+ $vars->{'message'} = 'custom_field_deleted';
+
+ delete_token($token);
+
+ $template->process('admin/custom_fields/list.html.tmpl', $vars)
+ || ThrowTemplateError($template->error());
+}
else {
ThrowUserError('no_valid_action', {'field' => 'custom_field'});
}