From: dklawren Date: Fri, 8 Mar 2019 16:57:29 +0000 (-0500) Subject: Bug 1507812 - merge_user.pl should not continue if the old user id has an account... X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=87ee0959f7f3219dd7fad7b0d5e77f8b1e8d96ea;p=thirdparty%2Fbugzilla.git Bug 1507812 - merge_user.pl should not continue if the old user id has an account in Phabricator --- diff --git a/extensions/PhabBugz/Extension.pm b/extensions/PhabBugz/Extension.pm index 7adf0a3fd..d8d0dce39 100644 --- a/extensions/PhabBugz/Extension.pm +++ b/extensions/PhabBugz/Extension.pm @@ -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; diff --git a/extensions/PhabBugz/template/en/default/hook/global/user-error-errors.html.tmpl b/extensions/PhabBugz/template/en/default/hook/global/user-error-errors.html.tmpl index 0274f72ce..cb6de5e75 100644 --- a/extensions/PhabBugz/template/en/default/hook/global/user-error-errors.html.tmpl +++ b/extensions/PhabBugz/template/en/default/hook/global/user-error-errors.html.tmpl @@ -39,4 +39,14 @@ [% 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 %] diff --git a/scripts/merge-users.pl b/scripts/merge-users.pl index 9934e8343..94f525181 100755 --- a/scripts/merge-users.pl +++ b/scripts/merge-users.pl @@ -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();