Setting user-specific folder permissions dynamically
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
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'] = '';
$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?
$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.