User role permissions… adding tags?

Hi,
I’m new to Kirby; couple of week of using it and it’s great :slight_smile:

I’m building a site which has different front end user(client) restricted areas. I’ve set up restricted areas with user roles, no problem. So user ‘client’ has access …

<?php if (($user = $kirby->user()) && $user->role()->id() === 'client'): ?>
This visible for clients with the role client.
<?php endif ?>

I’m probably missing something obvious. Is there any way of extending the role ‘client’ with, for example, tags? So the user ‘client’ can be allocated access to different restricted areas depending on their tag?

So, User1 with the role ‘client’ has a tag ‘area1’ and can have access to area1. User2 also has the role ‘client’ and has tags ‘area1’ and ‘area2’ so can have access to ‘area1’ and ‘area2’.

Then at a later date, User1 could also be given the tag ‘area2’

Hope this makes sense, and thanks in advance.

Yes, you can do that by assigning fields to users in your client blueprint where you can set such tags. I assume you have a setup where users cannot change their own settings? Then this should work well and you would only have to extend your if statements.

That’s great, thank you for your quick response.
I’ve setup so users cannot change their own settings with the following blueprint

title: Client
permissions:
  access:
    panel: false

tags:
  type: tags
  label: Tags
  options:
    - Retreat
    - School
    - Podcast
    - Cards

I think I should be doing something like this, but obviously not as I get an error …

<?php 
  $user = $kirby->user();
$client = $user->role()->id('client'); 
?>

<?php if ($client->tags()->options() === 'Retreat'): ?>
	Displays content for option retreat.	
<?php endif ?>

Thanks again for your help.

<?php
$user = $kirby->user();
if ($user && ($user->role()->name() === 'client') && in_array('Retreat', $user->tags()->split())) {
  // do stuff
}
1 Like

Brilliant, thank you … so much to learn :slight_smile: