diff options
Diffstat (limited to 'editfields.cgi')
-rw-r--r-- | editfields.cgi | 43 |
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'}); } |