diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 0863570..00dae2b 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -179,6 +179,40 @@ function shortcut_set_edit_access($shortcut_set = NULL) { return FALSE; } + /** + * Access callback for switching the shortcut set assigned to a user account. + * + * @param object $account + * (optional) The user account whose shortcuts will be switched. If not set, + * permissions will be checked for switching the loggedin user's own + * shortcut set. + * + * @return + * TRUE if the current user has access to switch the shortcut set of the + * provided account, FALSE otherwise. + */ +function shortcut_set_switch_access($account = NULL) { + global $user; + + if (user_access('administer shortcuts')) { + // Administrators can switch anyone's shortcut set. + return TRUE; + } + + if (!user_access('switch shortcut sets')) { + // The user has no permission to switch anyone's shortcut set. + return FALSE; + } + + if (!isset($account) || $user->uid == $account->uid) { + // Users with the 'switch shortcut sets' permission can switch their own + // shortcuts sets. + return TRUE; + } + + return FALSE; +} + /** * Access callback for editing a link in a shortcut set. */