Creating thousands of invitations in bulk

I suppose the answer is “blast the API with thousands of requests” but I was hoping there is something smarter.

Scenario: we built a community site for a large Co-Op. There are 15k+ members, probably 95% of them will never open a user and 4% more will create a user but never use it. Creating a single link for 15K invitations opens up the site for abuse, so what I want to do is create some 16k invitation links, each with only one invitation, and the mail templating tool will take care of stitching them. the only catch is the invitation link creation. I want to seperate the systems for privacy so I won’t be feeding the 15k+ addresses to discourse, so the discourse server will not be carrying the entire list of emails, just the list of anonymous invite links.

If you think that your storing addresses in Discourse is more dangerous than wherever else you’re storing them is a privacy concern, you’ll need to create them. If you don’t like the API, you could do it from rails:

 i=Invite.generate(user, skip_email: true, max_redemptions_allowed: 1)

Gives you an invite key.

"/invites/#{i.invite_key}"

is the URL. You could do something to write them all to a file.

4 Likes

That’s what I thought, still need to iterate in a loop :slight_smile:
ok, thanks!

1 Like

ok, I was really naiive. I made the curl line, and thought I’d just run in 16k times, but after a minute I got rate limited by my own discourse :slight_smile: :man_facepalming:

so, as a rails newbie, I need to open a shell in the discourse container, enter irb and do what actually?

Have you tried using Bulk Invites?

That would have been my go-to, naturally, only I don’t have the list of emails in advance. This is a site for a credit union, so the management can’t just hand me over a list 15,500 emails and risk a privacy disaster (and I don’t want to take the risk on myself). so I have to create 16,000 links with a single redemption in each, and they will stitch it in their email cannon. I hope it gets better later.

1 Like

I’m also guessing there’s no SSO auth that could be used.

In that case what @pfaffman suggested is the way to go.

Something like

user = User.find_by(username: 'system')
16000.times do
  i = Invite.generate(user, skip_email: true, max_redemptions_allowed: 1)
  puts "/invites/#{i.invite_key}"
  # write "/invites/#{i.invite_key}" to file
end

Would do. Start off with loops of 1 or 2 until you get working as you intend.

A lazy but OK way of doing this would be to just print them all (puts) and log your terminal session :smiley:

2 Likes

you know what, I don’t want to start bothering anyone to teach me RoR over a forum thing. I see that adding a 1 second delay between API calls I don’t get a speed ticket, so this first run will just be a slow run.

The API key was created for the “system” user, so all invitations are not showing up on my user’s manament screens. I’ll now set on a quest to see the state of the total invitations on the server without having to log in as “system”, if that is even possible.

Thanks for now, I hope I’ll have more inteligent and clever questions next time :slight_smile:

It’s pretty easy to login as system, if you’re an marked as a “developer” (emails provided when building the forum as default admins) of the forum. You can just open @system’s user page, select Admin, scroll all the way down, and click Impersonate.

1 Like

oh duh… I just never scrolled that low :slight_smile: very cool. I have used Discourse as a user on different sites for years, I just missed a few basic nuances as a manager of one…