Perry
December 17, 2016, 9:01am
1
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
texnixe
December 17, 2016, 9:14am
2
I assume it doesn’t work like that, otherwise you probably wouldn’t ask But could you please provide us with some more information. What exactly is the result? What is it that does not work as expected?
Perry
December 17, 2016, 9:35am
3
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’
texnixe
December 17, 2016, 12:45pm
4
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.
Perry
December 17, 2016, 2:19pm
5
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
Perry
December 18, 2016, 5:19pm
6
@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
texnixe
December 18, 2016, 5:53pm
7
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.
Perry
December 26, 2016, 7:12pm
8
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
texnixe
December 27, 2016, 12:41am
9
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
Perry
December 27, 2016, 8:26am
10
thank you @texnixe now it works without the error message.
Perry
December 28, 2016, 2:46pm
11
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';
}
}
}
texnixe
December 29, 2016, 8:02pm
13
Why do you need the loop? This should work:
'panel.page.read' => function() {
return $this->target()->page()->roles() == 'editor';
}
(not tested)
Perry
December 30, 2016, 8:57am
14
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