summaryrefslogtreecommitdiffstats
path: root/extensions
diff options
context:
space:
mode:
authorMax Kanat-Alexander <mkanat@bugzilla.org>2010-06-18 22:48:21 +0200
committerMax Kanat-Alexander <mkanat@bugzilla.org>2010-06-18 22:48:21 +0200
commitdb2a5492739a143ff828bbf25b1c97ab1524a9b9 (patch)
tree5047b59069a9f21f4a45ce770d991fc53fcba245 /extensions
parent7ae63b1e06f607ede3ed32829ac9316e4c657247 (diff)
downloadbugzilla-db2a5492739a143ff828bbf25b1c97ab1524a9b9.tar.gz
bugzilla-db2a5492739a143ff828bbf25b1c97ab1524a9b9.tar.xz
Bug 556422: Move the existing bug-moving functionality into an extension
called OldBugMove. r=dkl, a=mkanat
Diffstat (limited to 'extensions')
-rw-r--r--extensions/OldBugMove/Config.pm25
-rw-r--r--extensions/OldBugMove/Extension.pm214
-rw-r--r--extensions/OldBugMove/disabled0
-rw-r--r--extensions/OldBugMove/lib/Params.pm60
-rw-r--r--extensions/OldBugMove/template/en/default/admin/params/oldbugmove.html.tmpl40
-rw-r--r--extensions/OldBugMove/template/en/default/hook/bug/edit-after_comment_textarea.html.tmpl27
-rw-r--r--extensions/OldBugMove/template/en/default/hook/bug/format_comment-type.txt.tmpl29
-rw-r--r--extensions/OldBugMove/template/en/default/hook/global/user-error-auth_failure_action.html.tmpl23
-rw-r--r--extensions/OldBugMove/template/en/default/hook/global/user-error-errors.html.tmpl29
9 files changed, 447 insertions, 0 deletions
diff --git a/extensions/OldBugMove/Config.pm b/extensions/OldBugMove/Config.pm
new file mode 100644
index 000000000..e40126046
--- /dev/null
+++ b/extensions/OldBugMove/Config.pm
@@ -0,0 +1,25 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# 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 OldBugMove Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is Everything Solved, Inc.
+# Portions created by the Initial Developer is Copyright (C) 2010 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Max Kanat-Alexander <mkanat@bugzilla.org>
+
+package Bugzilla::Extension::OldBugMove;
+use strict;
+use constant NAME => 'OldBugMove';
+__PACKAGE__->NAME;
diff --git a/extensions/OldBugMove/Extension.pm b/extensions/OldBugMove/Extension.pm
new file mode 100644
index 000000000..c6b5659b0
--- /dev/null
+++ b/extensions/OldBugMove/Extension.pm
@@ -0,0 +1,214 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# 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 OldBugMove Bugzilla Extension.
+#
+# The Initial Developer of the Original Code is Everything Solved, Inc.
+# Portions created by the Initial Developer are Copyright (C) 2010 the
+# Initial Developer. All Rights Reserved.
+#
+# Contributor(s):
+# Max Kanat-Alexander <mkanat@bugzilla.org>
+
+package Bugzilla::Extension::OldBugMove;
+use strict;
+use base qw(Bugzilla::Extension);
+use Bugzilla::Constants;
+use Bugzilla::Error;
+use Bugzilla::Field::Choice;
+use Bugzilla::Mailer;
+use Bugzilla::User;
+use Bugzilla::Util qw(trim);
+
+use Scalar::Util qw(blessed);
+use Storable qw(dclone);
+
+# This is 4 because that's what it originally was when this code was
+# a part of Bugzilla.
+use constant CMT_MOVED_TO => 4;
+
+our $VERSION = BUGZILLA_VERSION;
+
+sub install_update_db {
+ my $reso_type = Bugzilla::Field::Choice->type('resolution');
+ my $moved_reso = $reso_type->new({ name => 'MOVED' });
+ # We make the MOVED resolution inactive, so that it doesn't show up
+ # as a valid drop-down option.
+ if ($moved_reso) {
+ $moved_reso->set_is_active(0);
+ $moved_reso->update();
+ }
+ else {
+ print "Creating the MOVED resolution...\n";
+ $reso_type->create(
+ { value => 'MOVED', sortkey => '30000', isactive => 0 });
+ }
+}
+
+sub config_add_panels {
+ my ($self, $args) = @_;
+ my $modules = $args->{'panel_modules'};
+ $modules->{'OldBugMove'} = 'Bugzilla::Extension::OldBugMove::Params';
+}
+
+sub template_before_create {
+ my ($self, $args) = @_;
+ my $config = $args->{config};
+
+ my $constants = $config->{CONSTANTS};
+ $constants->{CMT_MOVED_TO} = CMT_MOVED_TO;
+
+ my $vars = $config->{VARIABLES};
+ $vars->{oldbugmove_user_is_mover} = \&_user_is_mover;
+}
+
+sub object_before_delete {
+ my ($self, $args) = @_;
+ my $object = $args->{'object'};
+ if ($object->isa('Bugzilla::Field::Choice::resolution')) {
+ if ($object->name eq 'MOVED') {
+ ThrowUserError('oldbugmove_no_delete_moved');
+ }
+ }
+}
+
+sub object_before_set {
+ my ($self, $args) = @_;
+ my ($object, $field) = @$args{qw(object field)};
+ if ($field eq 'resolution' and $object->isa('Bugzilla::Bug')) {
+ # Store the old value so that end_of_set can check it.
+ $object->{'_oldbugmove_old_resolution'} = $object->resolution;
+ }
+}
+
+sub object_end_of_set {
+ my ($self, $args) = @_;
+ my ($object, $field) = @$args{qw(object field)};
+ if ($field eq 'resolution' and $object->isa('Bugzilla::Bug')) {
+ my $old_value = delete $object->{'_oldbugmove_old_resolution'};
+ return if $old_value eq $object->resolution;
+ if ($object->resolution eq 'MOVED') {
+ $object->add_comment('', { type => CMT_MOVED_TO,
+ extra_data => Bugzilla->user->login });
+ }
+ }
+}
+
+sub object_end_of_set_all {
+ my ($self, $args) = @_;
+ my $object = $args->{'object'};
+
+ if ($object->isa('Bugzilla::Bug') and _bug_is_moving($object)) {
+ my $new_status = Bugzilla->params->{'duplicate_or_move_bug_status'};
+ $object->set_bug_status($new_status, { resolution => 'MOVED' });
+ }
+}
+
+sub object_validators {
+ my ($self, $args) = @_;
+ my ($class, $validators) = @$args{qw(class validators)};
+ if ($class->isa('Bugzilla::Comment')) {
+ my $extra_data_validator = $validators->{extra_data};
+ $validators->{extra_data} =
+ sub { _check_comment_extra_data($extra_data_validator, @_) };
+ }
+ elsif ($class->isa('Bugzilla::Bug')) {
+ my $reso_validator = $validators->{resolution};
+ $validators->{resolution} =
+ sub { _check_bug_resolution($reso_validator, @_) };
+ }
+}
+
+sub _check_bug_resolution {
+ my $original_validator = shift;
+ my ($invocant, $resolution) = @_;
+
+ if ($resolution eq 'MOVED' and !_bug_is_moving($invocant)) {
+ # MOVED has a special meaning and can only be used when
+ # really moving bugs to another installation.
+ ThrowUserError('oldbugmove_no_manual_move');
+ }
+
+ return $original_validator->(@_);
+}
+
+sub _check_comment_extra_data {
+ my $original_validator = shift;
+ my ($invocant, $extra_data, undef, $params) = @_;
+ my $type = blessed($invocant) ? $invocant->type : $params->{type};
+
+ if ($type == CMT_MOVED_TO) {
+ return Bugzilla::User->check($extra_data)->login;
+ }
+ return $original_validator->(@_);
+}
+
+sub bug_end_of_update {
+ my ($self, $args) = @_;
+ my ($bug, $old_bug, $changes) = @$args{qw(bug old_bug changes)};
+ if (defined $changes->{'resolution'}
+ and $changes->{'resolution'}->[1] eq 'MOVED')
+ {
+ $self->_move_bug($bug, $old_bug);
+ }
+}
+
+sub _move_bug {
+ my ($self, $bug, $old_bug) = @_;
+
+ my $dbh = Bugzilla->dbh;
+ my $template = Bugzilla->template;
+
+ _user_is_mover(Bugzilla->user)
+ or ThrowUserError("auth_failure", { action => 'move',
+ object => 'bugs' });
+
+ # Don't export the new status and resolution. We want the current
+ # ones.
+ local $Storable::forgive_me = 1;
+ my $export_me = dclone($bug);
+ $export_me->{bug_status} = $old_bug->bug_status;
+ delete $export_me->{status};
+ $export_me->{resolution} = $old_bug->resolution;
+
+ # Prepare and send all data about these bugs to the new database
+ my $to = Bugzilla->params->{'move-to-address'};
+ $to =~ s/@/\@/;
+ my $from = Bugzilla->params->{'mailfrom'};
+ $from =~ s/@/\@/;
+ my $msg = "To: $to\n";
+ $msg .= "From: Bugzilla <" . $from . ">\n";
+ $msg .= "Subject: Moving bug " . $bug->id . "\n\n";
+ my @fieldlist = (Bugzilla::Bug->fields, 'group', 'long_desc',
+ 'attachment', 'attachmentdata');
+ my %displayfields = map { $_ => 1 } @fieldlist;
+ my $vars = { bugs => [$export_me], displayfields => \%displayfields };
+ $template->process("bug/show.xml.tmpl", $vars, \$msg)
+ || ThrowTemplateError($template->error());
+ $msg .= "\n";
+ MessageToMTA($msg);
+}
+
+sub _bug_is_moving {
+ my $bug = shift;
+ my $oldbugmove = Bugzilla->input_params->{"oldbugmove_" . $bug->id};
+ return $oldbugmove ? 1 : 0;
+}
+
+sub _user_is_mover {
+ my $user = shift;
+
+ my @movers = map { trim($_) } split(',', Bugzilla->params->{'movers'});
+ return ($user->id and grep($_ eq $user->login, @movers)) ? 1 : 0;
+}
+
+__PACKAGE__->NAME;
diff --git a/extensions/OldBugMove/disabled b/extensions/OldBugMove/disabled
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/extensions/OldBugMove/disabled
diff --git a/extensions/OldBugMove/lib/Params.pm b/extensions/OldBugMove/lib/Params.pm
new file mode 100644
index 000000000..a8617e347
--- /dev/null
+++ b/extensions/OldBugMove/lib/Params.pm
@@ -0,0 +1,60 @@
+# -*- Mode: perl; indent-tabs-mode: nil -*-
+#
+# 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 Bugzilla Bug Tracking System.
+#
+# The Initial Developer of the Original Code is Netscape Communications
+# Corporation. Portions created by Netscape are
+# Copyright (C) 1998 Netscape Communications Corporation. All
+# Rights Reserved.
+#
+# Contributor(s): Terry Weissman <terry@mozilla.org>
+# Dawn Endico <endico@mozilla.org>
+# Dan Mosedale <dmose@mozilla.org>
+# Joe Robins <jmrobins@tgix.com>
+# Jacob Steenhagen <jake@bugzilla.org>
+# J. Paul Reed <preed@sigkill.com>
+# Bradley Baetz <bbaetz@student.usyd.edu.au>
+# Joseph Heenan <joseph@heenan.me.uk>
+# Erik Stambaugh <erik@dasbistro.com>
+# Frédéric Buclin <LpSolit@gmail.com>
+#
+
+package Bugzilla::Extension::OldBugMove::Params;
+
+use strict;
+
+use Bugzilla::Config::Common;
+
+our $sortkey = 700;
+
+use constant get_param_list => (
+ {
+ name => 'move-to-url',
+ type => 't',
+ default => ''
+ },
+
+ {
+ name => 'move-to-address',
+ type => 't',
+ default => 'bugzilla-import'
+ },
+
+ {
+ name => 'movers',
+ type => 't',
+ default => ''
+ },
+);
+
+1;
diff --git a/extensions/OldBugMove/template/en/default/admin/params/oldbugmove.html.tmpl b/extensions/OldBugMove/template/en/default/admin/params/oldbugmove.html.tmpl
new file mode 100644
index 000000000..ce588b168
--- /dev/null
+++ b/extensions/OldBugMove/template/en/default/admin/params/oldbugmove.html.tmpl
@@ -0,0 +1,40 @@
+[%# 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 Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Netscape Communications
+ # Corporation. Portions created by Netscape are
+ # Copyright (C) 1998 Netscape Communications Corporation. All
+ # Rights Reserved.
+ #
+ # Contributor(s): Dave Miller <justdave@bugzilla.org>
+ # Frédéric Buclin <LpSolit@gmail.com>
+ #%]
+[%
+ title = "$terms.Bug Moving"
+ desc = "Set up parameters to move $terms.bugs to/from another installation"
+%]
+
+[% param_descs = {
+
+ "move-to-url" =>
+ "The URL of the database we allow some of our $terms.bugs to"
+ _ " be moved to.",
+
+ "move-to-address" =>
+ "To move ${terms.bugs}, an email is sent to the target database."
+ _ " This is the email address that that database uses to listen"
+ _ " for incoming ${terms.bugs}.",
+
+ movers =>
+ "A list of people with permission to move $terms.bugs ",
+
+} %]
diff --git a/extensions/OldBugMove/template/en/default/hook/bug/edit-after_comment_textarea.html.tmpl b/extensions/OldBugMove/template/en/default/hook/bug/edit-after_comment_textarea.html.tmpl
new file mode 100644
index 000000000..71fe06590
--- /dev/null
+++ b/extensions/OldBugMove/template/en/default/hook/bug/edit-after_comment_textarea.html.tmpl
@@ -0,0 +1,27 @@
+[%# 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 Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Everything Solved, Inc.
+ # Portions created by the Initial Developer are Copyright (C) 2010
+ # the Initial Developer. All Rights Reserved.
+ #
+ # Contributor(s):
+ # Max Kanat-Alexander <mkanat@bugzilla.org>
+ #%]
+
+[% IF oldbugmove_user_is_mover(user) AND bug.resolution != 'MOVED' %]
+ <br>
+ <input type="submit" name="oldbugmove_[% bug.id FILTER html %]"
+ id="oldbugmove"
+ value="Move [% terms.Bug FILTER html %] to
+ [%= Param('move-to-url') FILTER html %]">
+[% END %]
diff --git a/extensions/OldBugMove/template/en/default/hook/bug/format_comment-type.txt.tmpl b/extensions/OldBugMove/template/en/default/hook/bug/format_comment-type.txt.tmpl
new file mode 100644
index 000000000..1ce8e369d
--- /dev/null
+++ b/extensions/OldBugMove/template/en/default/hook/bug/format_comment-type.txt.tmpl
@@ -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 Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Everything Solved, Inc.
+ # Portions created by the Initial Developer are Copyright (C) 2010
+ # the Initial Developer. All Rights Reserved.
+ #
+ # Contributor(s):
+ # Max Kanat-Alexander <mkanat@bugzilla.org>
+ #%]
+
+[% IF comment.type == constants.CMT_MOVED_TO %]
+[% comment.body %]
+
+[%+ terms.Bug %] moved to [% Param("move-to-url") %].
+If the move succeeded, [% comment.extra_data FILTER email %] will receive a mail
+containing the number of the new [% terms.bug %] in the other database.
+If all went well, please paste in a link to the new [% terms.bug %].
+Otherwise, reopen this [% terms.bug %].
+[% END %]
diff --git a/extensions/OldBugMove/template/en/default/hook/global/user-error-auth_failure_action.html.tmpl b/extensions/OldBugMove/template/en/default/hook/global/user-error-auth_failure_action.html.tmpl
new file mode 100644
index 000000000..58500976b
--- /dev/null
+++ b/extensions/OldBugMove/template/en/default/hook/global/user-error-auth_failure_action.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 the Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Everything Solved, Inc.
+ # Portions created by the Initial Developer are Copyright (C) 2010
+ # the Initial Developer. All Rights Reserved.
+ #
+ # Contributor(s):
+ # Max Kanat-Alexander <mkanat@bugzilla.org>
+ #%]
+
+[% IF action == "move" %]
+ move
+[% END %]
diff --git a/extensions/OldBugMove/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/OldBugMove/template/en/default/hook/global/user-error-errors.html.tmpl
new file mode 100644
index 000000000..935117780
--- /dev/null
+++ b/extensions/OldBugMove/template/en/default/hook/global/user-error-errors.html.tmpl
@@ -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 Bugzilla Bug Tracking System.
+ #
+ # The Initial Developer of the Original Code is Everything Solved, Inc.
+ # Portions created by the Initial Developer are Copyright (C) 2010
+ # the Initial Developer. All Rights Reserved.
+ #
+ # Contributor(s):
+ # Max Kanat-Alexander <mkanat@bugzilla.org>
+ #%]
+
+[% IF error == "oldbugmove_no_delete_moved" %]
+ As long as the OldBugMove extension is active, you cannot
+ delete the [%+ display_value("resolution", "MOVED") FILTER html %]
+ resolution.
+[% ELSIF error == "oldbugmove_no_manual_move" %]
+ You cannot set the resolution of [% terms.abug %] to
+ [%+ display_value("resolution", "MOVED") FILTER html %] without
+ moving the [% terms.bug %].
+[% END %]