From 6f162f144e360fa6841cfe8d9041625cdebf73e6 Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 2 Oct 2013 16:29:08 +0000 Subject: [PATCH] add context sensitive link to ACL/grant access to top-menu, same is to be happen for cats and preferences itself and preferences in sidebox will be removed --- admin/inc/class.admin_acl.inc.php | 5 +- admin/inc/class.uiconfig.inc.php | 3 +- phpgwapi/inc/class.egw_framework.inc.php | 31 +++++++++++ phpgwapi/js/jsapi/jsapi.js | 36 ++++++++++++- .../idots/class.idots_framework.inc.php | 4 +- .../inc/class.preferences_hooks.inc.php | 53 +++++++++++++++++++ preferences/setup/setup.inc.php | 4 ++ preferences/templates/default/config.tpl | 40 ++++++++++++++ 8 files changed, 169 insertions(+), 7 deletions(-) create mode 100644 preferences/templates/default/config.tpl diff --git a/admin/inc/class.admin_acl.inc.php b/admin/inc/class.admin_acl.inc.php index d4a3dc0268..1a82fb5bea 100644 --- a/admin/inc/class.admin_acl.inc.php +++ b/admin/inc/class.admin_acl.inc.php @@ -444,14 +444,15 @@ class admin_acl 'get_rows' => 'admin_acl::get_rows', 'no_cat' => true, 'filter' => !empty($_GET['acl_filter']) ? $_GET['acl_filter'] : - $GLOBALS['egw_info']['user']['preferences']['admin']['acl_filter'], + ($GLOBALS['egw_info']['flags']['currentapp'] != 'admin' ? 'other' : + $GLOBALS['egw_info']['user']['preferences']['admin']['acl_filter']), 'filter2' => !empty($_GET['acl_app']) ? $_GET['acl_app'] : '', 'lettersearch' => false, 'order' => 'acl_appname', 'sort' => 'ASC', 'row_id' => 'id', 'account_id' => isset($_GET['account_id']) && (int)$_GET['account_id'] ? (int)(int)$_GET['account_id'] : - $GLOBALS['egw_info']['user']['acount_id'], + $GLOBALS['egw_info']['user']['account_id'], 'actions' => self::get_actions(), 'acl_rights' => $GLOBALS['egw']->hooks->process(array( 'location' => 'acl_rights', diff --git a/admin/inc/class.uiconfig.inc.php b/admin/inc/class.uiconfig.inc.php index 99cac3140c..daa2599714 100644 --- a/admin/inc/class.uiconfig.inc.php +++ b/admin/inc/class.uiconfig.inc.php @@ -52,8 +52,7 @@ class uiconfig case 'admin': case 'addressbook': case 'calendar': - case 'email': - case 'nntp': + case 'preferences': /* Other special apps can go here for now, e.g.: case 'bogusappname': diff --git a/phpgwapi/inc/class.egw_framework.inc.php b/phpgwapi/inc/class.egw_framework.inc.php index 8b35baa1c0..f63253ac2d 100644 --- a/phpgwapi/inc/class.egw_framework.inc.php +++ b/phpgwapi/inc/class.egw_framework.inc.php @@ -1027,6 +1027,11 @@ abstract class egw_framework )); } + if (($acl = $this->topmenu_acl())) + { + $this->_add_topmenu_item($acl); + } + if($GLOBALS['egw_info']['user']['apps']['manual'] && isset($apps['manual'])) { $this->_add_topmenu_item(array_merge($apps['manual'],array('title' => lang('Help')))); @@ -1049,6 +1054,32 @@ abstract class egw_framework $this->_add_topmenu_info_item($vars['quick_add']); } + /** + * Add ACL link to topmenu using acl_rights-hook to know if an app supports acl + */ + function topmenu_acl() + { + if (!$GLOBALS['egw_info']['user']['apps']['preferences'] || + $GLOBALS['egw_info']['server']['deny_acl'] && array_intersect( + $GLOBALS['egw']->accounts->memberships($GLOBALS['egw_info']['user']['account_id'], true), + (array)$GLOBALS['egw_info']['server']['deny_acl'])) + { + return; // user has no access to preferences app + } + $apps = $GLOBALS['egw']->hooks->process('acl_rights'); + foreach($apps as $app => $rights) + { + if (!$rights) unset($apps[$app]); + } + $apps = array_keys($apps); + + return array( + 'name' => 'preferences', + 'title' => lang('Access'), + 'url' => 'javascript:egw_preferences("acl", '.json_encode($apps).')', + ); + } + /** * Add menu items to the topmenu template class to be displayed * diff --git a/phpgwapi/js/jsapi/jsapi.js b/phpgwapi/js/jsapi/jsapi.js index dc6ea593e7..7272040ab6 100644 --- a/phpgwapi/js/jsapi/jsapi.js +++ b/phpgwapi/js/jsapi/jsapi.js @@ -777,7 +777,7 @@ function dropdown_menu_hack(el) el.contentOptions [el.contentOptions.length] = { "value": el.options[i].value,"text": el.options[i].innerHTML - } + }; if(!el.options[i].selected){el.options[i].removeNode(true);i--;}; } el.onkeydown = switchMenu; @@ -786,3 +786,37 @@ function dropdown_menu_hack(el) } } +/** + * Dummy link handler, which can be overwritten by templates + * + * @param _link + * @param _app + */ +function egw_link_handler(_link, _app) +{ + window.location.href = egw_webserverUrl+_link; +} + +/** + * Call context / open app specific preferences function + * + * @param string name 'acl', 'prefs', or 'cats' + * @param array apps apps allowing to call that + */ +function egw_preferences(name, apps) +{ + var current_app = egw_getAppName(); + if ($j.inArray(current_app, apps) == -1) + { + egw_message(egw.lang('Not supported by current application!'), 'warning'); + } + else + { + switch(name) + { + case 'acl': + egw_link_handler(egw_webserverUrl+'/index.php?menuaction=preferences.preferences_acl.index&acl_app='+current_app, current_app); + break; + } + } +} diff --git a/phpgwapi/templates/idots/class.idots_framework.inc.php b/phpgwapi/templates/idots/class.idots_framework.inc.php index f30ce31923..d81602b446 100644 --- a/phpgwapi/templates/idots/class.idots_framework.inc.php +++ b/phpgwapi/templates/idots/class.idots_framework.inc.php @@ -674,9 +674,9 @@ egw.set_user('.$GLOBALS['egw']->accounts->json($GLOBALS['egw_info']['user']['acc */ function _add_topmenu_item(array $app_data,$alt_label=null) { - $_item['url'] = $app_data['url']; + $_item['url'] = htmlspecialchars($app_data['url']); $_item['urlextra'] = $app_data['target']; - $_item['label'] = ($alt_label?$alt_label:$app_data['title']); + $_item['label'] = $alt_label ? $alt_label : $app_data['title']; $this->tplsav2->menuitems[] = $_item; $this->tplsav2->icon_or_star = $GLOBALS['egw_info']['server']['webserver_url'] . '/phpgwapi/templates/'.$this->template.'/images'.'/orange-ball.png'; } diff --git a/preferences/inc/class.preferences_hooks.inc.php b/preferences/inc/class.preferences_hooks.inc.php index 3d2f4b937a..d5bcea627e 100644 --- a/preferences/inc/class.preferences_hooks.inc.php +++ b/preferences/inc/class.preferences_hooks.inc.php @@ -472,4 +472,57 @@ class preferences_hooks 'extradata' => 'menuaction=preferences.preferences_settings.index' ); } + + /** + * hooks to build sidebox-menu plus the admin and preferences sections + * + * @param string|array $args hook args + */ + static function admin($args) + { + $appname = 'preferences'; + $file = Array( + 'Site configuration' => egw::link('/index.php','menuaction=admin.uiconfig.index&appname=' . $appname), + ); + display_section($appname, $file); + } + + /** + * Hook returning options for deny_acl groups + * + * @param array $config + */ + public static function deny_prefs($config) + { + $accountsel = new uiaccountsel(); + + return ''. + $accountsel->selection('newsettings[deny_prefs]', 'deny_prefs', $config['deny_prefs'], 'groups', 4); + } + + /** + * Hook returning options for deny_acl groups + * + * @param array $config + */ + public static function deny_acl($config) + { + $accountsel = new uiaccountsel(); + + return ''. + $accountsel->selection('newsettings[deny_acl]', 'deny_acl', $config['deny_acl'], 'groups', 4); + } + + /** + * Hook returning options for deny_cats groups + * + * @param array $config + */ + public static function deny_cats($config) + { + $accountsel = new uiaccountsel(); + + return ''. + $accountsel->selection('newsettings[deny_cats]', 'deny_cats', $config['deny_cats'], 'groups', 4); + } } diff --git a/preferences/setup/setup.inc.php b/preferences/setup/setup.inc.php index dea7828f69..1a0b37dd73 100755 --- a/preferences/setup/setup.inc.php +++ b/preferences/setup/setup.inc.php @@ -26,6 +26,10 @@ $setup_info['preferences']['hooks']['edit_user'] = 'preferences_hooks::edit_ $setup_info['preferences']['hooks']['view_user'] = 'preferences_hooks::edit_user'; $setup_info['preferences']['hooks']['edit_group'] = 'preferences_hooks::edit_user'; $setup_info['preferences']['hooks']['group_manager'] = 'preferences_hooks::edit_user'; +$setup_info['preferences']['hooks']['admin'] = 'preferences_hooks::admin'; +$setup_info['preferences']['hooks']['deny_prefs'] = 'preferences_hooks::deny_prefs'; +$setup_info['preferences']['hooks']['deny_acl'] = 'preferences_hooks::deny_acl'; +$setup_info['preferences']['hooks']['deny_cats'] = 'preferences_hooks::deny_cats'; /* Dependencies for this app to work */ $setup_info['preferences']['depends'][] = array( diff --git a/preferences/templates/default/config.tpl b/preferences/templates/default/config.tpl new file mode 100644 index 0000000000..e5eed7d52c --- /dev/null +++ b/preferences/templates/default/config.tpl @@ -0,0 +1,40 @@ + + +

{error}

+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + +
 {title}
{lang_Deny_following_groups_access_to_preferences}:{call_preferences_hooks::deny_prefs}
{lang_Deny_following_groups_access_to_ACL_(grant_access)}:{call_preferences_hooks::deny_acl}
{lang_Deny_following_groups_access_to_edit_categories}:{call_preferences_hooks::deny_cats}
+  +
+ + +
+
+
+