You can get access immediately to their primary_group_name, but it won’t provide you with all groups they have access to.
To get all groups, you might have to do a call to /u/username.json and read the groups property. That makes it a tad more difficult as now you are awaiting the response of a call before you can show the link.
Thanks! In this case it is their primary group, so that should make it easier, then. Would you mind helping me out with a snippet of example code, how I would use this? Here’s the code I want to make conditional. If the user is a member of ‘group1’, this button should display, otherwise not:
Actually, it would be nice for Discourse to add group-derived classes to the root body element.
This way makes it very easy to tailor the display according to the user. For example, if I have groups based on counties, I can easily include css that displays the country’s flag as a background.
Or each department can have a different color. And so on. Very very useful.
It exist already. For example, If a user’s primary group is customers then the body tag will have the CSS class primary-group-customers. And it will work only for primary group property.
But it should work for all groups. Just the primary group is very restrictive.
If you have all, I can have elaborate css to decide what format to use based on groups.
EDIT: Many groups are not primary. They are used just to restrict access for categories. Some are use simply for identification purposes, and these groups are primary candidates for formatting purposes. It is very unlikely that the primary group is all you need.
Actually, as of v2.2.0.beta9+29 .anon doesn’t work anymore. OTOH, .primary-group-patreons still works fine. Instead, what happens now for users who aren’t logged in is that they’re getting the “Regular member!” banner.
Did something change in Discourse? Anyone else seeing this?
I’m trying to do something with CSS (as a bandaid/painting with whiteout) since I have no “proper” way to do this.
I’m trying to hide all contents in a category from EVERYONE not in a specific group. While group permissions do the trick mostly, it doesn’t hide the contents from an admin. This is a problem with our board as the admin (me) should not see the contents of an executive group. (this is a business teams instance)
I know what and why this is a bandaid. Until the nature of things change with discourse access control, this is what I have to do.
I want the category contents invisible to the admin(s), but visable to the members of the a specific group:
The category name: secretary
The category id: 33
The group: secretary
Here’s my code that hides ALL within the category. It works to hide the content from the admin/(me).