From 33e88d25aee9fb853e9e85a76930076db76cf92c Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Fri, 31 Jul 2020 09:47:49 +0200 Subject: [PATCH] * Preferences: use push to ask every affected client to reload preferences, if affected --- api/js/jsapi/egw_preferences.js | 18 ++++++++++++++++++ api/js/jsapi/egw_user.js | 2 +- api/src/Accounts.php | 5 +++-- .../inc/class.preferences_settings.inc.php | 8 ++++++-- 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/api/js/jsapi/egw_preferences.js b/api/js/jsapi/egw_preferences.js index aeaab16f78..3695616b55 100644 --- a/api/js/jsapi/egw_preferences.js +++ b/api/js/jsapi/egw_preferences.js @@ -121,6 +121,24 @@ egw.extend('preferences', egw.MODULE_GLOBAL, function() } }, + /** + * Endpoint for push to request reload of preference, if loaded and affected + * + * @param _app app-name of prefs to reload + * @param _account_id _account_id 0: allways reload (default or forced prefs), <0: reload if member of group + */ + reload_preferences: function(_app, _account_id) + { + if (typeof _account_id !== 'number') _account_id = parseInt(_account_id); + if (typeof prefs[_app] === 'undefined' || // prefs not loaded + _account_id < 0 && this.user('memberships').indexOf(_account_id) < 0) // no member of this group + { + return; + } + var request = this.json('EGroupware\\Api\\Framework::ajax_get_preference', [_app]); + request.sendRequest(); + }, + /** * Call context / open app specific preferences function * diff --git a/api/js/jsapi/egw_user.js b/api/js/jsapi/egw_user.js index 490a7a56cc..42d9c50617 100644 --- a/api/js/jsapi/egw_user.js +++ b/api/js/jsapi/egw_user.js @@ -66,7 +66,7 @@ egw.extend('user', egw.MODULE_GLOBAL, function() * Get data about current user * * @param {string} _field - * - 'account_id','account_lid','person_id','account_status', + * - 'account_id','account_lid','person_id','account_status','memberships' * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone' * - 'apps': object with app => data pairs the user has run-rights for * @return {string|array|null} diff --git a/api/src/Accounts.php b/api/src/Accounts.php index 63df1cd3e9..4151043178 100644 --- a/api/src/Accounts.php +++ b/api/src/Accounts.php @@ -411,7 +411,7 @@ class Accounts /** * Get an account as json, returns only whitelisted fields: - * - 'account_id','account_lid','person_id','account_status', + * - 'account_id','account_lid','person_id','account_status','memberships' * - 'account_firstname','account_lastname','account_email','account_fullname','account_phone' * * @param int|string $id @@ -420,11 +420,12 @@ class Accounts function json($id) { static $keys = array( - 'account_id','account_lid','person_id','account_status', + 'account_id','account_lid','person_id','account_status','memberships', 'account_firstname','account_lastname','account_email','account_fullname','account_phone', ); if (($account = $this->read($id))) { + if (isset($account['memberships'])) $account['memberships'] = array_keys($account['memberships']); $account = array_intersect_key($account, array_flip($keys)); } // for current user, add the apps available to him diff --git a/preferences/inc/class.preferences_settings.inc.php b/preferences/inc/class.preferences_settings.inc.php index 9169d429cd..8326b94640 100644 --- a/preferences/inc/class.preferences_settings.inc.php +++ b/preferences/inc/class.preferences_settings.inc.php @@ -122,9 +122,13 @@ class preferences_settings Framework::refresh_opener($msg, null, null, null, null, null, null, $msg_type); } } + // update client-side Api\Preferences in response (only current user/session) + Framework::ajax_get_preference($appname); + + // ask every affected client to reload preferences, if affected ($appname prefs loaded and member of group for group prefs) + $push = new Api\Json\Push($account_id > 0 ? (int)$account_id : Api\Json\Push::ALL); + $push->call('egw.reload_preferences', $appname, $account_id ? (int)$account_id : 0); } - // update client-side Api\Preferences in response - Framework::ajax_get_preference($appname); } if (in_array($button, array('save','cancel'))) {