Show some pages and subpages in panel with permissions (always hide subpages?)


#1

I need hide some pages for ‘Editor’ role. Ok, I achive this with:

'panel.page.read' => function() {
	if($this->target()->page()->template() === 'noticias' ||
	   $this->target()->page()->template() === 'grupos') {
		return true;
	};
}

In this way, I show only the pages with template ‘noticias’ or ‘grupos’. The problem is that I can’t show the childrens/subpages of these pages:

'panel.page.read' => function() {
	if($this->target()->page()->template() === 'noticias' ||
	   $this->target()->page()->template() === 'noticia' || //This is the template for pages of main page 'noticias'
	   $this->target()->page()->template() === 'grupos' ||
	   $this->target()->page()->template() === 'grupo') { //This is the template for pages of main page 'grupos'
		return true;
	};
}

All subpages are hidden, avoid create new subpages… (There are a lot of subpages for this pages)

imagen

Blueprint for ‘noticias’ is:

title: Noticias
options: 
	status: false
	url: false
	delete: false
pages:
	template: noticia
	num:
		mode: date
		field: fecha
		display: d/m/Y
	sort: flip
files: false

and Blueprint for ‘grupos’ is:

title: Grupos
pages:
	template: grupo
	num: zero
files: false
options: 
	template: false  
	status: false

I try diferents codes with php, and nothing. Can you help me, please?


#2

I tested your code in a Starterkit with blog/articles and projects/project instead of your blueprint names and it works as it should. What happens if you create a new page, does this not show up, either?

Do the subpages show up for the admin user?


#3

For the admin user all is ok. All pages and subpages are visible and editables.

I need that editor user can’t add new pages (the rest of pages don’t have subpages). The only thing that editor could be do is add/delete/edit subpages of ‘noticias’ and ‘grupos’.

I tested again. User editor can create a new page if the template is ‘noticias’ or ‘grupos’ (This new page is visible in panel… I check this later, because i need that he can’t do it. Now, all fields are readonly). If the template is different, he can’t create a new page.

imagen

Now, If user editor tries to create a new subpage in any of these pages, he can’t do it. Show the message " Error. You are not allowed to do this). Really, this new subpage has been created, but it’s hidden too.

This is my editor.php:

<?php
	return [
		'name'        => 'Editor',
		'default'     => false,
		'permissions' => [
			'*'                 => true,
			'panel.user.*'      => false,
			'panel.user.read'   => true,
			'panel.user.update' => function() {
				return $this->user()->is($this->target()->user());
			},
			'panel.page.url'	=> false,
			'panel.page.visibility' => false,
			'panel.page.template'	=> false,
			'panel.page.read' => function() {
				if($this->target()->page()->template() === 'noticias' ||
				   $this->target()->page()->template() === 'noticia' || //This is the template for pages of main page 'noticias'
				   $this->target()->page()->template() === 'grupos' ||
				   $this->target()->page()->template() === 'grupo') { //This is the template for pages of main page 'grupos'
					return true;
				};
			}
		]
	];

I try using only ‘panel.page.read’ but, nothing, the same problem.


#4

I’m missing something. It works well in Starterkit, but I don’t get it. :confounded:


#5

Hi! Solved!

I forgot to add template /noticia.php and template / grupo.php

First time with Kirby, sorry !!

Thanks a lot!