`PermissionException` thrown when trying to change a page's template with PHP while impersonating Kirby

Hi all,

I have a PHP script in a route that should change a page’s template with the $page->changeTemplate('template') method that is inside a $kirby->impersonate() closure. Something like this:

$kirby = kirby();

//...

$kirby->impersonate('kirby', function () {			

	$podcast = page('balados/scene-nationale-du-son');

	$podcast = $podcast->changeTemplate('podcast');

	// ...
});

The changeTemplate() method throws a PermissionException even while impersonating Kirby. I had no permission problems with the createChild() method used in a different part of the same script.

Here’s the stack trace of the PermissionException:

[2021-03-24 15:57:58.454852] [error] Kirby\Exception\PermissionException: You are not allowed to change the template for "scene-nationale-du-son" in /shared/httpd/transistor/public/kirby/src/Cms/PageRules.php:228
Stack trace:
#0 /shared/httpd/transistor/public/kirby/src/Cms/PageActions.php(349): Kirby\Cms\PageRules::changeTemplate(Object(Kirby\Cms\Page), 'podcast')
#1 /shared/httpd/transistor/public/kirby/src/Cms/PageActions.php(311): Kirby\Cms\Page->commit('changeTemplate', Array, Object(Closure))
#2 /shared/httpd/transistor/public/site/plugins/transistor-helpers/src/TransistorFmApiHandler.php(144): Kirby\Cms\Page->changeTemplate('podcast')
#3 [internal function]: Kirby\Cms\App->TransistorFmApiHandler\{closure}(Object(Kirby\Cms\User))
#4 /shared/httpd/transistor/public/kirby/src/Cms/AppUsers.php(64): Closure->call(Object(Kirby\Cms\App), Object(Kirby\Cms\User))
#5 /shared/httpd/transistor/public/site/plugins/transistor-helpers/src/TransistorFmApiHandler.php(177): Kirby\Cms\App->impersonate('kirby', Object(Closure))
#6 /shared/httpd/transistor/public/site/config/config.php(72): TransistorFmApiHandler\TransistorFmApiHandler::saveShowsToDisk(Array)
#7 [internal function]: Kirby\Http\Route->{closure}('balados')
#8 /shared/httpd/transistor/public/kirby/src/Http/Router.php(107): Closure->call(Object(Kirby\Http\Route), 'balados')
#9 /shared/httpd/transistor/public/kirby/src/Cms/App.php(336): Kirby\Http\Router->call('balados', 'GET')
#10 /shared/httpd/transistor/public/kirby/src/Cms/App.php(1039): Kirby\Cms\App->call(NULL, NULL)
#11 /shared/httpd/transistor/public/index.php(5): Kirby\Cms\App->render()
#12 {main}

I tired checking the conditional that throws the error, but the permissions seem fine.

Any ideas?

What is the blueprint setting for that page? changeTemplate: false?

1 Like

It was unset, which means false. Seems like that was the problem!

Weird. I would expect that Kirby would have free reign to edit things at it pleases. If I wanted to impersonate an editor I wouldn’t have use Kirby.

No, that is not the case.