From 726d2c3a51363872b0b6ea56e76b15bcf29842b8 Mon Sep 17 00:00:00 2001 From: nathangray Date: Mon, 13 Jun 2016 20:35:43 -0600 Subject: [PATCH] Fix resource categories: - category admin is different from category owner - fix error saving ACL - fix missing column IDs, which prevented user from resizing or toggling some columns --- resources/inc/class.resources_acl_bo.inc.php | 2 +- resources/inc/class.resources_acl_ui.inc.php | 45 +++++++++++++------- resources/templates/default/acl.xet | 19 ++++++--- resources/templates/default/acl_edit.xet | 4 +- 4 files changed, 45 insertions(+), 25 deletions(-) diff --git a/resources/inc/class.resources_acl_bo.inc.php b/resources/inc/class.resources_acl_bo.inc.php index af099bedb6..59b8b55f06 100755 --- a/resources/inc/class.resources_acl_bo.inc.php +++ b/resources/inc/class.resources_acl_bo.inc.php @@ -244,7 +244,7 @@ class resources_acl_bo $GLOBALS['egw']->acl->delete_repository('resources','L' . $cat_id,false); - foreach(array_unique(array_intersect($readcat, $writecat, $calreadcat, $calbookcat, $admincat)) as $account_id) + foreach(array_unique(array_merge($readcat, $writecat, $calreadcat, $calbookcat, $admincat)) as $account_id) { $rights = false; $rights = in_array($account_id,$readcat) ? ($rights | Acl::READ) : false; diff --git a/resources/inc/class.resources_acl_ui.inc.php b/resources/inc/class.resources_acl_ui.inc.php index 2e35b32194..bf1f5bc01e 100755 --- a/resources/inc/class.resources_acl_ui.inc.php +++ b/resources/inc/class.resources_acl_ui.inc.php @@ -35,7 +35,8 @@ class resources_acl_ui 'read' => Acl::READ, 'write' => Acl::ADD, 'calread' => resources_acl_bo::CAL_READ, - 'calwrite' => resources_acl_bo::DIRECT_BOOKING + 'calwrite' => resources_acl_bo::DIRECT_BOOKING, + 'admin' => resources_acl_bo::CAT_ADMIN ); function __construct() @@ -64,7 +65,7 @@ class resources_acl_ui 'row_id' => 'id', // I key into row content to set it's value as row-id, eg. 'id' 'parent_id' => 'parent',// I key into row content of children linking them to their parent, also used as col_filter to query children 'dataStorePrefix'=> 'categories',// Avoid conflict with user list when in admin - 'actions' => $this->get_actions(), // I array with actions, see nextmatch_widget::egw_actions + 'actions' => self::get_actions(), // I array with actions, see nextmatch_widget::egw_actions 'placeholder_actions' => array('add') // I Array Optional list of actions allowed on the placeholder. If not provided, it's ["add"]. ); $template = new Etemplate('resources.acl'); @@ -73,7 +74,7 @@ class resources_acl_ui $template->exec(__METHOD__, $content, $sel_options, $readonlys); } - protected function get_actions($appname='resources') { + protected static function get_actions($appname='resources') { $actions = array( 'open' => array( // does edit if allowed, otherwise view @@ -163,6 +164,10 @@ class resources_acl_ui { $this->deny(); } + + $config = Api\Config::read('resources'); + $location_cats = $config['location_cats'] ? explode(',', $config['location_cats']) : array(); + if (!isset($content)) { if (!(isset($_GET['cat_id']) && $_GET['cat_id'] > 0 && @@ -193,8 +198,18 @@ class resources_acl_ui try { $cats->edit($content); resources_acl_bo::set_rights( - $content['id'], $content['read'], $content['write'], $content['calread'], $content['calwrite'], null + $content['id'], $content['read'], $content['write'], $content['calread'], $content['calwrite'], Array($content['admin']) ); + if($content['location']) + { + $location_cats[] = $content['id']; + $location_cats = array_unique($location_cats); + } + else if(($key = array_search($content['id'], $location_cats)) !== false) + { + unset($location_cats[$key]); + } + config::save_value('location_cats', implode(',', $location_cats), 'resources'); $msg = lang('Category saved.'); } catch (Api\Exception\WrongUserinput $e) @@ -224,24 +239,24 @@ class resources_acl_ui $content['icon_url'] = $content['base_url'] . $content['data']['icon']; } - // Make sure $content['owner'] is an array otherwise it wont show up values in the multiselectbox - if($content['owner'] == 0) - { - unset($content['owner']); - } - else if (!is_array($content['owner'])) - { - $content['owner'] = explode(',',$content['owner']); - } foreach(self::$acl_map as $field => $acl) { $content[$field] = $GLOBALS['egw']->acl->get_ids_for_location('L'.$content['id'], $acl, 'resources'); } + // Make sure $content['admin'] is an array otherwise it wont show up values in the multiselectbox + if($content['admin'] == 0) + { + unset($content['admin']); + } + else if (!is_array($content['admin'])) + { + $content['admin'] = explode(',',$content['admin']); + } + // Location - $config = Api\Config::read('resources'); - $content['location'] = in_array($content['id'],$config['location_cats'] ? explode(',', $config['location_cats']) : array()); + $content['location'] = in_array($content['id'],$location_cats); $tmpl = new Etemplate('resources.acl_edit'); $tmpl->exec('resources.resources_acl_ui.edit',$content,$sel_options,$readonlys,$content,2); diff --git a/resources/templates/default/acl.xet b/resources/templates/default/acl.xet index cd42587dc3..9c3b0aa654 100644 --- a/resources/templates/default/acl.xet +++ b/resources/templates/default/acl.xet @@ -7,6 +7,7 @@ + @@ -16,17 +17,18 @@ - - - - + + + + + - + - + - + @@ -36,6 +38,9 @@ + + + diff --git a/resources/templates/default/acl_edit.xet b/resources/templates/default/acl_edit.xet index c8728ab6bf..8e79f26a28 100644 --- a/resources/templates/default/acl_edit.xet +++ b/resources/templates/default/acl_edit.xet @@ -18,8 +18,8 @@ - - + +