]> git.ipfire.org Git - thirdparty/bugzilla.git/commitdiff
Bug 1507812 - merge_user.pl should not continue if the old user id has an account...
authordklawren <dklawren@users.noreply.github.com>
Fri, 8 Mar 2019 16:57:29 +0000 (11:57 -0500)
committerGitHub <noreply@github.com>
Fri, 8 Mar 2019 16:57:29 +0000 (11:57 -0500)
extensions/PhabBugz/Extension.pm
extensions/PhabBugz/template/en/default/hook/global/user-error-errors.html.tmpl
scripts/merge-users.pl

index 7adf0a3fd6ad54390e9cef2b5627a990e768e60b..d8d0dce392eec00cd608df31f91a0694ff9e1c43 100644 (file)
@@ -14,7 +14,9 @@ use warnings;
 use parent qw(Bugzilla::Extension);
 
 use Bugzilla::Constants;
+use Bugzilla::Error;
 use Bugzilla::Extension::PhabBugz::Constants;
+use Bugzilla::Extension::PhabBugz::Util qw(request);
 
 our $VERSION = '0.01';
 
@@ -95,4 +97,20 @@ sub install_filesystem {
   $files->{$scriptname} = {perms => Bugzilla::Install::Filesystem::WS_EXECUTE};
 }
 
+sub merge_users_before {
+  my ($self, $args) = @_;
+  my $old_id = $args->{old_id};
+  my $force  = $args->{force};
+
+  return if $force;
+
+  my $result = request('bugzilla.account.search', {ids => [$old_id]});
+
+  foreach my $user (@{$result->{result}}) {
+    next if !$user->{phid};
+    ThrowUserError('phabricator_merge_user_abort',
+      {user => Bugzilla::User->new({id => $old_id, cache => 1})});
+  }
+}
+
 __PACKAGE__->NAME;
index 0274f72ceb1e6c85e6bae073bb4d3e42d61a9996..cb6de5e7591e51fa6fd84eb3a1dfc736dfe71d09 100644 (file)
   [% title = "Unauthorized User" %]
   You do not have permission to use this endpoint.
 
+[% ELSIF error == "phabricator_merge_user_abort" %]
+  [% title = "Cannot Merge User" %]
+  ERROR: Cannot merge old user [% user.login FILTER html %] since old user
+  has a linked account in Phabricator and the user will no longer match the
+  account in [% terms.Bugzilla %]. User needs to create new user in Phabricator
+  and link it to the newer account in [% terms.Bugzilla %]. Then file a [% terms.bug %]
+  for a phabricator admin to fix the accounts in phabricator.
+  Instructions: https://mana.mozilla.org/wiki/display/EW/Phabricator+-+Renaming+a+user+account.
+  Once this is complete, re-run merge-users.pl using --force switch.
+
 [% END %]
index 9934e83435492649ec8af62f20661aaed02f736a..94f5251812d3b435420d0c0402cef696b5bf0185 100755 (executable)
@@ -45,11 +45,12 @@ use Pod::Usage;
 my $dbh = Bugzilla->dbh;
 
 # Display the help if called with --help or -?.
-my $help = 0;
-my $result = GetOptions("help|?" => \$help);
+# Force swicth can be used by extension code.
+my $help   = 0;
+my $force  = 0;
+my $result = GetOptions("help|?" => \$help, "force|f" => \$force);
 pod2usage(0) if $help;
 
-
 # Make sure accounts were specified on the command line and exist.
 my $old = $ARGV[0] || die "You must specify an old user account.\n";
 my $old_id;
@@ -151,7 +152,7 @@ $dbh->bz_start_transaction();
 
 # BMO - pre-work hook
 Bugzilla::Hook::process('merge_users_before',
-  {old_id => $old_id, new_id => $new_id});
+  {force => $force, old_id => $old_id, new_id => $new_id});
 
 # Delete old records from logincookies and tokens tables.
 $dbh->do('DELETE FROM logincookies WHERE userid = ?', undef, $old_id);
@@ -261,7 +262,7 @@ $user->derive_regexp_groups();
 
 # BMO - post-work hook
 Bugzilla::Hook::process('merge_users_after',
-  {old_id => $old_id, new_id => $new_id});
+  {force => $force, old_id => $old_id, new_id => $new_id});
 
 # Commit the transaction
 $dbh->bz_commit_transaction();