Description
Short description of the issue
On a default install (current dev branch, blank profile), $page->trashable
returns false
for the superuser, unless the core permission page-edit-trash-created
is manually installed.
Expected behavior
The superuser should always be able to delete any page, so $page->trashable
should always return true for the superuser.
Actual behavior
The permissions check fails unless the page-edit-trash-created
permission is installed on the site.
Optional: Screenshots/Links that demonstrate the issue
Forum post and detailed explanation here.
Optional: Suggestion for a possible fix
Ok so I have dug deep and determined why it isn't working. The
$page->trashable()
method is added byPagePermissions.module
as a hook. The methodPagePermissions::trashable
first calls$this->deleteable()
, which returns false for the current page (so far expected and documented behaviour). However, the$this->wire('permissions')->has('page-edit-trash-created')
check in this line fails, since thepage-edit-trash-created
permission doesn't exist in a default install. Since it directly calls the permissions fuel whose has method doesn't check for superuser, and the check fails if the permission doesn't exist. If I either create the permission through the backend or replace the above check with$this->user->hasPermission('page-edit-trash-created')
, it works as expected.
This is my suggested fix (for PagePermissions.module#L734):
// current
if(!$event->return && $this->wire('permissions')->has('page-edit-trash-created') && $page->editable()) {
// change to
if(!$event->return && $this->wire('user')->hasPermission('page-edit-trash-created') && $page->editable()) {
Steps to reproduce the issue
- Install ProcessWire (dev branch, blank profile)
- Check $page->trashable for the current page as the superuser
- The method returns false
Setup/Environment
- ProcessWire version: 3.0.130
- PHP version: 7.2
- MySQL version: 5.7