Ho un sito di membership (anch’esso in Rails) e sto utilizzando l’API di Discourse per creare e popolare automaticamente gruppi di forum riservati per tutti i miei gruppi di utenti. Funziona benissimo; sto persino assegnando a ciascun gruppo un post wiki come punto di partenza. (Ho pubblicato il mio codice.)
Ora mi sono imbattuto nel problema che a volte devo sincronizzare manualmente l’iscrizione ai gruppi, ad esempio quando unisco gruppi sul mio sito o quando il coordinatore ha accidentalmente cancellato/aggiunto persone tramite il forum. A questo scopo, voglio eliminare TUTTI i membri del gruppo Discourse e poi riaggiungere quelli che dovrebbero farne parte.
Primo problema: l’API di Discourse non sembra prevedere un DELETE ALL per i membri del gruppo, quindi devo specificare i nomi di tutti coloro che devono essere eliminati.
Secondo problema: non riesco effettivamente a recuperare l’iscrizione corrente del gruppo Discourse, perché per qualche motivo mi chiede il NOME del gruppo invece dell’ID. Sul mio sito ho memorizzato solo l’ID del gruppo, poiché è quello che Discourse utilizza per le relative richieste PUT/POST/DELETE.
Terzo problema: dovrebbe essere ovvio, ma non vedo un modo per recuperare il nome del gruppo fornendo il suo ID, a meno che non voglia recuperare tutti i 200+ gruppi e iterare su di essi fino a trovarne uno il cui ID corrisponda. Sembra un lavoro eccessivo e contraddice anche le convenzioni di Rails.
Cosa mi sta sfuggendo?
EDIT: @codinghorror è stato davvero utile l’ultima volta - hai qualche idea ora?
You seem to be right on this – you cannot access group resources with the ID number, only the name.
The ID referenced here is not an ID, but the name, per
It probably makes sense to refactor the /g/<group-name> route to match how we now handle topics and categories. Something like /g/<group-name>/<id> or /g/patrons/41 and allow /g/41 to function the same way.
Until we fix that up, though, it seems the only way to accomplish what you’re looking for is:
Storing the group name alongside the id
Hitting g/<group-name>/members.json with a GET request to get the members
Loop through those to delete each so you can re-sync.
This is an awesome problem to be looking into. Thanks for raising it, @Judith! Groups are so powerful and have so much promise! I noticed this issue recently as well, when looking at maintaining group membership from wordpress. It would be pretty neat to be able to automagically add/remove people from groups for country and region of the world they say they are based in, languages they speak, themes they are interested in, etc, when they sign up and update their profiles in wordpress.
@justin’s suggestion of storing both group name and group ID is a good one and I’ll pass it on to the folks working on this integration now.
One feature I’d also love to see added to the UI is the ability for admins or group owners to bulk remove all members from a group, and re-add them. This would allow them to reset their group memberships manually from time to time based on exports from wordpress, even if they don’t have an automated systme in place to add/remove people from groups as they update their profiles in wordpress.
I recommend using SSO between your main site and Discourse. That way you get group membership handling for free, and will have a sync_sso endpoint to update the membership in a straightforward way.
At first I was only using SSO, but then I ran into the problem that it only updates group membership when people log in. In the case of people not being re-elected, or otherwise losing the right to access a group, or gaining the right to access a group (and should receive email notifications for messages in the restricted group subforum), I need to add/remove them via the API.
The sync_sso exists to address this exact problem! You can trigger what is effectively a “virtual” sso login anytime a membership change to fully sync up a user.