diff --git a/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php index 1ac94bd..6edb4e9 100644 --- a/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php +++ b/core/modules/rest/tests/src/Functional/EntityResource/Shortcut/ShortcutResourceTestBase.php @@ -146,13 +146,10 @@ protected function getExpectedUnauthorizedAccessMessage($method) { switch ($method) { case 'GET': - return "The 'access shortcuts' AND 'customize shortcut links' permissions is required to view this shortcut entity of bundle default."; case 'POST': - return "The 'access shortcuts' AND 'customize shortcut links' permissions is required to create this shortcut entity of bundle default."; case 'PATCH': - return "The 'access shortcuts' AND 'customize shortcut links' permissions is required to update this shortcut entity of bundle default."; case 'DELETE': - return "The 'access shortcuts' AND 'customize shortcut links' permissions is required to delete this shortcut entity of bundle default."; + return "The 'access shortcuts' AND 'customize shortcut links' permissions is required."; default: return parent::getExpectedUnauthorizedAccessMessage($method); } diff --git a/core/modules/shortcut/shortcut.module b/core/modules/shortcut/shortcut.module index 156b491..1d503f6 100644 --- a/core/modules/shortcut/shortcut.module +++ b/core/modules/shortcut/shortcut.module @@ -65,7 +65,10 @@ function shortcut_set_edit_access(ShortcutSetInterface $shortcut_set = NULL) { // Sufficiently-privileged users can edit their currently displayed shortcut // set, but not other sets. They must also be able to access shortcuts. $may_edit_current_shortcut_set = $account->hasPermission('customize shortcut links') && (!isset($shortcut_set) || $shortcut_set == shortcut_current_displayed_set()) && $account->hasPermission('access shortcuts'); - return AccessResult::allowedIf($may_edit_current_shortcut_set)->cachePerPermissions(); + if (!$may_edit_current_shortcut_set) { + return AccessResult::neutral("The 'access shortcuts' AND 'customize shortcut links' permissions is required.")->cachePerPermissions(); + } + return AccessResult::allowed()->cachePerPermissions(); } /** diff --git a/core/modules/shortcut/shortcut.routing.yml b/core/modules/shortcut/shortcut.routing.yml index 333a4c7..1133357 100644 --- a/core/modules/shortcut/shortcut.routing.yml +++ b/core/modules/shortcut/shortcut.routing.yml @@ -58,9 +58,9 @@ entity.shortcut.canonical: path: '/admin/config/user-interface/shortcut/link/{shortcut}' defaults: _entity_form: 'shortcut.default' - _title: 'View' + _title: 'Edit' requirements: - _entity_access: 'shortcut.view' + _entity_access: 'shortcut.update' shortcut: \d+ entity.shortcut.edit_form: diff --git a/core/modules/shortcut/src/ShortcutAccessControlHandler.php b/core/modules/shortcut/src/ShortcutAccessControlHandler.php index c75b3e1..3fe2734 100644 --- a/core/modules/shortcut/src/ShortcutAccessControlHandler.php +++ b/core/modules/shortcut/src/ShortcutAccessControlHandler.php @@ -52,12 +52,7 @@ public static function createInstance(ContainerInterface $container, EntityTypeI */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { if ($shortcut_set = $this->shortcutSetStorage->load($entity->bundle())) { - $access = shortcut_set_edit_access($shortcut_set, $account); - if ($access->isNeutral()) { - $message = sprintf("The 'access shortcuts' AND 'customize shortcut links' permissions is required to %s this shortcut entity of bundle %s.", $operation, $entity->bundle()); - $access = AccessResult::neutral($message)->cachePerPermissions()->addCacheableDependency($shortcut_set); - } - return $access; + return shortcut_set_edit_access($shortcut_set, $account); } // @todo Fix this bizarre code: how can a shortcut exist without a shortcut // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903. @@ -69,11 +64,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter */ protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) { if ($shortcut_set = $this->shortcutSetStorage->load($entity_bundle)) { - $access = shortcut_set_edit_access($shortcut_set, $account); - if ($access->isNeutral()) { - $access = AccessResult::neutral("The 'access shortcuts' AND 'customize shortcut links' permissions is required to create this shortcut entity of bundle $entity_bundle.")->cachePerPermissions()->addCacheableDependency($shortcut_set); - } - return $access; + return shortcut_set_edit_access($shortcut_set, $account); } // @todo Fix this bizarre code: how can a shortcut exist without a shortcut // set? The above if-test is unnecessary. See https://www.drupal.org/node/2339903.