8.4.2: search_file_folder permissions don't work on user

Permalink
I have a user 'user1' who can edit the site and add a block if permissions 'search_file_folder' are set. I've added the 'user1' to the File Manager Permissions (see attached pic). And I have the following code in a block controller:
$key = \Concrete\Core\Permission\Key\Key::getByHandle('search_file_folder');
if ($key->validate()) {
    $this->set('permissions', true);
} else {
    $this->set('permissions', false);
}

and this in the block form:
<?php if ($permissions) { ?>
    ...
<?php } else { ?>
    <fieldset class="ab-file-list-form">
        <div class="form-group">
            <div class="alert alert-danger" role="alert">
                <?php echo t('You do not have permissions to search files'); ?>
            </div>
        </div>
    </fieldset>
<?php } ?>

What happens is when I add the block as the original admin, it works fine. But when I add the block as 'user1', it says 'You do not have permissions to search files', that is the 'search_file_folder' is not set for that user.

What's wrong here?

Thank you.

1 Attachment

linuxoid
 
linuxoid replied on at Permalink Reply
linuxoid
Sorted it out. It turns out the editor must be added to the Search File Folder permissions in the File Manager.
jasteele12 replied on at Permalink Reply
jasteele12
Nice, but can that be done programmitallly?
linuxoid replied on at Permalink Reply
linuxoid
If you make a package for yourself and know the group, you should be able to. If you develop a package for the marketplace, you never know what groups should be allowed.

So if you know the group:
use Concrete\Core\Permission\Key\FileFolderKey;
$group = Group::getByID($group_id);
// or
// $group = Group::getByName('My Group'); 
if ($group) {
    $file_system = $this->app->make(Filesystem::class);
    $root_folder = $file_system->getRootFolder();
    $folder = FileFolder::getNodeByName('My Folder');
    if ($folder && $folder instanceof FileFolder) {
        $pk = FileFolderKey::getByHandle('search_file_folder');
        $pk->setPermissionObject($folder);
        $pt = $pk->getPermissionAssignmentObject();
        if ($pt) {
            $pt->clearPermissionAssignment();
            $pa = $pk->getPermissionAccessObject();

Note the above is adapted from another piece of code for a different permission key, I have not tried that. See the /concrete/src/File/FolderItemList.php