How to add all members in a new group?

Hello,

I would like to add all members in a new group, but when I try to copy paste a big list of username separated by a comma, I got an error.

It works when I try to import 100, but I have 40K members to add…

In the past it was possible to import up to 10K.

Any ideas ?

1 Like

Yea, I’m not sure the UI bulk add likes thousands of users. I think you can do it by creating a new group then using rails console to add trust_level: 0 users to that group. If you decide to go this route, be sure to backup first.

2 Likes

Why? What problem is this solving? Are you planning to later remove some of them? Why not just use trust_level_0 or trust_level_1? It’s lkely that whatever you are trying to do, adding all users to a group is not a good way to solve the problem.

You can do it from rails. I think this would work.

group=Group.find_by_name('my_group')
User.all.each do |user|
  GroupUser.create!(user_id: user.id, group_id: group.id)
end

I wrote a plugin that might help, though it’s not well tested and someone who tried it had trouble. If you’ve got a budget or are brave, you can contact me.

3 Likes

Yea I just use Trust_level_0 anytime I need to target the all members demographic.

1 Like

I would like to mention in a topic (and notify by email) all the members. Will it work with the Trust_level_0 level group ? Ideally I would prefer create a new group to custom the group name.

Maybe just have an announcements category and have everyone set to watch that category?

You can add everyone from rails like I suggested, but that’s not going to add new users.

Maybe look at the automation plugin and group membership through badges. Looks like you could create a custom badge that would add users with that badge to the group: Discourse Automation

3 Likes

If you have more than 100 users, you will have to change the max users notified per group mention setting.

2 Likes

ah yes, good point! thanks, I forgot about that setting. :slight_smile:

1 Like

The maximum number of users that you can add at one time to a group’s Add Users form is 1000. Looking at the code, it seems that you should get an error message similar to this if you attempt to add more:

“Maximum 1000 users can be added at once.”

There has to be some kind of limit, otherwise Discourse risks throwing an unhandled error. To get around the limit, I like the Automation Plugin approach that Jay suggested.

2 Likes

Why not use encapsulated interface group.add(user)? Wouldn’t there be potential problems with directly manipulating ActiveRecords in this way?

1 Like

I’m pretty sure this is the best (and simplest) solution for @kam44’s use-case.

But it is very good having knowing how to add folk to a group from the Rails console: this will come in handy for merging large groups, which I’ve had to do on occasion!

2 Likes

Why not indeed? Not sure why I didn’t see that when I went looking a while back.

It’s not dangerous to call active record stuff. It enforces the rules it needs to.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.