Merge Users Plugin

Github repository

With this plugin you can easily merge two users together.

Installation

Just add one line to your app.yml:

hooks:
  after_code:
    - exec:
        cd: $home/plugins
        cmd:
          - git clone https://github.com/discourse/docker_manager.git
          - git clone https://github.com/curiousdannii/discourse-merge-users.git

Then rebuild the container:

cd /var/discourse
sudo ./launcher rebuild app

See this topic for more on installing plugins.

28 Likes

Awesome! To clarify… does this replicate the rake task exactly? Eg Does the email address of the deleted user move to the secondary email of the retained user?

1 Like

It calls the same library that the rake task does, so yes the results are exactly the same.

Oh, except for one cool new feature, it sends a message to the target user once the merge is complete to let them know!

6 Likes

Nice! Can that message be optional? I do not always want to inform them.

3 Likes

Hmm, I’ll have to think about that. I feel like it should notify them, as it’s their account. If it’s important they not be notified for some reason, the rake task is still a good option. But if a lot of people do want it to be optional, it wouldn’t be too hard to change it.

3 Likes

Merging users has some very particular data protection implications, it’s probably safer to always notify.

3 Likes

It’s also not reversible so if you do it by accident… there’s no way to undo that.

6 Likes

Yep, another reason that it’s probably worth always explaining what happened.

4 Likes

That makes me think of a good enhancement I could make. It currently puts up a confirm dialog saying “Do you want to merge source into target?” But I could also make it show their avatar and display name as well, just in case someone thought they had the right username but would recognise through the avatar that they have the wrong one.

6 Likes

I think that is an excellent idea and also mention it is permanent!

6 Likes

I don’t diagree with what you are saying here. And I am sure it makes sense for other communities.

In my community I often have to do merges because people were invited as staged users, then they ended up joining using a different email address which creates a second account. In this case it is of no interest to the user and notifying them will just confuse them.

I also have a canned reply I use regularly to personally explain what I did when I do a merge like I have for many account related tasks. I don’t really need or want an automatic notification to help me with this.

I can continue using the rake task but other people on my team do not have shell access and it would be nice to be able to delegate this task to them using your plugin.

3 Likes

This plugin does use the standard text template system, so you could change the message it sends to your current canned reply. Would that work for you?

3 Likes

Not really - like I said, I don’t always send it and when I do I write it myself using the canned reply. We do not edit the default out of the box translations in discourse at all, and don’t want to start doing that now just for this task.

I guess for now I will just keep using the rake task, but I’d love to start doing it via the UI so I can delegate it to colleagues who don’t have shell access. My strong preference would be for your plugin to have an admin setting to disable this automatic message entirely.

2 Likes

Well as @codinghorror keeps liking your posts, I’ll take that as a sign that it would be okay to make the messages optional. But probably as a checkbox on the form rather than a setting. Or maybe both.

2 Likes

I like that, but I think I would go a bit further here.

I would display something along the lines of:

You are about to merge these accounts:

Avatar 1: Sam saffron1: 200 posts on 17 topics, account created 1st of June 2011
Avater 2: Sam saffron2: 100 posts on 11 topics, account created 1st of July 2017

This operation is permanent there is no way to unmerge accounts.

Are you sure you want to do this? Type: YES to confirm
[                                 ]
CONFIRM BUTTON

This is definitely going to be a core feature at some point, we just need to find the right time and have all the safeguards in place.

9 Likes

Hmm, I do like the look of that!

But I’m just using bootbox.confirm at the moment which is nowhere near that flexible. Any pointers on how I could create a custom dialog? Or an example from elsewhere in Discourse that I could look at?

You are going to need a modal for that it is not the easiest API in the world, but there are lots of examples in core (like modal/flag.hbs) and so on.

2 Likes

This is an excellent mockup :+1: but you should need to type the username to confirm the merge, otherwise you’ll just remember to type YES every time.

3 Likes

In my case, email address is an important aspect of mergers. So maybe this could be expanded to e.g.

Avatar 1: Sam saffron1 (sam@foo.com): 200 posts on 17 topics, account created 1st of June 2011
Avater 2: Sam saffron2 (sam@bar.com): 100 posts on 11 topics, account created 1st of July 2017

Perhaps overkill, but if we’re already talking about a modal it might be a nice addition here to be able to choose the username and email address to retain for the user, and which email address (if any) to be kept as secondary.

5 Likes

I don’t think we need all this info. I’m planning to have the username link to the account page, so if someone needs to double check they can, but the rest of it’s really there for a last ditch sanity check. Avatar, username, display name, and email would probably be most useful. (Though email views are meant to be logged… maybe just let them click through to the account page.)

Which user, or both? The admin already did have to type in the usernames before. I’m not opposed to this, but choosing only one feels kind of arbitrary when it’s a major operation that affects two people if it’s done mistakenly.