From 609e755c148651c928495ce14d3962017d85b767 Mon Sep 17 00:00:00 2001 From: Dave Lawrence Date: Thu, 8 Dec 2011 15:21:20 -0500 Subject: Bug 695698: add FlagTypeComment extension --- extensions/FlagTypeComment/Config.pm | 29 ++++ extensions/FlagTypeComment/Extension.pm | 189 +++++++++++++++++++++ extensions/FlagTypeComment/lib/Constants.pm | 50 ++++++ .../en/default/flag/type_comment.html.tmpl | 54 ++++++ .../hook/admin/flag-type/edit-rows.html.tmpl | 41 +++++ .../default/hook/attachment/create-end.html.tmpl | 23 +++ .../en/default/hook/attachment/edit-end.html.tmpl | 23 +++ .../hook/bug/edit-after_custom_fields.html.tmpl | 23 +++ 8 files changed, 432 insertions(+) create mode 100644 extensions/FlagTypeComment/Config.pm create mode 100644 extensions/FlagTypeComment/Extension.pm create mode 100644 extensions/FlagTypeComment/lib/Constants.pm create mode 100644 extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl create mode 100644 extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl create mode 100644 extensions/FlagTypeComment/template/en/default/hook/attachment/create-end.html.tmpl create mode 100644 extensions/FlagTypeComment/template/en/default/hook/attachment/edit-end.html.tmpl create mode 100644 extensions/FlagTypeComment/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl (limited to 'extensions/FlagTypeComment') diff --git a/extensions/FlagTypeComment/Config.pm b/extensions/FlagTypeComment/Config.pm new file mode 100644 index 000000000..e20be10e3 --- /dev/null +++ b/extensions/FlagTypeComment/Config.pm @@ -0,0 +1,29 @@ +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the FlagTypeComment Bugzilla Extension. +# +# The Initial Developer of the Original Code is Alex Keybl +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Keybl +# byron jones + +package Bugzilla::Extension::FlagTypeComment; +use strict; + +use constant NAME => 'FlagTypeComment'; + +use constant REQUIRED_MODULES => []; +use constant OPTIONAL_MODULES => []; + +__PACKAGE__->NAME; diff --git a/extensions/FlagTypeComment/Extension.pm b/extensions/FlagTypeComment/Extension.pm new file mode 100644 index 000000000..4c1b5cc05 --- /dev/null +++ b/extensions/FlagTypeComment/Extension.pm @@ -0,0 +1,189 @@ +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the FlagTypeComment Bugzilla Extension. +# +# The Initial Developer of the Original Code is Alex Keybl +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Keybl +# byron jones + +package Bugzilla::Extension::FlagTypeComment; +use strict; +use base qw(Bugzilla::Extension); + +use Bugzilla::FlagType; +use Bugzilla::Util 'trick_taint'; + +use Bugzilla::Extension::FlagTypeComment::Constants; + +our $VERSION = '1'; + +################ +# Installation # +################ + +sub db_schema_abstract_schema { + my ($self, $args) = @_; + $args->{'schema'}->{'flagtype_comments'} = { + FIELDS => [ + type_id => { + TYPE => 'SMALLINT(6)', + NOTNULL => 1, + REFERENCES => { + TABLE => 'flagtypes', + COLUMN => 'id', + DELETE => 'CASCADE' + } + }, + on_status => { + TYPE => 'CHAR(1)', + NOTNULL => 1 + }, + comment => { + TYPE => 'MEDIUMTEXT', + NOTNULL => 1 + }, + ], + INDEXES => [ + flagtype_comments_idx => ['type_id'], + ], + }; +} + +############# +# Templates # +############# + +sub template_before_process { + my ($self, $args) = @_; + my ($vars, $file) = @$args{qw(vars file)}; + + return unless Bugzilla->user->id; + if (grep { $_ eq $file } FLAGTYPE_COMMENT_TEMPLATES) { + _set_ftc_states($file, $vars); + } +} + +sub _set_ftc_states { + my ($file, $vars) = @_; + my $dbh = Bugzilla->dbh; + + my $db_states; + if ($file =~ /^admin\//) { + # admin + my $type = $vars->{'type'} || return; + if ($type->target_type eq 'bug') { + return unless FLAGTYPE_COMMENT_BUG_FLAGS; + } else { + return unless FLAGTYPE_COMMENT_ATTACHMENT_FLAGS; + } + $db_states = $dbh->selectall_hashref( + "SELECT type_id AS flagtype, on_status AS state, comment AS text + FROM flagtype_comments WHERE type_id=?", + 'state', + undef, + $type->id); + + } else { + # creating/editing attachment / viewing bug + my $bug; + if (exists $vars->{'bug'}) { + $bug = $vars->{'bug'}; + } elsif (exists $vars->{'attachment'}) { + $bug = $vars->{'attachment'}->{bug}; + } else { + return; + } + + my $flag_types = Bugzilla::FlagType::match({ + 'target_type' => ($file =~ /^bug/ ? 'bug' : 'attachment'), + 'product_id' => $bug->product_id, + 'component_id' => $bug->component_id, + 'bug_id' => $bug->id, + 'is_active' => 1, + }); + + my $types = join(',', map { $_->id } @$flag_types); + $db_states = $dbh->selectall_hashref( + "SELECT type_id AS flagtype, on_status AS state, comment AS text + FROM flagtype_comments WHERE type_id IN ($types)", + 'state'); + } + + my @edit_states; + foreach my $state (FLAGTYPE_COMMENT_STATES) { + if (exists $db_states->{$state}) { + push @edit_states, $db_states->{$state}; + } else { + push @edit_states, { state => $state, text => '' }; + } + } + $vars->{'ftc_states'} = \@edit_states; +} + +######### +# Admin # +######### + +sub flagtype_end_of_create { + my ($self, $args) = @_; + _set_flagtypes($args->{id}); +} + +sub flagtype_end_of_update { + my ($self, $args) = @_; + _set_flagtypes($args->{id}); +} + +sub _set_flagtypes { + my $flagtype_id = shift; + my $input = Bugzilla->input_params; + my $dbh = Bugzilla->dbh; + + my $i = 0; + foreach my $state (FLAGTYPE_COMMENT_STATES) { + my $text = $input->{"ftc_text_$i"} || ''; + $text =~ s/\r\n/\n/g; + trick_taint($text); + + if ($text ne '') { + if ($dbh->selectrow_array( + "SELECT 1 FROM flagtype_comments WHERE type_id=? AND on_status=?", + undef, + $flagtype_id, $state) + ) { + $dbh->do( + "UPDATE flagtype_comments SET comment=? + WHERE type_id=? AND on_status=?", + undef, + $text, $flagtype_id, $state); + } else { + $dbh->do( + "INSERT INTO flagtype_comments(type_id, on_status, comment) + VALUES (?, ?, ?)", + undef, + $flagtype_id, $state, $text); + } + + } else { + $dbh->do( + "DELETE FROM flagtype_comments WHERE type_id=? AND on_status=?", + undef, + $flagtype_id, $state); + } + $i++; + } +} + +__PACKAGE__->NAME; diff --git a/extensions/FlagTypeComment/lib/Constants.pm b/extensions/FlagTypeComment/lib/Constants.pm new file mode 100644 index 000000000..e1a99e5b3 --- /dev/null +++ b/extensions/FlagTypeComment/lib/Constants.pm @@ -0,0 +1,50 @@ +# The contents of this file are subject to the Mozilla Public +# License Version 1.1 (the "License"); you may not use this file +# except in compliance with the License. You may obtain a copy of +# the License at http://www.mozilla.org/MPL/ +# +# Software distributed under the License is distributed on an "AS +# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or +# implied. See the License for the specific language governing +# rights and limitations under the License. +# +# The Original Code is the FlagTypeComment Bugzilla Extension. +# +# The Initial Developer of the Original Code is Alex Keybl +# Portions created by the Initial Developer are Copyright (C) 2011 the +# Initial Developer. All Rights Reserved. +# +# Contributor(s): +# Alex Keybl +# byron jones + +package Bugzilla::Extension::FlagTypeComment::Constants; +use strict; + +use base qw(Exporter); +our @EXPORT = qw( + FLAGTYPE_COMMENT_TEMPLATES + FLAGTYPE_COMMENT_STATES + FLAGTYPE_COMMENT_BUG_FLAGS + FLAGTYPE_COMMENT_ATTACHMENT_FLAGS +); + +use constant FLAGTYPE_COMMENT_STATES => ("?", "+", "-"); +use constant FLAGTYPE_COMMENT_BUG_FLAGS => 0; +use constant FLAGTYPE_COMMENT_ATTACHMENT_FLAGS => 1; + +sub FLAGTYPE_COMMENT_TEMPLATES { + my @result = ("admin/flag-type/edit.html.tmpl"); + if (FLAGTYPE_COMMENT_BUG_FLAGS) { + push @result, ("bug/comments.html.tmpl"); + } + if (FLAGTYPE_COMMENT_ATTACHMENT_FLAGS) { + push @result, ( + "attachment/edit.html.tmpl", + "attachment/createformcontents.html.tmpl", + ); + } + return @result; +} + +1; diff --git a/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl b/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl new file mode 100644 index 000000000..81484f17c --- /dev/null +++ b/extensions/FlagTypeComment/template/en/default/flag/type_comment.html.tmpl @@ -0,0 +1,54 @@ +[%# The contents of this file are subject to the Mozilla Public License Version + # 1.1 (the "License"); you may not use this file except in compliance with + # the License. You may obtain a copy of the License at + # http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS IS" basis, + # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + # for the specific language governing rights and limitations under the + # License. + # + # The Original Code is FlagTypeComment Bugzilla Extension. + # + # The Initial Developer of the Original Code is + # the Mozilla Foundation. + # Portions created by the Initial Developer are Copyright (C) 2011 + # the Initial Developer. All Rights Reserved. + # + # Contributor(s): + # Alex Keybl + # byron jones + #%] + +[% IF ftc_states.size %] + +[% END %] diff --git a/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl b/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl new file mode 100644 index 000000000..7f2c328af --- /dev/null +++ b/extensions/FlagTypeComment/template/en/default/hook/admin/flag-type/edit-rows.html.tmpl @@ -0,0 +1,41 @@ +[%# The contents of this file are subject to the Mozilla Public License Version + # 1.1 (the "License"); you may not use this file except in compliance with + # the License. You may obtain a copy of the License at + # http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS IS" basis, + # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + # for the specific language governing rights and limitations under the + # License. + # + # The Original Code is FlagTypeComment Bugzilla Extension. + # + # The Initial Developer of the Original Code is + # the Mozilla Foundation. + # Portions created by the Initial Developer are Copyright (C) 2011 + # the Initial Developer. All Rights Reserved. + # + # Contributor(s): + # Alex Keybl + # byron jones + #%] + +[% IF ftc_states %] + + Flag Comments: + add text into the comment box when flag is changed to a state + + + [% FOREACH state = ftc_states %] + +   + + for [% state.state FILTER html %]
+ + + + [% END %] +[% END %] diff --git a/extensions/FlagTypeComment/template/en/default/hook/attachment/create-end.html.tmpl b/extensions/FlagTypeComment/template/en/default/hook/attachment/create-end.html.tmpl new file mode 100644 index 000000000..dfa010d7c --- /dev/null +++ b/extensions/FlagTypeComment/template/en/default/hook/attachment/create-end.html.tmpl @@ -0,0 +1,23 @@ +[%# The contents of this file are subject to the Mozilla Public License Version + # 1.1 (the "License"); you may not use this file except in compliance with + # the License. You may obtain a copy of the License at + # http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS IS" basis, + # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + # for the specific language governing rights and limitations under the + # License. + # + # The Original Code is FlagTypeComment Bugzilla Extension. + # + # The Initial Developer of the Original Code is + # the Mozilla Foundation. + # Portions created by the Initial Developer are Copyright (C) 2011 + # the Initial Developer. All Rights Reserved. + # + # Contributor(s): + # Alex Keybl + # byron jones + #%] + +[% INCLUDE flag/type_comment.html.tmpl %] diff --git a/extensions/FlagTypeComment/template/en/default/hook/attachment/edit-end.html.tmpl b/extensions/FlagTypeComment/template/en/default/hook/attachment/edit-end.html.tmpl new file mode 100644 index 000000000..dfa010d7c --- /dev/null +++ b/extensions/FlagTypeComment/template/en/default/hook/attachment/edit-end.html.tmpl @@ -0,0 +1,23 @@ +[%# The contents of this file are subject to the Mozilla Public License Version + # 1.1 (the "License"); you may not use this file except in compliance with + # the License. You may obtain a copy of the License at + # http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS IS" basis, + # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + # for the specific language governing rights and limitations under the + # License. + # + # The Original Code is FlagTypeComment Bugzilla Extension. + # + # The Initial Developer of the Original Code is + # the Mozilla Foundation. + # Portions created by the Initial Developer are Copyright (C) 2011 + # the Initial Developer. All Rights Reserved. + # + # Contributor(s): + # Alex Keybl + # byron jones + #%] + +[% INCLUDE flag/type_comment.html.tmpl %] diff --git a/extensions/FlagTypeComment/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl b/extensions/FlagTypeComment/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl new file mode 100644 index 000000000..dfa010d7c --- /dev/null +++ b/extensions/FlagTypeComment/template/en/default/hook/bug/edit-after_custom_fields.html.tmpl @@ -0,0 +1,23 @@ +[%# The contents of this file are subject to the Mozilla Public License Version + # 1.1 (the "License"); you may not use this file except in compliance with + # the License. You may obtain a copy of the License at + # http://www.mozilla.org/MPL/ + # + # Software distributed under the License is distributed on an "AS IS" basis, + # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + # for the specific language governing rights and limitations under the + # License. + # + # The Original Code is FlagTypeComment Bugzilla Extension. + # + # The Initial Developer of the Original Code is + # the Mozilla Foundation. + # Portions created by the Initial Developer are Copyright (C) 2011 + # the Initial Developer. All Rights Reserved. + # + # Contributor(s): + # Alex Keybl + # byron jones + #%] + +[% INCLUDE flag/type_comment.html.tmpl %] -- cgit v1.2.3-24-g4f1b