Recipie for restricting admin groups to group upload folder

Talk about writing modules and plugins for CMS Made Simple, or about specific core functionality. This board is for PHP programmers that are contributing to CMSMS not for site developers
Post Reply
gazzur
New Member
New Member
Posts: 4
Joined: Tue Jun 16, 2009 10:19 am

Recipie for restricting admin groups to group upload folder

Post 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!
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm
Location: Fernie British Columbia, Canada

Re: Recipie for restricting admin groups to group upload folder

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
Post Reply

Return to “Developers Discussion”