合并用户的 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 个赞

我有一个具体案例需要帮助,类似案例见上文

我想合并两个用户账号,但存在以下情况:

  • 账号 #1 拥有用户希望保留的旧用户名。
  • 账号 #2 拥有用户的新邮箱。(用户无法访问账号 #1 的邮箱,因为那是机构邮箱。)

我能否使用“合并”界面将这两个账号合并,使合并后的账号保留旧用户名但使用新邮箱?

我认为无法通过管理员界面完成此操作,但可以通过额外步骤实现:

通过管理员界面合并
通过 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 覆盖邮箱”设置时,合并后的用户可能无法登录,除非从 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 个赞

你好。
合并后发现一个小问题:欢迎徽章在用户资料中显示了两次,就像用户第一次就获得了两次一样:slight_smile

4 个赞