R33573 - in /trunk/resources: inc/class.resources_hooks.inc.php setup/setup.inc.php

Author: nathangray
New Revision: 33573

URL: http://www.egroupware.org/viewvc/egroupware?rev=33573&view=rev
Log:

  • Add protection against inaccessable resources when their category is removed
    Resources will be moved to the parent category, default category from setup, or an admin only ‘No category’.
    Resources’ ACL requires a category

Modified:
trunk/resources/inc/class.resources_hooks.inc.php
trunk/resources/setup/setup.inc.php

Modified: trunk/resources/inc/class.resources_hooks.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/resources/inc/class.resources_hooks.inc.php?rev=33573&r1=33572&r2=33573&view=diff

— trunk/resources/inc/class.resources_hooks.inc.php (original)
+++ trunk/resources/inc/class.resources_hooks.inc.php Fri Jan 7 23:31:59 2011
@@ -117,4 +117,57 @@
)
);
}
+

  • /**
    • Handle deleted category
    • Resources’ ACL requires a category.
    • Moves all resources to parent, if it exists. If it doesn’t, another category is created.
  • */
  • function delete_category($args)
  • {
  •   $cat = categories::read($args['cat_id']);
    
  •   if(!$cat) return; // Can't find current cat?
    
  •   if($cat['parent'] == 0)
    
  •   {
    
  •   	// No parent, try the default cat from setup
    
  •   	$categories = new categories('', 'resources');
    
  •   	$default = $categories->name2id('General resources');
    
  •   	if($default)
    
  •   	{
    
  •   		$new_cat_id = $default;
    
  •   	}
    
  •   	else
    
  •   	{
    
  •   		// Default missing, look for 'No category'
    
  •   		$new_cat_id = $categories->name2id('No category');
    
  •   		if($new_cat_id == 0) {
    
  •   			// No category not there, add it
    
  •   			$new_cat_id = $categories->add(array(
    
  •   				'name'		=> 'No category',
    
  •   				'description'	=> 'This category has been added to rescue resources whose category was deleted.',
    
  •   				'parent'	=> 0
    
  •   			));
    
  •   			$admin = -2;
    
  •   			ExecMethod2('resources.bo_acl.set_rights', $new_cat_id, array($admin), array($admin), array($admin), array($admin),array($admin));
    
  •   		}
    
  •   	}
    
  •   }
    
  •   else
    
  •   {
    
  •   	$new_cat_id = $cat['parent'];
    
  •   }
    
  •   // Get any resources affected
    
  •   $query = array('filter' => $args['cat_id']);
    
  •   $bo = CreateObject('resources.bo_resources');
    
  •   $bo->get_rows($query, $resources, $readonly);
    
  •   foreach($resources as $resource)
    
  •   {
    
  •   	$resource['cat_id'] = $new_cat_id;
    
  •   	$bo->save($resource);
    
  •   }
    
  • }
    }

Modified: trunk/resources/setup/setup.inc.php
URL: http://www.egroupware.org/viewvc/egroupware/trunk/resources/setup/setup.inc.php?rev=33573&r1=33572&r2=33573&view=diff

— trunk/resources/setup/setup.inc.php (original)
+++ trunk/resources/setup/setup.inc.php Fri Jan 7 23:31:59 2011
@@ -33,6 +33,7 @@
$setup_info[‘resources’][‘hooks’][‘sidebox_menu’] = ‘resources.resources_hooks.admin_prefs_sidebox’;
$setup_info[‘resources’][‘hooks’][‘search_link’] = ‘resources.resources_hooks.search_link’;
$setup_info[‘resources’][‘hooks’][‘calendar_resources’] = ‘resources.resources_hooks.calendar_resources’;
+$setup_info[‘resources’][‘hooks’][‘delete_category’] = ‘resources.resources_hooks.delete_category’;
// $setup_info[‘resources’][‘hooks’][] = ‘home’;
// $setup_info[‘resources’][‘hooks’][] = ‘settings’;


Gaining the trust of online customers is vital for the success of any company
that requires sensitive data to be transmitted over the Web. Learn how to
best implement a security strategy that keeps consumers’ information secure
and instills the confidence they need to proceed with transactions.
http://p.sf.net/sfu/oracle-sfdevnl


eGroupWare-cvs mailing list
eGroupWare-cvs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/egroupware-cvs