XF 2.2 Setting default visibility for flysystem via config.php

Kirby

Well-known member
@Mike pointed out in https://xenforo.com/community/threa...nternal-data-and-code-cache-is-public.195330/ that it should be possible to set the default visibility via config.php

However I don't see a nice way to accomplish this:
The adapter does not seem to have access to the config, this does always get passed as a paramter to individual methods (like write, writeStream, etc.).

Therefore I don't see a way to set the default visibility (short of hacking the permissions for public to effectivyle become private) via config.php.

Am I missing smth. here?
 
You can override the adapter in use via $config['fsAdapters'][$typeName]. ($typeName being data, internal-data or code-cache.) Set it to a closure and then you're basically doing what XF\FsMounts::getLocalAdapter does to set the desired permissions. I don't believe you can change the public visibility part per se as that's passed into the event wrapper, but you can change what the permissions used are in this way.
 
Alternatively I think you could listen to the mounted_file_write event and take the desired action there.
 
I don't believe you can change the public visibility part per se as that's passed into the event wrapper, but you can change what the permissions used are in this way.
Yes, that's my point exactly - I could change the permissions for visibilty public on specific adapters, but I can't change the visibility itself.

Using a code event would be possible, but I am not sure if I'd like to use that event as taht would be fired quite often - seems like a lot of overhead for just setting smth,. that the libary does allow to set by default :)

I think I'll extend XF\FsMounts but ideally I really think this is smth, that should supported in core; doesn't have to be painful for anyone if it's configurable (and not enabled by default).

PHP:
namespace XF:

class FsMounts
{
    public static function loadDefaultMounts(array $config)
    {
        $visibility = AdapterInterface::VISIBILITY_PUBLIC;

        $chmodPrivate = XF::app()->config('chmodPrivate');
        if ($chmodPrivate !== false)
        {
            $visibility = AdapterInterface::VISIBILITY_PRIVATE;
        }
 
        $internalData = new EventableFilesystem($internalDataAdapter, [
            'visibility' => $visibility
        ]);

        [...]

        $codeCache = new EventableFilesystem($codeCacheAdapter, [
            'visibility' => $visibility
        ]);
    }

    [...]

    public static function getLocalAdapter($path)
    {
        [...]

        $flysystemPermissions = [
            'file' => ['public' => $permissions['file']]
            'dir' => ['public' => $permissions['dir']],
        ];
     
        $chmodPrivate = XF::app()->config('chmodPrivate');
     
        if ($chmodPrivate !== false)
        {
            $flysystemPermissions['file']['private'] = $chmodPrivate['file'];
            $flysystemPermissions['dir']['private'] = $chmodPrivate['dir'];
        }

        return new LocalFsAdapter(
            File::canonicalizePath($path),
            LOCK_EX,
            \League\Flysystem\Adapter\Local::DISALLOW_LINKS,
            $flysystemPermissions
        );
    }
}
 
Back
Top Bottom