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.
The discussion revolves around syncing group membership with an external list of email addresses. Jonathan5 initially asks about the easiest way to achieve this, suggesting an external script or a plugin.
pfaffman responds by asking for a clearer definition of the problem and suggests exploring existing solutions, such as DiscourseConnect.
Jonathan5 shares a potential approach using a private mailing list and a private Discourse category, while pfaffman provides a code snippet for updating group membership based on a CSV file.
pfaffman also suggests a plugin that automatically adds users to a group based on their activity in a category. However, Jonathan5 points out the potential chicken-and-egg scenario with this approach.
The conversation concludes with [pfaffman](/t/-/190552/7, /t/-/190552/8, /t/-/190552/9) suggesting alternative approaches, such as importing data to the list, using Discourse’s API, or leveraging Mailman hooks. Additionally, pfaffman mentions a category setting called “… Mirrors a list” that might be helpful.
Overall, the discussion explores various ways to sync group membership with an external list of email addresses, with Jonathan5 ultimately considering a script-based solution using Discourse’s API.
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.
I love the bluntness of computer people ![]()
I was considering trying out Mirroring a read-only mailing list in Discourse with a private mailing list and therefore a private Discourse category.
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?
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.
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! ![]()
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.
There’s a category setting called something like “… Mirrors a list” that might also be helpful.