]>
git.ipfire.org Git - thirdparty/bugzilla.git/blob - editfields.cgi
2 # This Source Code Form is subject to the terms of the Mozilla Public
3 # License, v. 2.0. If a copy of the MPL was not distributed with this
4 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
6 # This Source Code Form is "Incompatible With Secondary Licenses", as
7 # defined by the Mozilla Public License, v. 2.0.
16 use Bugzilla
::Constants
;
22 my $cgi = Bugzilla
->cgi;
23 my $template = Bugzilla
->template;
26 # Make sure the user is logged in and is an administrator.
27 my $user = Bugzilla
->login(LOGIN_REQUIRED
);
28 $user->in_group('admin')
29 || ThrowUserError
('auth_failure', {group
=> 'admin',
31 object
=> 'custom_fields'});
33 my $action = trim
($cgi->param('action') || '');
34 my $token = $cgi->param('token');
38 # List all existing custom fields if no action is given.
40 $template->process('admin/custom_fields/list.html.tmpl', $vars)
41 || ThrowTemplateError
($template->error());
43 # Interface to add a new custom field.
44 elsif ($action eq 'add') {
45 $vars->{'token'} = issue_session_token
('add_field');
47 $template->process('admin/custom_fields/create.html.tmpl', $vars)
48 || ThrowTemplateError
($template->error());
50 elsif ($action eq 'new') {
51 check_token_data
($token, 'add_field');
52 $vars->{'field'} = Bugzilla
::Field
->create({
53 name
=> scalar $cgi->param('name'),
54 description
=> scalar $cgi->param('desc'),
55 long_desc
=> scalar $cgi->param('long_desc'),
56 type
=> scalar $cgi->param('type'),
57 sortkey
=> scalar $cgi->param('sortkey'),
58 mailhead
=> scalar $cgi->param('new_bugmail'),
59 enter_bug
=> scalar $cgi->param('enter_bug'),
60 obsolete
=> scalar $cgi->param('obsolete'),
63 visibility_field_id
=> scalar $cgi->param('visibility_field_id'),
64 visibility_values
=> [ $cgi->param('visibility_values') ],
65 value_field_id
=> scalar $cgi->param('value_field_id'),
66 reverse_desc
=> scalar $cgi->param('reverse_desc'),
67 is_mandatory
=> scalar $cgi->param('is_mandatory'),
72 $vars->{'message'} = 'custom_field_created';
74 $template->process('admin/custom_fields/list.html.tmpl', $vars)
75 || ThrowTemplateError
($template->error());
77 elsif ($action eq 'edit') {
78 my $name = $cgi->param('name') || ThrowUserError
('field_missing_name');
79 # Custom field names must start with "cf_".
80 if ($name !~ /^cf_/) {
81 $name = 'cf_' . $name;
83 my $field = new Bugzilla
::Field
({'name' => $name});
84 $field || ThrowUserError
('customfield_nonexistent', {'name' => $name});
86 $vars->{'field'} = $field;
87 $vars->{'token'} = issue_session_token
('edit_field');
89 $template->process('admin/custom_fields/edit.html.tmpl', $vars)
90 || ThrowTemplateError
($template->error());
92 elsif ($action eq 'update') {
93 check_token_data
($token, 'edit_field');
94 my $name = $cgi->param('name');
97 $name || ThrowUserError
('field_missing_name');
98 # Custom field names must start with "cf_".
99 if ($name !~ /^cf_/) {
100 $name = 'cf_' . $name;
102 my $field = new Bugzilla
::Field
({'name' => $name});
103 $field || ThrowUserError
('customfield_nonexistent', {'name' => $name});
105 $field->set_description($cgi->param('desc'));
106 $field->set_long_desc($cgi->param('long_desc'));
107 $field->set_sortkey($cgi->param('sortkey'));
108 $field->set_in_new_bugmail($cgi->param('new_bugmail'));
109 $field->set_enter_bug($cgi->param('enter_bug'));
110 $field->set_obsolete($cgi->param('obsolete'));
111 $field->set_is_mandatory($cgi->param('is_mandatory'));
112 $field->set_visibility_field($cgi->param('visibility_field_id'));
113 $field->set_visibility_values([ $cgi->param('visibility_values') ]);
114 $field->set_value_field($cgi->param('value_field_id'));
115 $field->set_reverse_desc($cgi->param('reverse_desc'));
118 delete_token
($token);
120 $vars->{'field'} = $field;
121 $vars->{'message'} = 'custom_field_updated';
123 $template->process('admin/custom_fields/list.html.tmpl', $vars)
124 || ThrowTemplateError
($template->error());
126 elsif ($action eq 'del') {
127 my $name = $cgi->param('name');
130 $name || ThrowUserError
('field_missing_name');
131 # Custom field names must start with "cf_".
132 if ($name !~ /^cf_/) {
133 $name = 'cf_' . $name;
135 my $field = new Bugzilla
::Field
({'name' => $name});
136 $field || ThrowUserError
('customfield_nonexistent', {'name' => $name});
138 $vars->{'field'} = $field;
139 $vars->{'token'} = issue_session_token
('delete_field');
141 $template->process('admin/custom_fields/confirm-delete.html.tmpl', $vars)
142 || ThrowTemplateError
($template->error());
144 elsif ($action eq 'delete') {
145 check_token_data
($token, 'delete_field');
146 my $name = $cgi->param('name');
149 $name || ThrowUserError
('field_missing_name');
150 # Custom field names must start with "cf_".
151 if ($name !~ /^cf_/) {
152 $name = 'cf_' . $name;
154 my $field = new Bugzilla
::Field
({'name' => $name});
155 $field || ThrowUserError
('customfield_nonexistent', {'name' => $name});
157 # Calling remove_from_db will check if field can be deleted.
158 # If the field cannot be deleted, it will throw an error.
159 $field->remove_from_db();
161 $vars->{'field'} = $field;
162 $vars->{'message'} = 'custom_field_deleted';
164 delete_token
($token);
166 $template->process('admin/custom_fields/list.html.tmpl', $vars)
167 || ThrowTemplateError
($template->error());
170 ThrowUserError
('unknown_action', {action
=> $action});