From 775362d8fb630da4fbb1e3f75c45183fd0a28667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Buclin?= Date: Tue, 1 Aug 2017 16:37:44 +0200 Subject: Backport upstream bug 69267: Add the ability to deactivate keywords --- Bugzilla/Bug.pm | 14 +++++ Bugzilla/DB/Schema.pm | 3 +- Bugzilla/Install/DB.pm | 4 ++ Bugzilla/Keyword.pm | 28 +++++++-- Bugzilla/Template.pm | 7 ++- Bugzilla/WebService/Bug.pm | 1 + docs/en/rst/administering/keywords.rst | 6 +- editkeywords.cgi | 1 + template/en/default/admin/keywords/edit.html.tmpl | 11 +++- template/en/default/admin/keywords/list.html.tmpl | 56 +++++++++-------- template/en/default/bug/create/create.html.tmpl | 2 +- template/en/default/bug/edit.html.tmpl | 2 +- template/en/default/global/user-error.html.tmpl | 2 +- template/en/default/reports/keywords.html.tmpl | 73 ++++++++++++++++------- 14 files changed, 148 insertions(+), 62 deletions(-) diff --git a/Bugzilla/Bug.pm b/Bugzilla/Bug.pm index 8b4493f85..00231c1c5 100644 --- a/Bugzilla/Bug.pm +++ b/Bugzilla/Bug.pm @@ -1848,6 +1848,20 @@ sub _check_keywords { my $obj = Bugzilla::Keyword->check($keyword); $keywords{$obj->id} = $obj; } + + my %old_kw_id; + if (blessed $invocant) { + my @old_keywords = @{$invocant->keyword_objects}; + %old_kw_id = map { $_->id => 1 } @old_keywords; + } + + foreach my $keyword (values %keywords) { + next if $keyword->is_active || exists $old_kw_id{$keyword->id}; + + ThrowUserError('value_inactive', + { value => $keyword->name, class => ref $keyword }); + } + return [values %keywords]; } diff --git a/Bugzilla/DB/Schema.pm b/Bugzilla/DB/Schema.pm index d1c1dc7e9..d2742bc73 100644 --- a/Bugzilla/DB/Schema.pm +++ b/Bugzilla/DB/Schema.pm @@ -587,6 +587,8 @@ use constant ABSTRACT_SCHEMA => { PRIMARYKEY => 1}, name => {TYPE => 'varchar(64)', NOTNULL => 1}, description => {TYPE => 'MEDIUMTEXT', NOTNULL => 1}, + is_active => {TYPE => 'BOOLEAN', NOTNULL => 1, + DEFAULT => 'TRUE'}, ], INDEXES => [ keyworddefs_name_idx => {FIELDS => ['name'], @@ -604,7 +606,6 @@ use constant ABSTRACT_SCHEMA => { REFERENCES => {TABLE => 'keyworddefs', COLUMN => 'id', DELETE => 'CASCADE'}}, - ], INDEXES => [ keywords_bug_id_idx => {FIELDS => [qw(bug_id keywordid)], diff --git a/Bugzilla/Install/DB.pm b/Bugzilla/Install/DB.pm index ed2539251..f7fd8b2ab 100644 --- a/Bugzilla/Install/DB.pm +++ b/Bugzilla/Install/DB.pm @@ -732,6 +732,10 @@ sub update_table_definitions { # 2015-12-16 LpSolit@gmail.com - Bug 1232578 _sanitize_audit_log_table(); + # 2014-11-18 dylan@mozilla.com - Bug 69267 + $dbh->bz_add_column('keyworddefs', 'is_active', + {TYPE => 'BOOLEAN', NOTNULL => 1, DEFAULT => 'TRUE'}); + ################################################################ # New --TABLE-- changes should go *** A B O V E *** this point # ################################################################ diff --git a/Bugzilla/Keyword.pm b/Bugzilla/Keyword.pm index afa93e1e9..ef044a0c5 100644 --- a/Bugzilla/Keyword.pm +++ b/Bugzilla/Keyword.pm @@ -26,6 +26,7 @@ use constant DB_COLUMNS => qw( keyworddefs.id keyworddefs.name keyworddefs.description + keyworddefs.is_active ); use constant DB_TABLE => 'keyworddefs'; @@ -33,11 +34,13 @@ use constant DB_TABLE => 'keyworddefs'; use constant VALIDATORS => { name => \&_check_name, description => \&_check_description, + is_active => \&_check_is_active, }; use constant UPDATE_COLUMNS => qw( name description + is_active ); ############################### @@ -62,6 +65,7 @@ sub bug_count { sub set_name { $_[0]->set('name', $_[1]); } sub set_description { $_[0]->set('description', $_[1]); } +sub set_is_active { $_[0]->set('is_active', $_[1]); } ############################### #### Subroutines ###### @@ -125,6 +129,10 @@ sub _check_description { return $desc; } +sub _check_is_active { return $_[1] ? 1 : 0 } + +sub is_active { return $_[0]->{is_active} } + 1; __END__ @@ -145,13 +153,13 @@ Bugzilla::Keyword - A Keyword that can be added to a bug. Bugzilla::Keyword represents a keyword that can be added to a bug. -This implements all standard C methods. See +This implements all standard C methods. See L for more details. -=head1 SUBROUTINES +=head1 METHODS -This is only a list of subroutines specific to C. -See L for more subroutines that this object +This is only a list of methods specific to C. +See L for more methods that this object implements. =over @@ -166,6 +174,18 @@ implements. Returns: A reference to an array of Keyword objects, or an empty arrayref if there are no keywords. +=item C + + Description: Indicates if the keyword may be used on a bug + Params: none + Returns: a boolean value that is true if the keyword can be applied to bugs. + +=item C + + Description: Set the is_active property to a boolean value + Params: the new value of the is_active property. + Returns: nothing + =back =cut diff --git a/Bugzilla/Template.pm b/Bugzilla/Template.pm index 41b9265c6..95882b65f 100644 --- a/Bugzilla/Template.pm +++ b/Bugzilla/Template.pm @@ -1122,11 +1122,16 @@ sub create { # Whether or not keywords are enabled, in this Bugzilla. 'use_keywords' => sub { return Bugzilla::Keyword->any_exist; }, - # All the keywords. + # All the keywords 'all_keywords' => sub { return [map { $_->name } Bugzilla::Keyword->get_all()]; }, + # All the active keywords + 'active_keywords' => sub { + return [map { $_->name } grep { $_->is_active } Bugzilla::Keyword->get_all()]; + }, + 'feature_enabled' => sub { return Bugzilla->feature(@_); }, # field_descs can be somewhat slow to generate, so we generate diff --git a/Bugzilla/WebService/Bug.pm b/Bugzilla/WebService/Bug.pm index b07d3cb01..34e6b6662 100644 --- a/Bugzilla/WebService/Bug.pm +++ b/Bugzilla/WebService/Bug.pm @@ -245,6 +245,7 @@ sub _legal_field_values { elsif ($field_name eq 'keywords') { my @legal_keywords = Bugzilla::Keyword->get_all; foreach my $value (@legal_keywords) { + next unless $value->is_active; push (@result, { name => $self->type('string', $value->name), description => $self->type('string', $value->description), diff --git a/docs/en/rst/administering/keywords.rst b/docs/en/rst/administering/keywords.rst index 245bcbe4c..d61a5aea5 100644 --- a/docs/en/rst/administering/keywords.rst +++ b/docs/en/rst/administering/keywords.rst @@ -10,7 +10,5 @@ must be fixed by the next release—this keyword can make tracking those bugs much easier. Keywords are global, rather than per product. Keywords can be created, edited, or deleted by clicking the "Keywords" -link in the admin page. There are two fields for each keyword—the keyword -itself and a brief description. Currently keywords cannot be marked obsolete -to prevent future usage. - +link in the admin page. There are three fields for each keyword—the keyword +itself, a brief description, and if the keyword is active or not. diff --git a/editkeywords.cgi b/editkeywords.cgi index 01f30dbed..e6b62bec3 100755 --- a/editkeywords.cgi +++ b/editkeywords.cgi @@ -110,6 +110,7 @@ if ($action eq 'update') { $keyword->set_all({ name => scalar $cgi->param('name'), description => scalar $cgi->param('description'), + is_active => scalar $cgi->param('is_active'), }); my $changes = $keyword->update(); diff --git a/template/en/default/admin/keywords/edit.html.tmpl b/template/en/default/admin/keywords/edit.html.tmpl index 23158d36f..7e6617a84 100644 --- a/template/en/default/admin/keywords/edit.html.tmpl +++ b/template/en/default/admin/keywords/edit.html.tmpl @@ -18,14 +18,19 @@
- - - + + + + + [% INCLUDE bug/field.html.tmpl bug = default, field = bug_fields.keywords, editable = 1, - value = keywords, possible_values = all_keywords, + value = keywords, possible_values = active_keywords, desc_url = "describekeywords.cgi", value_span = 3 %] diff --git a/template/en/default/bug/edit.html.tmpl b/template/en/default/bug/edit.html.tmpl index 1e10d38e8..e269d438d 100644 --- a/template/en/default/bug/edit.html.tmpl +++ b/template/en/default/bug/edit.html.tmpl @@ -549,7 +549,7 @@ [% INCLUDE bug/field.html.tmpl bug = bug, field = bug_fields.keywords, value = bug.keywords editable = bug.check_can_change_field("keywords", 0, 1), - desc_url = "describekeywords.cgi", possible_values = all_keywords + desc_url = "describekeywords.cgi", possible_values = active_keywords %] [% END %] diff --git a/template/en/default/global/user-error.html.tmpl b/template/en/default/global/user-error.html.tmpl index 69afaf46a..dcf4fc789 100644 --- a/template/en/default/global/user-error.html.tmpl +++ b/template/en/default/global/user-error.html.tmpl @@ -1433,7 +1433,7 @@ Either you mis-typed the name or that user has not yet registered for a [% terms.Bugzilla %] account. [% ELSIF class == "Bugzilla::Keyword" %] - See the list of available keywords. + See the list of available keywords. [% END %] [% ELSIF error == "old_password_incorrect" %] diff --git a/template/en/default/reports/keywords.html.tmpl b/template/en/default/reports/keywords.html.tmpl index 598979d33..6e7ad0c50 100644 --- a/template/en/default/reports/keywords.html.tmpl +++ b/template/en/default/reports/keywords.html.tmpl @@ -18,36 +18,67 @@ title = "$terms.Bugzilla Keyword Descriptions" style_urls = ['skins/standard/admin.css'] %] +[% cgi = Bugzilla.cgi %] +[% show_inactive_keywords = cgi.param("show_inactive_keywords") %] -
Name: +
Description:
[% INCLUDE global/textarea.html.tmpl + id = 'description' name = 'description' minrows = 4 cols = 64 diff --git a/template/en/default/admin/keywords/list.html.tmpl b/template/en/default/admin/keywords/list.html.tmpl index c3f4a5292..9d920036e 100644 --- a/template/en/default/admin/keywords/list.html.tmpl +++ b/template/en/default/admin/keywords/list.html.tmpl @@ -10,6 +10,7 @@ # keywords: array keyword objects having the properties: # - id: number. The ID of the keyword. # - name: string. The name of the keyword. + # - is_active: boolean. true if the keyword can be used. # - description: string. The description of the keyword. # - bug_count: number. The number of bugs with the keyword. #%] @@ -20,34 +21,39 @@ %] [% columns = [ - { - name => "name" - heading => "Edit keyword..." - contentlink => "editkeywords.cgi?action=edit&id=%%id%%" - }, - { - name => "description" - heading => "Description" - allow_html_content => 1 - }, - { - name => "bug_count" - heading => "$terms.Bugs" - class => "right" - contentlink => "buglist.cgi?keywords=%%name%%" - }, - { - heading => "Action" - content => "Delete" - contentlink => "editkeywords.cgi?action=del&id=%%id%%" - } - ] + { + name => "name" + heading => "Edit keyword..." + contentlink => "editkeywords.cgi?action=edit&id=%%id%%" + }, + { + name => "description" + heading => "Description" + allow_html_content => 1 + }, + { + name => "is_active", + heading => "Active", + yesno_field => 1 + }, + { + name => "bug_count" + heading => "$terms.Bugs" + class => "right" + contentlink => "buglist.cgi?keywords=%%name%%" + }, + { + heading => "Action" + content => "Delete" + contentlink => "editkeywords.cgi?action=del&id=%%id%%" + } +] %] [% PROCESS admin/table.html.tmpl - columns = columns - data = keywords - footer = footer_row + columns = columns + data = keywords + footer = footer_row %]

Add a new keyword

diff --git a/template/en/default/bug/create/create.html.tmpl b/template/en/default/bug/create/create.html.tmpl index 61faf1c1a..d76c082cc 100644 --- a/template/en/default/bug/create/create.html.tmpl +++ b/template/en/default/bug/create/create.html.tmpl @@ -537,7 +537,7 @@ TUI_hide_default('attachment_text_field');
+ + +

+ [% show_inactive_keywords ? "Show" : "Hide" FILTER html %] inactive keywords +

+ +
+ [% FOREACH keyword = keywords %] - - - - - - + + + + + + + [% END %]
Name DescriptionActive Open [% terms.Bugs %] Total [% terms.Bugs %]
[% keyword.name FILTER html %][% keyword.description FILTER html_light %] - [% IF keyword.bug_count > 0 %] - - Search - [% ELSE %] - none - [% END %] - - [% IF keyword.bug_count > 0 %] - - [% keyword.bug_count %] - [% ELSE %] - none - [% END %] -
[% keyword.name FILTER html %][% keyword.description FILTER html_light %][% keyword.is_active ? "Yes" : "No" FILTER html %] + [% IF keyword.bug_count > 0 %] + + Search + [% ELSE %] + none + [% END %] + + [% IF keyword.bug_count > 0 %] + + [% keyword.bug_count %] + [% ELSE %] + none + [% END %] +
-- cgit v1.2.1