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

help hidding folders in a google bucket #322

Open
longthoughtsolutions opened this issue Mar 25, 2023 · 1 comment
Open

help hidding folders in a google bucket #322

longthoughtsolutions opened this issue Mar 25, 2023 · 1 comment

Comments

@longthoughtsolutions
Copy link

longthoughtsolutions commented Mar 25, 2023

I am able to user GoogleCloudStorage (gcs) and everything is working fine. What I have having trouble with is "hiding" all folders expect the one I want a user to have access to. In that one folder The user should have full access. I am using "barryvdh/laravel-elfinder": "^0.5.2",

My config file is default except for
/*
|--------------------------------------------------------------------------
| Upload dir
|--------------------------------------------------------------------------
|
| The dir where to store the images (relative from public)
|
*/
'dir' => 'none',

/*
|--------------------------------------------------------------------------
| Filesystem disks (Flysytem)
|--------------------------------------------------------------------------
|
| Define an array of Filesystem disks, which use Flysystem.
| You can set extra options, example:
|
| 'my-disk' => [
|        'URL' => url('to/disk'),
|        'alias' => 'Local storage',
|    ]
*/
'disks' => [
    'gcs' => [
        'alias' => 'Cloud File Storage'
    ]
],

I have a middleware with two function that are NOT doing what I thought they would

public function handle(Request $request, Closure $next){
        $disk = Storage::disk('gcs');
        $thisOrgId = current_org()->ID;
        $thisOrgName = current_org()->OrganizationName;
        $dirName = $thisOrgId;
        if ($dirName != '' && !$disk->directoryExists($dirName)) {
            $disk->makeDirectory($dirName);
        }
        $dirs = $disk->directories();
        $this->app = app();
        // $roots = $this->app->config->get('elfinder.roots', []);
        if (empty($roots)) {
            $roots = [];
            foreach ($dirs as $key => $dir) {
                // if the dir should be shown
                if($dir == $thisOrgId){
                    array_push($roots , [
                    'driver' => 'gcs', // driver for accessing file system (REQUIRED)
                    'path' => $dir, // path to files (REQUIRED)
                    'startPath' => $dir,
                    'URL' => config('app.google.bucket_prefix'), // URL to files (REQUIRED)
                    'accessControl' => $this->access(
                        'hidden',
                        config('app.google.bucket_prefix').'/'.$dir,'gcs',
                        'accessControlData',
                        true,
                        '/'.$dir), // https://github.com/Studio-42/elFinder/wiki/Connector-configuration-options-2.1#accesscontrol
                    'alias' => $thisOrgName,
                    'uploadAllow' => array('image'),
                    'uploadMaxSize' => '5M',
                    'attributes' => array(
                        array(
                            'pattern' => '/\'/', // Dont write or delete to this but subfolders and files
                            'read' => true,
                            'write' => true,
                            'locked' => true
                            )
                        )
                    ]);
                } else {
                    // hide the dir
                    array_push($roots , [
                        'driver' => 'gcs', // driver for accessing file system (REQUIRED)
                        'path' => $dir, // path to files (REQUIRED)
                        'URL' => config('app.google.bucket_prefix'), // URL to files (REQUIRED)
                        'attributes' => array(
                            array(
                                'pattern'=> $dir,
                                'hidden'=>true
                                )
                            )
                        ]);
                }
            }
        }
        $opts = $this->app->config->get('elfinder.options', array());
        
        $bind = '';
        $plugin = '';
        $opts = array_merge(['bind'=>$bind,'plugin'=>$plugin,'roots' => $roots], $opts);
        
        return $next($request);
    }
function access($attr, $path, $data, $volume, $isDir, $relpath) {
    $basename = basename($path);
    return $basename[0] === '.'                  // if file/folder begins with '.' (dot)
             && strlen($relpath) !== 1           // but with out volume root
        ? !($attr == 'read' || $attr == 'write') // set read+write to false, other (locked+hidden) set to true
        :  null;                                 // else elFinder decide it itself
}

If I dump it looks like the example I have seen, What am I doing wrong?

image

@longthoughtsolutions
Copy link
Author

Is this still monitored?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant