]>
git.ipfire.org Git - thirdparty/bugzilla.git/blob - editkeywords.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
;
19 use Bugzilla
::Keyword
;
22 my $cgi = Bugzilla
->cgi;
23 my $dbh = Bugzilla
->dbh;
24 my $template = Bugzilla
->template;
27 my $user = Bugzilla
->login(LOGIN_REQUIRED
);
31 $user->in_group('editkeywords')
32 || ThrowUserError
("auth_failure", {group
=> "editkeywords",
34 object
=> "keywords"});
36 my $action = trim
($cgi->param('action') || '');
37 my $key_id = $cgi->param('id');
38 my $token = $cgi->param('token');
40 $vars->{'action'} = $action;
44 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
46 $template->process("admin/keywords/list.html.tmpl", $vars)
47 || ThrowTemplateError
($template->error());
51 if ($action eq 'add') {
52 $vars->{'token'} = issue_session_token
('add_keyword');
54 $template->process("admin/keywords/create.html.tmpl", $vars)
55 || ThrowTemplateError
($template->error());
60 # action='new' -> add keyword entered in the 'action=add' screen
62 if ($action eq 'new') {
63 check_token_data
($token, 'add_keyword');
64 my $name = $cgi->param('name') || '';
65 my $desc = $cgi->param('description') || '';
67 my $keyword = Bugzilla
::Keyword
->create(
68 { name
=> $name, description
=> $desc });
72 $vars->{'message'} = 'keyword_created';
73 $vars->{'name'} = $keyword->name;
74 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
76 $template->process("admin/keywords/list.html.tmpl", $vars)
77 || ThrowTemplateError
($template->error());
83 # action='edit' -> present the edit keywords from
85 # (next action would be 'update')
88 if ($action eq 'edit') {
89 my $keyword = new Bugzilla
::Keyword
($key_id)
90 || ThrowUserError
('invalid_keyword_id', { id
=> $key_id });
92 $vars->{'keyword'} = $keyword;
93 $vars->{'token'} = issue_session_token
('edit_keyword');
95 $template->process("admin/keywords/edit.html.tmpl", $vars)
96 || ThrowTemplateError
($template->error());
102 # action='update' -> update the keyword
105 if ($action eq 'update') {
106 check_token_data
($token, 'edit_keyword');
107 my $keyword = new Bugzilla
::Keyword
($key_id)
108 || ThrowUserError
('invalid_keyword_id', { id
=> $key_id });
111 name
=> scalar $cgi->param('name'),
112 description
=> scalar $cgi->param('description'),
114 my $changes = $keyword->update();
116 delete_token
($token);
118 $vars->{'message'} = 'keyword_updated';
119 $vars->{'keyword'} = $keyword;
120 $vars->{'changes'} = $changes;
121 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
123 $template->process("admin/keywords/list.html.tmpl", $vars)
124 || ThrowTemplateError
($template->error());
128 if ($action eq 'del') {
129 my $keyword = new Bugzilla
::Keyword
($key_id)
130 || ThrowUserError
('invalid_keyword_id', { id
=> $key_id });
132 $vars->{'keyword'} = $keyword;
133 $vars->{'token'} = issue_session_token
('delete_keyword');
135 $template->process("admin/keywords/confirm-delete.html.tmpl", $vars)
136 || ThrowTemplateError
($template->error());
140 if ($action eq 'delete') {
141 check_token_data
($token, 'delete_keyword');
142 my $keyword = new Bugzilla
::Keyword
($key_id)
143 || ThrowUserError
('invalid_keyword_id', { id
=> $key_id });
145 $keyword->remove_from_db();
147 delete_token
($token);
149 $vars->{'message'} = 'keyword_deleted';
150 $vars->{'keyword'} = $keyword;
151 $vars->{'keywords'} = Bugzilla
::Keyword
->get_all_with_bug_count();
153 $template->process("admin/keywords/list.html.tmpl", $vars)
154 || ThrowTemplateError
($template->error());
158 ThrowUserError
('unknown_action', {action
=> $action});