Issue #2062021 by rhm50, InternetDevels: Replace user_access() calls with ->hasPermission() in shortcut module.

8.0.x
webchick 2013-09-04 14:18:30 -07:00
parent 297778513d
commit e2e00fdae4
3 changed files with 15 additions and 12 deletions

View File

@ -23,16 +23,17 @@ class ShortcutSetAccessController extends EntityAccessController {
switch ($operation) { switch ($operation) {
case 'create': case 'create':
case 'update': case 'update':
if (user_access('administer shortcuts', $account)) { if ($account->hasPermission('administer shortcuts')) {
return TRUE; return TRUE;
} }
if (user_access('customize shortcut links', $account)) { if ($account->hasPermission('customize shortcut links')) {
return !isset($entity) || $entity == shortcut_current_displayed_set($account); return !isset($entity) || $entity == shortcut_current_displayed_set($account);
} }
return FALSE; return FALSE;
break; break;
case 'delete': case 'delete':
if (!user_access('administer shortcuts', $account)) { if (!$account->hasPermission('administer shortcuts')) {
return FALSE; return FALSE;
} }
return $entity->id() != 'default'; return $entity->id() != 'default';

View File

@ -27,7 +27,8 @@ use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
* @see shortcut_set_switch_submit() * @see shortcut_set_switch_submit()
*/ */
function shortcut_set_switch($form, &$form_state, $account = NULL) { function shortcut_set_switch($form, &$form_state, $account = NULL) {
global $user; $user = Drupal::currentUser();
if (!isset($account)) { if (!isset($account)) {
$account = $user; $account = $user;
} }
@ -42,7 +43,7 @@ function shortcut_set_switch($form, &$form_state, $account = NULL) {
} }
// Only administrators can add shortcut sets. // Only administrators can add shortcut sets.
$add_access = user_access('administer shortcuts'); $add_access = $user->hasPermission('administer shortcuts');
if ($add_access) { if ($add_access) {
$options['new'] = t('New set'); $options['new'] = t('New set');
} }

View File

@ -12,7 +12,7 @@ use Symfony\Component\HttpFoundation\Request;
* Implements hook_help(). * Implements hook_help().
*/ */
function shortcut_help($path, $arg) { function shortcut_help($path, $arg) {
global $user; $user = Drupal::currentUser();
switch ($path) { switch ($path) {
case 'admin/help#shortcut': case 'admin/help#shortcut':
@ -32,7 +32,7 @@ function shortcut_help($path, $arg) {
case 'admin/config/user-interface/shortcut': case 'admin/config/user-interface/shortcut':
case 'admin/config/user-interface/shortcut/%': case 'admin/config/user-interface/shortcut/%':
if (user_access('switch shortcut sets')) { if ($user->hasPermission('switch shortcut sets')) {
$output = '<p>' . t('Define which shortcut set you are using on the <a href="@shortcut-link">Shortcuts tab</a> of your account page.', array('@shortcut-link' => url("user/{$user->id()}/shortcuts"))) . '</p>'; $output = '<p>' . t('Define which shortcut set you are using on the <a href="@shortcut-link">Shortcuts tab</a> of your account page.', array('@shortcut-link' => url("user/{$user->id()}/shortcuts"))) . '</p>';
return $output; return $output;
} }
@ -171,12 +171,13 @@ function shortcut_admin_paths() {
* otherwise. * otherwise.
*/ */
function shortcut_set_edit_access($shortcut_set = NULL) { function shortcut_set_edit_access($shortcut_set = NULL) {
$account = Drupal::currentUser();
// Sufficiently-privileged users can edit their currently displayed shortcut // Sufficiently-privileged users can edit their currently displayed shortcut
// set, but not other sets. Shortcut administrators can edit any set. // set, but not other sets. Shortcut administrators can edit any set.
if (user_access('administer shortcuts')) { if ($account->hasPermission('administer shortcuts')) {
return TRUE; return TRUE;
} }
if (user_access('customize shortcut links')) { if ($account->hasPermission('customize shortcut links')) {
return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set(); return !isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set();
} }
return FALSE; return FALSE;
@ -195,14 +196,14 @@ function shortcut_set_edit_access($shortcut_set = NULL) {
* provided account, FALSE otherwise. * provided account, FALSE otherwise.
*/ */
function shortcut_set_switch_access($account = NULL) { function shortcut_set_switch_access($account = NULL) {
global $user; $user = Drupal::currentUser();
if (user_access('administer shortcuts')) { if ($user->hasPermission('administer shortcuts')) {
// Administrators can switch anyone's shortcut set. // Administrators can switch anyone's shortcut set.
return TRUE; return TRUE;
} }
if (!user_access('switch shortcut sets')) { if (!$user->hasPermission('switch shortcut sets')) {
// The user has no permission to switch anyone's shortcut set. // The user has no permission to switch anyone's shortcut set.
return FALSE; return FALSE;
} }