I’d like be able to restrict access to the content of entries, served by a common template, subject to the user group of the logged in user.
For example:
- There is a template T
- User U is a member of group G
- Users V and W are members of group H
- Entry A, served by template T, is accessible by group G, and therefore only by user U
- Entry B, also served by template T, is accessible by group H, and therefore only by users V and W
Is this possible with Craft out of the box? Or does it require custom plugins?
I’ve done this kind of thing in ExpressionEngine using its ZooVisitor add-on, but this is my first foray into user restricted access to content with Craft.
If a sticking point is the single template, could it be done with a template per user group?
I'd be grateful if someone could point me in the right direction, as I can’t quite see the wood for the trees on this scope in the Docs.
Update:
I infer from https://craftcms.com/docs/templating/usermodel I can…
{% if currentUser.isInGroup(group) %} {# do something… #} {% endif %}
So I guess I just need a way to feed entry specific stuff into the conditional.
Or more ideally, dynamically write the conditional as an outcome of creating a new entry that has user group requirements assigned to it. Though that sounds a bit tricky.