User permissions templates and their child

Hello,

how to set the user permissions
only for the page ‘aktuell’ and their children

aktuell

news-overview
 news-years
  news

I tried that

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.user.*' => false,
    'panel.page.*' => false,


    'panel.page.read' => function() {
      return $this->target()->page()->template() === 'news-overview';
    },
    'panel.page.update' => function() {
      return $this->target()->page()->template() === 'news-overview';
    },
    'panel.page.delete' => function() {
      return $this->target()->page()->template() === 'news-overview';
    },
    'panel.page.create' => function() {
      return $this->target()->page()->template() === 'news-overview';
    }

	]
]


  ?>

greetings perry

I assume it doesn’t work like that, otherwise you probably wouldn’t ask :wink: But could you please provide us with some more information. What exactly is the result? What is it that does not work as expected?

yes sorry it doesn’t work

the result is:

the editor can read the page 'aktuell’
but not
create a subpage

how can i set the permission to
the editor can read, create und delete subpages and their children into the page ‘aktuell’

I think what you want is something like this:

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.user.*' => false,
    'panel.page.*' => false,


'panel.page.read' => function() {
  return $this->target()->page()->template() == 'blog' || $this->target()->page()->template() == 'article';
},
'panel.page.update' => function() {
  return $this->target()->page()->template() == 'article';
},
'panel.page.delete' => function() {
  return $this->target()->page()->template() == 'article';
},
'panel.page.create' => function() {
  return $this->target()->page()->template() == 'blog';
}

]
];

(This is based on the Starterkit, so you will have to adapt this to fit your template names.

The delete and update permissions must refer to the actual page the editor can edit, not the parent page.

Let me know if it works.

thank you @texnixe now it works

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.user.*' => false,
    'panel.page.*' => false,


'panel.page.read' => function() {
  return $this->target()->page()->template() == 'news-overview' || 
  $this->target()->page()->template() == 'news-years' || 
  $this->target()->page()->template() == 'news';
},

'panel.page.update' => function() {
  return $this->target()->page()->template() == 'news' || $this->target()->page()->template() == 'news-years' || $this->target()->page()->template() == 'news-overview';
},
'panel.page.delete' => function() {
  return $this->target()->page()->template() == 'news' || $this->target()->page()->template() == 'news-years' || $this->target()->page()->template() == 'news-overview';
},
'panel.page.create' => function() {
  return $this->target()->page()->template() == 'news' || $this->target()->page()->template() == 'news-years' || $this->target()->page()->template() == 'news-overview';
}

	]
]


  ?>

1 Like

@texnixe

if is possible to set permissions for a page by the panel
with the user-field

for example
the admin create the basic page structur and set with a selectfield [admin,editor,translator…]
who has the permission to edit the subpages

greetings perry

This should actually be possible, if you can define the permissions based on page title, like in the example in the docs, you might as well check for the value of any other page field.

I have tried this:

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.page.*' => false,
    'panel.page.update' => true,
    'panel.page.delete' => true,
    'panel.page.create' => true,




'panel.page.read' => function() {

//Version A
  if($this->target()->page()->title() == 'presse') {
        return true;
      }
//Version B
  return  $this->target()->page()->title() == 'presse';


}



	]
]


  ?>

What is the right version A or B ?
If I want to save changes, I get an error message,
Du darfst dies nicht tun in file: …
but the change is saved-

What am I doing wrong?

Greetings Perry

This should work:

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.page.update' => true,
    'panel.page.delete' => true,
    'panel.page.create' => true,
    'panel.page.read' => function() {

    //Version B
      return  $this->target()->page()->title() == 'Presse';
    }
  
	]
]

?>
1 Like

thank you @texnixe now it works without the error message.

Okay I now how to set permissions rules for templates or page titles,
but I do not understand how to do that with a loop.

I tried this:

blueprint

  roles:
    label: Who can edit?
    type: select
    options:
      admin: Admin
      editor: Editor

roles/editor.php


'panel.page.read' => function() 
{
  
  foreach($pages->index() as $child) 
  {
    

    if($child->roles() == 'editor')
    {
      //I do not know what I have to write here
       return
       $child->title() == 'galerie';

    }
    
  }
}

Is it the wrong way ?

Why do you need the loop? This should work:

'panel.page.read' => function() {

      return  $this->target()->page()->roles() == 'editor';
    }

(not tested)

yes it works, thank you @texnixe

<?php

// site/roles/editor.php
return [
  'name'        => 'Editor',
  'default'     => false,
  'permissions' => [
    '*'            => true,
    'panel.site.*' => true,
    'panel.page.update' => true,
    'panel.page.delete' => true,
    'panel.page.create' => true,


    'panel.page.read' => function() 
    {
      
      return  
      $this->target()->page()->roles() == 'editor'||
      $this->target()->page()->parent()->roles() == 'editor';

    }






	]
]



  ?>
1 Like