ユーザーをマージするためのRakeタスク

If you’re using Wordpress as the authority for SSO what benefit is there to storing a second email in Discourse?

right-o. unless I store it in wordpress too for the same reasons. but I don’t know how to prevent this rake task from storing a secondary email when merging users.

If secondary emails are an issue can’t they just be removed?

「いいね!」 1

Yes, that is one easy solution. Is there a rake task someone can share to list all the users with secondary emails, and to delete their secondary emails?

That said, I’d prefer to see discourse evolve to take advantage of a cool new feature like secondary emails rather than have to find ways to work around it. Other people are likely to bump up against this issue too at some point and wonder why the email address is not updating in discourse when updated in wordpress.

I don’t think there’s a rake task, but you could do it from the rails console. There should be some example queries about secondary emails for data explorer and some sample .update_all code for other rails examples. It’ll take more time than I can spare here today. If you’re stuck and want to pay, my contact info is in my profile.

See Additional email address per user account support - #34 by zogstrip

Here’s what you’re looking for: Additional email address per user account support - #34 by zogstrip

「いいね!」 3

I’ve written a plugin which makes it easier to run this task:

「いいね!」 8

So, if you’re using SSO on your site is it not possible to complete the rake merge task? The fine folks over at Communiteq (formerly DiscourseHosting) say they get this error message:

ActiveRecord::RecordNotSaved: Failed to save the new associated primary_email
/var/www/discourse/app/services/user_merger.rb:359:in `delete_source_user'

This also causes issues when trying to use the plugin from @Dannii because it looks like his process is trying to do this step first.

Any suggested workarounds for merging users for SSO sites? What we have happen is that a person changes from one organization to another and so they get a new account through the SSO process (they have a new email), but since it is the same person, we’d like to be able to merge the accounts once they’ve established themselves at their new location.

Disable SSO, merge, then re-enable SSO?

Thanks, I gave it a shot (disable/merge/enable) but no luck. Maybe after disabling a restart is required? Which I’m assuming would mean I couldn’t login any longer since I’m an SSO user too.

I don’t get this. I use sso using the wp_discourse Wordpress plugin and have no problem running this rake task. I then delete the Wordpress user that got merged.

「いいね!」 3

特定のケースについてお手伝いが必要です。上記で言及された類似のケースを参照してください。

2 つのユーザーアカウントをマージしたいのですが、以下の条件があります。

  • アカウント #1 には、ユーザーが保持したい古いユーザー名があります。
  • アカウント #2 には、ユーザーの新しいメールアドレスがあります(アカウント #1 のメールにはアクセスできません。これは機関アカウントであるためです)。

「マージ」UI を使用して 2 つのアカウントを結合し、結果として古いユーザー名と新しいメールアドレスの両方を持つアカウントを作成することは可能でしょうか?

Admin経由ではそれは難しいと思いますが、追加の手順を踏むことで実現できます。

Admin経由でマージ
Railsコンソール経由でそのユーザーのメールアドレスを変更:

cd /var/discourse
./launcher enter app
rails c
UserEmail.find_by(email: "old@example.com").update(email: "new@example.com")
「いいね!」 7

マージ中に新しいメールアドレスが「セカンダリメールアドレス」として追加されました。これが私のカスタム SSO ソリューションとどのように連携するか、少し不安でした。そのため、まずこちらの手順に従ってセカンダリメールアドレスを削除し、その後、あなたの提案に従いました。

@omarfilip さん、ありがとうございます!

「いいね!」 7

この状況には何度か遭遇しています。ユーザーがマージされると、ソースユーザーのプライマリメールアドレスは、ターゲットユーザーのセカンダリメールアドレスになります。SSO が使用され、かつ sso overrides email 設定が有効になっている場合、セカンダリメールアドレスを Rails コンソールから削除しない限り、マージされたユーザーがログインできなくなる可能性があります。

このタスクに、ソースのプライマリメールアドレスからターゲットのセカンダリメールアドレスを設定しないというオプションを追加すべきではないかと考えています。

「いいね!」 10

あるいは、それらを交換するための便利な手段があるといいですね。

「いいね!」 9

このエラーが発生しています。何かご存知でしょうか?

cd /var/discourse
./launcher enter app

ここで停止してしまいます!

「いいね!」 1

ぼやけがあって判断が難しいですが、最初のユーザー名の前に開き引用符 ' があるか再確認していただけますか?コンソールがさらに入力待ちをしているように見えるため(これは開いた文字列を示している可能性があります)。

「いいね!」 10
> /var/www/discourse# rake users:merge['anon94132497','PavelCherenkovv'] --trace
** Invoke users:merge (first_time)
** Invoke environment (first_time)
** Execute environment
** Execute users:merge
rake aborted!
ArgumentError: ArgumentError
/var/www/discourse/app/services/post_owner_changer.rb:12:in `initialize'
/var/www/discourse/app/services/user_merger.rb:63:in `new'
/var/www/discourse/app/services/user_merger.rb:63:in `change_post_owner'
/var/www/discourse/app/services/user_merger.rb:51:in `block in move_posts'
/var/www/discourse/app/services/user_merger.rb:49:in `each'
/var/www/discourse/app/services/user_merger.rb:49:in `move_posts'
/var/www/discourse/app/services/user_merger.rb:13:in `merge!'
/var/www/discourse/lib/tasks/users.rake:50:in `block in <main>'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:279:in `block in execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:279:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:279:in `execute'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:219:in `block in invoke_with_call_chain'
/usr/local/lib/ruby/2.6.0/monitor.rb:235:in `mon_synchronize'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:199:in `invoke_with_call_chain'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/task.rb:188:in `invoke'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:160:in `invoke_task'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block (2 levels) in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `each'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:116:in `block in top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:125:in `run_with_threads'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:110:in `top_level'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:83:in `block in run'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:186:in `standard_exception_handling'
/var/www/discourse/vendor/bundle/ruby/2.6.0/gems/rake-13.0.1/lib/rake/application.rb:80:in `run'
bin/rake:13:in `<top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:63:in `kernel_load'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli/exec.rb:28:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:476:in `exec'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/command.rb:27:in `run'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/invocation.rb:127:in `invoke_command'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor.rb:399:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:30:in `dispatch'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/vendor/thor/lib/thor/base.rb:476:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/cli.rb:24:in `start'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:46:in `block in <top (required)>'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/lib/bundler/friendly_errors.rb:123:in `with_friendly_errors'
/usr/local/lib/ruby/gems/2.6.0/gems/bundler-2.1.4/exe/bundle:34:in `<top (required)>'
/usr/local/bin/bundle:23:in `load'
/usr/local/bin/bundle:23:in `<main>'
Tasks: TOP => users:merge

このエラーが発生しました。

「いいね!」 1

こんにちは。
マージ後に軽微なバグが見つかりました。ユーザープロフィールに「ようこそ」バッジが2回表示され、まるで初めて2回獲得したかのような状態になっています :slight_smile:

「いいね!」 4