Page 1 of 1

Recipie for restricting admin groups to group upload folder

Posted: Thu Aug 20, 2009 1:33 pm
by gazzur
I can't see a way of making this into a module, but it's a way of automatically adding a folder for each new group and restricting their access just to that folder. The config file could also be tweaked to do the same thing with the images upload folder. Would love to hear any feedback on ways to improve this...

   1.  Edit config.php file as follows (where it defines the $config['uploads_path'] and $config['uploads_url'] variables):
     

Code: Select all

 #Where are uploaded files put?  This defaults to uploads.
     if(isset($_SESSION['cms_admin_user_id']) && $_SESSION['cms_admin_user_id'] == 1){
              $config['uploads_path'] = 'D:\xampp\xampp\htdocs\cms16\uploads';
          }
          else{
              $config['uploads_path'] = 'D:\xampp\xampp\htdocs\cms16\uploads' . '\\' . $_SESSION['cms_admin_group_name'];
          }
      #Where is the url to this uploads directory?
      if(isset($_SESSION['cms_admin_user_id'])&& $_SESSION['cms_admin_user_id'] == 1){

          $config['uploads_url'] = $config['root_url'] . '/uploads';
      }
      else{
          $config['uploads_url'] = $config['root_url'] . '/uploads' . '/' . $_SESSION['cms_admin_group_name'];
      }
   2. Create 2 UDTs as follows:
      UDT 1:
      Name: creategroupfolder
     
     

Code: Select all

 /** Creates a folder named after newly created group **/
      global $gCms;
      $config = $gCms->config;
      $newgp = $params['group'];
      mkdir($config['uploads_path'] . '\\' . $newgp->name);
      UDT 2:
      Name: deletegroupfolder
 
     

Code: Select all

/** Deletes the folder of the group that has just been deleted **/
      global $gCms;
      $config = $gCms->config;
      $thegp = $params['group'];
      rmdir($config['uploads_path'] . '\\' . $thegp->name);
   3. Go to Event Manager and add creategroupfolder UDT to AddGroupPost event

   4. Add deletegroupfolder UDT to DeleteGroupPre event.

   5. You're done!

Re: Recipie for restricting admin groups to group upload folder

Posted: Thu Aug 20, 2009 1:38 pm
by calguy1000
This won't work (or won't work properly) if you have users that aren't members of any groups... or are members of more than one group.