These commands have become an important and handy part of my workflow to bring back defunct users who have become unreachable, or to invite people who attend or apply for our events to join our community. Often there is a need to change the email address of the existing account, while retaining the correspondence with a new, staged user.
The answer for now seems to be to merge the user, delete the secondary email address of the remaining user using @gerhard’s rails commands, then change the email address via the web interface. (in my case it’s via wordpress SSO). Presto, done. But it’s three commands involving some copy pasting and is a bit time consuming.
Some suggestions follow. Curious to hear reactions.
How about a users:swapemail command to run before the merge?
Add ability to edit secondary email addresses via the admin UI?
I have SSO on my site so can’t use this, but for those who don’t it would be useful to be able to edit the primary and secondary email addresses directly via the user admin.
Add ability to update secondary email via SSO?
This might already be possible via API, but support for a secondary email field would need to be added to the SSO provider, in my case wordpress.
Move primary email to secondary when primary email is changed?
Perhaps a simpler, more sustainable long-term solution that doesn’t require alot of other changes would be to simply change it so when a user or admin (via web or SSO) changes the primary email, it moves the old email to the secondary email field first. This could be enabled with an admin site setting.
Any ideas on how to proceed? I’ve got SSO enabled, and am trying to merge the non-sso user into the SSO user. I have a few accounts which existed prior to enabling SSO on the forum.
Ah, thanks! Quotes break it… I originally tried no spaces, and no quotes, but somehow missed no quotes and no spaces…
So, now when I run this I encounter the following exception, PostsExistError. This seems a bit odd to me, since isn’t goal to move all posts? I also ran the change ownership task for good measure and I got the same result. The admin page says this user has “-6” posts created, and none listed on the user replies view.
Edit: Well, I went into the console and just updated the owner of 5 posts that seems to be assigned to blob’s account. Not sure what happened, but after that the merge was successful.
I’m running into trouble with this command and my SSO setup, which appears to fail silently if a user changes their email address to an address that exists already in the secondary email field. The email address changes in wordpress and all appears to be well, but it does not change in discourse.
The primary email address is not an issue, because if someone tries to change their email address to an address that already exists in wordpress, it doesn’t let them.
Does anyone have any suggestions? Is it possible to disable the secondary email address field, or to have the API ignore it or use it better? E.g. if the email address exists as secondary, just move what was primary to secondary and move what was secondary to primary?
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.
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.
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.
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.
During the merge the new email was added a Secondary Email. I wasn’t quite sure how this might interface with my custom SSO solution. So I removed the secondary email first (following these steps), and then followed your suggestion.