لدي موقع عضوية (مبني أيضًا باستخدام Rails) وأستخدم واجهة برمجة تطبيقات Discourse لإنشاء مجموعات منتديات مقيدة وملؤها تلقائيًا لجميع مجموعات المستخدمين الخاصة بي. هذا يعمل بشكل رائع؛ بل إنني أقوم حتى بتعيين منشور ويكي لكل مجموعة كبداية. (لقد نشرت الكود الخاص بي.)
الآن واجهت مشكلة تتمثل في أنني أحتاج أحيانًا إلى مزامنة عضوية المجموعة يدويًا، على سبيل المثال عند دمج المجموعات على موقعي أو عندما يقوم المنسق بحذف/إضافة أشخاص عن طريق الخطأ عبر المنتدى. لهذا الغرض، أريد حذف جميع أعضاء مجموعة Discourse ثم إعادة إضافة أولئك الذين يجب أن يكونوا فيها.
المشكلة الأولى: لا يبدو أن واجهة برمجة تطبيقات Discourse تتضمن أمرًا لحذف جميع الأعضاء دفعة واحدة، لذا يجب علي تحديد أسماء جميع الأشخاص الذين سيتم حذفهم.
المشكلة الثانية: لا يمكنني فعليًا استرجاع العضوية الحالية لمجموعة Discourse، لأن السبب غير معروف يجعلها تطلب مني اسم المجموعة بدلاً من معرفها (ID). لقد قمت بتخزين معرف المجموعة فقط على موقعي، لأن هذا هو ما تستخدمه Discourse لطلبات PUT/POST/DELETE ذات الصلة.
المشكلة الثالثة: يجب أن يكون الأمر واضحًا، لكنني لا أرى طريقة لاسترجاع اسم المجموعة عن طريق تزويدها بمعرفها (ID)، إلا إذا أردت استرجاع جميع المجموعات الـ 200+ أو أكثر والتدقيق فيها واحدة تلو الأخرى حتى أجد واحدة يتطابق معرفها. هذا يبدو قدرًا هائلاً من المتاعب كما أنه يتعارض مع تقاليد Rails.
ما الذي أفتقده؟
تعديل: كان @codinghorror مفيدًا للغاية في المرة السابقة - هل لديك أي أفكار الآن؟
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.