I have a page setup where the user should not be able to edit the names of image-files, my blueprint looks like this:
File-Blueprint
title: Artist Image
accept: image/png, image/jpeg, image/gif
options:
changeName: false
However, when the user uploads a file i want to move it to a different directory and rename it in a hook. i am impersonating as ‘kirby’ to override the permissions of the blueprint:
'file.create:after' => function($file) {
// bail out if not a virtual-page
if(!method_exists($file->parent(), 'isVirtualPage')) return true;
$fileSlug = $file->parent()->intendedTemplate() . '_' . $file->parent()->slug();
// add page-slug to filename for retrieval
kirby()->impersonate('kirby', function () use($file, $fileSlug) {
$newFile = $file->changeName($fileSlug . VP_FILENAME_DELIMITER . $file->name() , false);
// copy uploaded file to media-page
$newFile->copy(site()->find(option('brauchbarkeit.virtual-page.mediaPageSlug')));
$newFile->delete();
});
// delete unused directory that was created during upload
$dir = realpath($file->parent()->root());
if (is_dir($dir) && Dir::isEmpty($dir)) {
Dir::remove($dir);
}
}
However i keep getting the “You are not allowed to change the name of XYZ.jpeg”-Error.
Is the the xpected behaviour? My thinking was that the ‘kirby’-user has no restrictions whatsoever?