diff options
8 files changed, 432 insertions, 0 deletions
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 <akeybl@mozilla.com> +# byron jones <glob@mozilla.com> + +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 <akeybl@mozilla.com> +# byron jones <glob@mozilla.com> + +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 <akeybl@mozilla.com> +# byron jones <glob@mozilla.com> + +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 <akeybl@mozilla.com> + # byron jones <glob@mozilla.com> + #%] + +[% IF ftc_states.size %] + <script type="text/javascript"> + YAHOO.util.Event.onDOMReady(function() { + var selects = YAHOO.util.Dom.getElementsByClassName('flag_select'); + for (var i = 0; i < selects.length; i++) { + YAHOO.util.Event.on(selects[i], 'change', ftc_on_change); + } + }); + + function ftc_on_change(ev) { + var id = ev.target.id.split('-')[1]; + var state = ev.target.value; + var commentEl = document.getElementById('comment'); + if (!commentEl) return; + [% FOREACH state = ftc_states %] + [% IF state.flagtype %] + if ([% state.flagtype FILTER none %] == id && '[% state.state FILTER js %]' == state) { + var text = '[% state.text FILTER js %]'; + var value = commentEl.value; + if (value == text) { + return; + } else if (value == '') { + commentEl.value = text; + } else { + commentEl.value = text + "\n\n" + value; + } + } + [% END %] + [% END %] + } + </script> +[% 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 <akeybl@mozilla.com> + # byron jones <glob@mozilla.com> + #%] + +[% IF ftc_states %] + <tr> + <th>Flag Comments:</th> + <td>add text into the comment box when flag is changed to a state</td> + </tr> + + [% FOREACH state = ftc_states %] + <tr> + <td> </td> + <td> + for [% state.state FILTER html %]<br> + <textarea + id="ftc_text_[% loop.index FILTER none %]" + name="ftc_text_[% loop.index FILTER none %]" + cols="50" rows="2">[% state.text FILTER html %]</textarea> + </td> + </tr> + [% 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 <akeybl@mozilla.com> + # byron jones <glob@mozilla.com> + #%] + +[% 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 <akeybl@mozilla.com> + # byron jones <glob@mozilla.com> + #%] + +[% 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 <akeybl@mozilla.com> + # byron jones <glob@mozilla.com> + #%] + +[% INCLUDE flag/type_comment.html.tmpl %] |