Sync group membership with external list of email addresses

What would be the easiest way to do this?

An external script that runs nightly and uses Discourse’s API?

Or is there a plugin that exists already?

Thanks.

You are describing what is probably the worst solution to your problem. Can you take a step back and define the problem?

What’s maintaining the list? DiscourseConnect - Official Single-Sign-On for Discourse (sso) is a likely solution, though there could be others.

2 Likes

I love the bluntness of computer people :slight_smile:

I was considering trying out Creating a read-only mailing list mirror with a private mailing list and therefore a private Discourse category.

1 Like

What would be the best way? Or even a slightly better way? If people on the list prefer the forum’s private category then it’s a win for Discourse.

If you don’t have those users managed in some external application then you could do something like this:

  def load_csv(path)
    CSV.parse(File.read(path), headers: true)
  end

  def update_group
   g=Group.find(43) #whatever group ID yo uwant
   GroupUser.where(group_id: g.id).destroy_all
   user_emails=load_csv('/path/to/file')
    user_emails.each do |u|
      user = User.find_by_email(u['Email'])
      next unless user
      puts "found user #{uid}"
      GroupUser.find_or_create_by(group_id: g.id, user_id: user.id)
    end
  end

Just how is a whole nother issue. A plugin, perhaps.

Maybe a plugin that automatically adds a user to the group if they post in the category?

1 Like

Thanks for this.

The category would only be visible to members of the group so there would be a chicken and egg scenario here!

I’m fairly accustomed to PHP so think I could write a script that takes the email addresses from Mailman 2 (it has a Python script for that) and checks them against the Discourse user list, adding or removing Discourse users from the relevant group as appropriate. I know you said this is “probably the worst solution”…

I’ve not even set up the mailing list mirror yet, so these are just ideas so far.

1 Like

Yes, but I was thinking that you’d be importing data to the list some other way.

You could also make the group allow requests and have discourse handle that.

I hate php, so your solution is sounding worse! :joy:

But the discourse api is pretty easy to figure out, so I think your solution is sounding like the right one for you!

If mailman has hooks, you could have it make api calls when it updates the subscriber list.

1 Like

There’s a category setting called something like “… Mirrors a list” that might also be helpful.