Setting user-specific folder permissions dynamically

edited October 2012 in Modules
I'd like to be able to dynamically set permissions for CMS users to be able to access and save images to a single directory in the images folder. I'm able to dynamically create a folder with the id number of a user but I have to go in to the CMS and give permissions to the whole assets directory in order for the user to be able to browse that directory. Here's what I've got so far in the form_fields function of my clients_model (clients_model explained here: http://www.getfuelcms.com/forums/discussion/989/understanding-fuel-module-hooks/#Item_7 )

$fields['new_game_logo_image_upload']['before_html'] = "<img src='/assets/images/$client_id/".$values["new_game_logo_image"] . "' style='float: right;' />"; // set the game image upload path $fields['new_game_logo_image_upload']['upload_path'] = assets_server_path($client_id, 'images'); $fields['new_game_logo_image']['class'] = "asset_select images/$client_id";
If the user clicks on the 'select' button in the form to browse their directory for an image the lightbox that pops up is blank and shows nothing if the user hasn't been given permissions to the entire assets directory from 'Manage->Permissions' in the CMS.

Is there a way to dynamically set permissions to specific folders based on a user's id from the fuel_users table?

Comments

  • edited October 2012
    Unfortunately, FUEL doesn't provide granule control of sub folder permissions for asset files. I suppose you could overwrite the assets_model so that it would only look into the folder of the logged in persons ID but may be a little more work.

    To overwrite, I would copy the existing assets_model.php file and create a new one perhaps called my_assets_model.php file. Then in the MY_fuel_modules.php config file, add the following:
    $config['module_overwrites']['assets']['model_name'] = 'my_assets_model'; $config['module_overwrites']['assets']['model_location'] = '';
  • edited 12:34PM
    Thanks for the reply. Might be something I should build outside the CMS. Will see what I can do.
  • edited 12:34PM
    Ok, I copied the existing assets_model.php file and placed it in the applications/models dir naming it MY_assets_model.php. I then went into MY_fuel_modules.php and added this:
    $config['module_overwrites']['assets']['model'] = 'MY_assets_model'; $config['module_overwrites']['assets']['model_location'] = ''; however, it didn't seem to be running MY_assets_model.php at all. I even broke the code in the 'MY' file to be sure. So, I searched around in the docs and the forum here and found a few options for doing this trying them all.

    One was:
    $config['module_overwrites']['assets'] = array('model_name' => 'MY_assets_model'); which produced this error:
    Fatal error: Class 'My_assets_model' not found in /Applications/MAMP/htdocs/mypromogame.com/htdocs/fuel/application/third_party/fuel/Loader.php on line 240

    Also tried:
    $config['module_overwrites']['assets'] = array('model_name' => 'MY_assets_model', 'model_location' => FUEL_PATH . '/models/assets_model.php'); but got the same error as above. Tried setting the model_location to an empty string as well but error didn't change.

    I also tried doing a require_once of the assets_model.php file in MY_assets.model.php but got an error at the end of the file that the class can't be declared twice.

    Any ideas?
  • edited 12:34PM
    You are right in that it should be "model_name" and not just "model". I'd try changing the "model_name" value to be My_assets_model (note that it's not MY)
  • edited October 2012
    Thanks. It's weird but I changed the name to My_assets_model.php and changed the line in MY_fuel_modules.php to:

    $config['module_overwrites']['assets']['model_name'] = 'My_assets_model';

    Getting this error:

    Fatal error: Class 'My_assets_model' not found in /Applications/MAMP/htdocs/mypromogame.com/htdocs/fuel/application/third_party/fuel/Loader.php on line 240

    Does module_overwrites default to looking in the application/models folder? I tried:

    $config['module_overwrites']['assets'] = array('model_name' => 'My_assets_model', 'model_location' => APPPATH . '/models'); and a few other values for the model location and keep getting the same error.
  • edited 12:34PM
    The model location value should be blank "" or the word "app" which is used to point to the application directory.
  • edited 12:34PM
    Thanks for all your help. Got it working!
Sign In or Register to comment.