vikaspotluri123 / discourse-on-ghost

Add Ghost-based SSO to Discourse
https://github.vikaspotluri.me/discourse-on-ghost
MIT License
24 stars 3 forks source link

[feature] Sync groups with labels instead of plans? #30

Open o-simardcasanova opened 1 year ago

o-simardcasanova commented 1 year ago

The problem I'm trying to solve

First of all, thank you for this software! It's great, and it fills an important need in the Ghost ecosystem.

I'm currently running a Ghost-powered newsletter (let's call it A), and I'm planning to launch a second one soon (let's call it B). My plan is to host both of their communities in the same Discourse instance. As far as I understand, DoG can only authenticate Discourse members against one Ghost instance. I'm assuming building support in DoG for multiple Ghost instances would be a lot of work.

A workaround would be for me to host a third Ghost instance (let's call it C) that I would solely use as the source of trust for Discourse. I would use Zapier to sync members and their status. Members would get labels in C based on their membership access in A and B, and would use C to log in Discourse.

Feature request

I'm wondering how easy it would be for DoG to use labels instead of (or in addition to?) membership tiers to sync members with groups in Discourse? If a member has the label A_paid, it would be added to the group A_paid in Discourse.

Switching from membership tiers to labels could be an option to set in the configuration file, with the default value being the current behavior (membership tiers).

Alternatives

For what I understand, with a bit of extra code it seems possible to sync groups with user roles in WordPress. In this scenario, C is a WordPress instance with the Discourse plugin to offer SSO between WordPress and Discourse.

Additional context

If something isn't clear, of if you need more details/explanations, do not hesitate. And once again, thank you for this software!

vikaspotluri123 commented 1 year ago

Hey @simardcasanova 👋🏾

You're definitely right that DoG is designed to work with one Ghost instance! Fallback strategies to support multiple instances would be crazy 😁

Theoretically, it should be possible for DoG to pass labels to Discourse.

I'm not sure when I can get to it, so I'll include the (non-exhaustive) list of considerations/changes to be made if someone wants to add support.

  1. New environment variable - DOG_GHOST_LABELS - optional, comma-separated list of labels to be processed (meaning every label that's supported is opt-in)
  2. DiscourseSyncService#syncTiersToGroups needs to be renamed and updated to support optional labels
  3. If Ghost's /members/api/member endpoint doesn't return labels, session mode will have to fetch member labels (if needed) using the Admin API and augment the response
  4. GhostService#getMemberByEmail needs to include member labels in the response (if required)
  5. SSOController#convertGhostMemberToDiscourseSSO needs to map labels to Discourse group slugs (if there are any labels)
  6. The getSlug + getNiceName in the Discourse Service need to support both labels and tiers