Granular group-based permissions for anonymous and logged in users

Heya Martin :wave:

i opened a quick PR to add those two classes (anonymous_users and logged_in_users) to the theme component, but i don’t think it is really necessary (see my note below).

i haven’t really tested it (lol) but i think it’s pretty straight-forward. the code just checks if the current user exists, and if they do, then they are a member of logged_in_users, and if not, then they are anonymous_users. :grin:

note: you can do this sort of anon/logged in css without that component. i’m pretty sure Discourse automatically adds .anon anyways, so the css for anonymous vs logged in can be achieved without installing the component, but the PR simply adds code to use the new group conventions.

for example, something like this:

// for anonymous users
@if $hide_this_from_anon {
  html.anon {
    .something {
      display: none;
    }
  }
}

// for logged-in users
@if $hide_this_from_logged_in_users {
  html:not(.anon) {
   .something {
      display: none;
    }
  }
}
2 Likes