Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flysystem disks visibility #503

Closed
Tracked by #148
mjauvin opened this issue Mar 21, 2022 · 8 comments
Closed
Tracked by #148

Flysystem disks visibility #503

mjauvin opened this issue Mar 21, 2022 · 8 comments
Assignees
Labels
high priority Issues that need to be more critically actioned
Milestone

Comments

@mjauvin
Copy link
Member

mjauvin commented Mar 21, 2022

Winter CMS Build

Other (please specify below)

PHP Version

8.0

Database engine

MySQL/MariaDB

Plugins installed

No response

Issue description

Laravel\Illuminate\Filesystem\FilesystemManager now use Visibility::PRIVATE by default now when instanciating the LocalAdapter class.

ref. https://github.com/laravel/framework/blob/9.x/src/Illuminate/Filesystem/FilesystemManager.php#L169-L174

So we need to pass visibility => 'public' to the Disk config if we want the files/folder created under that disk to be publicly accessible.

The Image Resizer seems to be using the "local" disk in some parts of the code(folders/files creation) and the "system" disk in other parts (for mapping assets resources).

Steps to replicate

  • add this markup to a test page: {{ 'assets/images/my-test-image.jpg' | theme | resize(600,400) }}
  • Remove folder storage/app/resized
  • Open the page URL
  • look at the permissions of the storage/app/resized folder (and subfolders)

Workaround

Add 'visibility' => 'public' to the local disk definition.

@mjauvin mjauvin added maintenance PRs that fix bugs, are translation changes or make only minor changes needs review Issues/PRs that require a review from a maintainer labels Mar 21, 2022
@mjauvin mjauvin added this to the v1.2.0 milestone Mar 21, 2022
@LukeTowers
Copy link
Member

LukeTowers commented Mar 22, 2022

Sounds like instead we should set the permissions property of the system disk config to cms.defaultMask.folder

@mjauvin
Copy link
Member Author

mjauvin commented Mar 22, 2022

You mean like this, but for the system disk:

    protected function registerNativeFilesystem()
    {   
        $this->app->singleton('files', function () {
            $config = $this->app['config'];
            $files = new Filesystem;
            $files->filePermissions = $config->get('cms.defaultMask.file', null);
            $files->folderPermissions = $config->get('cms.defaultMask.folder', null);
            $files->pathSymbols = [
                '~' => base_path(),
                '$' => base_path() . $config->get('cms.pluginsDir', '/plugins'),
                '#' => base_path() . $config->get('cms.themesDir', '/themes'),
            ];
            return $files;
        });
    }

@mjauvin
Copy link
Member Author

mjauvin commented Mar 22, 2022

Adding this to Winter\Storm\Filesystem\FilesystemManager works:

    protected function resolve($name, $config = null)
    {   
        if (is_null($config)) {
            $config = $this->getConfig($name);
        }
        if ($name === 'local') {
            $config['visibility'] = 'public';
        }

        return parent::resolve($name, $config);
    }

The problem with the permissions property of the system disk is that it's more complex:
ref. https://laravel.com/docs/9.x/filesystem#local-files-and-visibility

But we could also just pass the visibility parameter to Storage::put():
ref. https://laravel.com/docs/9.x/filesystem#file-visibility

@mjauvin
Copy link
Member Author

mjauvin commented Mar 22, 2022

I tried to replace FileHelper::put($tempPath, $this->getSourceFileContents()) with FileHelper::put($tempPath, $this->getSourceFileContents(), 'public') in modules/system/classesImageResizer.php and it doesn't work either.

@LukeTowers
Copy link
Member

Hmm, this is odd. The issue is happening on my server but not locally on Homestead. Server creates the directories with permissions 0700 and homestead creates them with 0755. I also tried changing $disk->put($path, file_get_contents($tempPath), ['visibility' => 'public']); in the resize() method but that didn't have any effect on the server.

Do you have idea what is causing the difference between local and the remote server @mjauvin?

@mjauvin
Copy link
Member Author

mjauvin commented Mar 22, 2022

I don't know, could be the PHP user's umask maybe? Not sure.

@mjauvin mjauvin added Type: Bug and removed maintenance PRs that fix bugs, are translation changes or make only minor changes needs review Issues/PRs that require a review from a maintainer labels May 14, 2022
@mjauvin
Copy link
Member Author

mjauvin commented May 14, 2022

@bennothommo can you reproduce this as well? Any idea on how to properly fix this?

@LukeTowers
Copy link
Member

Fixed by wintercms/storm@97588cb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
high priority Issues that need to be more critically actioned
Projects
None yet
Development

No branches or pull requests

3 participants