we have introduced a permission structure for users.
this works well.
But, when a user from a user group, that is allowed to create pages, but view only his own pages there will be an error on creating a page:
Why? Because we checked the “self” pages via the user-field.
When the user is creating a new page, he wrote the name for the page, then the error comes…
The folder and the txt-file is created, but without the filled user.
The Blueprint is like so…
user:
label: Created from User
type: user
width: 1/3
#default: groupname
When i add the default this will function.
In a second test we created an own UserField on plugins/own-fields
This looks like this
<?php
if (!class_exists('UserField')) { return; }
class User2Field extends UserField {
public function value() {
$value = parent::value();
// default to current user if no default one is defined
if(empty($value) && !$this->default && $this->default !== false) {
return site()->user()->username();
} else {
return $value;
}
return $value;
}
public function _default($params, $default) {
// Get current user
$user = site()->user()->username();
return $user;
}
}
Blueprint like this:
user2:
type: user2
This has the same result:
The txt will be created, but none user will be added on the create.
Well, I guess that is because nothing gets saved in the file when the page is created, but only on page update. So that when the user is redirected to the page after it is created, he is not allowed to read it and therefore the error is thrown.
A workaround I can think of would be to use a panel.page.createhook to store the current user in the file.
our subsequent update has then thrown the error because the user! = was the registered user and this then had no authority.
So the solution is to allow the update as well, if user == is empty. that’s exactly the case right in the create-hook. There, the update is then made and set to the current user.