Categories access based on custom fields

AI-generated summary

In a discussion about granting category access based on custom user fields, Nicolas_Goutaland asked if Discourse has a built-in feature to restrict categories using metadata like company or department. He noted that creating groups for every metadata value would be cumbersome. Falco clarified that no built-in method exists but suggested two workarounds: using a script to sync groups via the API or passing group memberships directly through the SSO payload. Nicolas_Goutaland sought clarification on the SSO approach, confirming whether this requires pre-creating groups, assigning them to categories, and then updating membership via add_groups or remove_groups in the SSO payload. Falco confirmed this process is correct and provided a link to the relevant Discourse commit detailing the SSO group parameters. Nicolas_Goutaland concluded the thread by thanking Falco for the guidance.

Hi,
Thanks for your amazing work. Discourse is a very great forum.

Long story :
We have a mobile application were users are required to login. Onced logged, they may access to a forum, and are automatically logged in throught SSO. If user do not exists on discourse, it will be created, else, its profile will be updated with current user data. We have several special fields that describe our users, such as company, department, etc…
We are transfering them to discourse.

That was the easy part, now, we want to grant access to forum categories based on these metadata. If there a way to achieve that ? We may create groups for each metadata value, but it will be a mess to configure. So, is there something like that in discourse ? Should we develop a plugin allowing us to determine categories access based on users custom fields ?

TLDR : I want to know if there is a built-in way to grant categories access based on user custom fields.

Thanks for your help.

Regards

1 Mi Piace

No, but you can:

  • Create a simple script that reads from your database and setup all the groups on Discourse using the API

  • Pass group membership along on the SSO payload.

SSO is easier, the only problem is that membership is only updated on login.

1 Mi Piace

Can you tell me more about group membership on SSO ?
This means that I have to create group first, then affect groups to categories and finally, through SSO Payload, add groups information (add_groups / remove_groups?

1 Mi Piace

Exactly!

Groups SSO info are here:

https://github.com/discourse/discourse/commit/3d76ce14219a168bdf85769c5474420951c14253

3 Mi Piace

Thanks a lot for your help.