Mojo90
June 26, 2017, 2:05pm
1
I have the requirement that there are some users which only have to go to one page in the panel and are allowed to upload images there.
Out of the Permissions-Site it does not work for me. I tried sth like this:
<?php
return [
'name' => 'Fahrlehrer',
'default' => false,
'permissions' => [
'panel.file.upload' => function() {
return $this->target()->page()->template() === 'shop_fahrschueler';
}
]
];
?>
Try this:
<?php
return [
'name' => 'Fahrlehrer',
'default' => false,
'permissions' => [
'panel.page.update' => false,
'panel.page.read' => function() {
return $this->target()->page()->template() === 'shop_fahrschueler';
},
'panel.file.upload' => function() {
return $this->target()->page()->template() === 'shop_fahrschueler';
}
]
];
Mojo90
June 26, 2017, 2:27pm
3
Than it looks like this:
Could it be a problem that “shop_fahrschueler” is a sub-page of “shop”?
Here the corresponding blueprint of shop:
<?php if(!defined('KIRBY')) exit ?>
title: Shop
pages:
template:
- shop_category
- shop_fahrschueler
Yes, you then have to grant read access to the parent page as well.
Mojo90
June 26, 2017, 2:51pm
5
Yes now it works with this:
<?php
return [
'name' => 'Fahrlehrer',
'default' => false,
'permissions' => [
'panel.page.update' => false,
'panel.page.create' => false,
'panel.page.delete' => false,
'panel.page.url' => false,
'panel.page.visibility' => false,
'panel.page.read' => function() {
$check = false;
if($this->target()->page()->template() === 'shop'){
$check = true;
} else if($this->target()->page()->template() === 'shop_fahrschueler') {
$check = true;
}
return $check;
},
'panel.file.update' => false,
'panel.file.replace' => false,
'panel.file.delete' => false,
'panel.file.upload' => function() {
return $this->target()->page()->template() === 'shop_fahrschueler';
}
]
];
?>
But now I have one thing that is missing. Now the people can still change the template of a page. Is there an option here? Than I think the only thing what they could change is upload files to that specific page!
1 Like
Mojo90
June 26, 2017, 2:57pm
6
Managed it like so, think the most smartest way?
<?php
return [
'name' => 'Fahrlehrer',
'default' => false,
'permissions' => [
'*' => false,
'panel.access' => true,
'panel.widget.pages' => true,
'panel.page.read' => function() {
$check = false;
if($this->target()->page()->template() === 'shop'){
$check = true;
} else if($this->target()->page()->template() === 'shop_fahrschueler') {
$check = true;
}
return $check;
},
'panel.file.upload' => function() {
return $this->target()->page()->template() === 'shop_fahrschueler';
}
]
];
?>
This can be shortened anyway and also prohibit changing of templates.
<?php
return [
'name' => 'Fahrlehrer',
'default' => false,
'permissions' => [
'panel.page.*' => false,
'panel.page.read' => function() {
if($this->target()->page()->template() === 'shop' || $this->target()->page()->template() === 'shop_fahrschueler') return true;
},
'panel.file.upload' => function() {
return $this->target()->page()->template() === 'blog';
}
]
];
(Side note: don’t use a php closing tag in a php-only file)