diff --git a/core/core.link_relation_types.yml b/core/core.link_relation_types.yml index 88fea0e31c94b1b067afb2c57f8632037434cab9..fb340274d5a3f4362f6b91e0c533d34c3f636cb2 100644 --- a/core/core.link_relation_types.yml +++ b/core/core.link_relation_types.yml @@ -79,6 +79,9 @@ create-form: current: description: "Refers to a resource containing the most recent item(s) in a collection of resources." reference: '[RFC5005]' +customize-form: + description: "The target URI points to a resource where a submission form for customizing associated resource can be obtained." + reference: '[RFC6861]' derivedfrom: description: 'The target IRI points to a resource from which this material was derived.' reference: '[draft-hoffman-xml2rfc]' diff --git a/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonAnonTest.php b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonAnonTest.php new file mode 100644 index 0000000000000000000000000000000000000000..a1cdf2773c43ed802079a3711eff16260a58afd2 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonAnonTest.php @@ -0,0 +1,30 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; +use Drupal\Tests\rest\Functional\EntityResource\ShortcutSet\ShortcutSetResourceTestBase; + +/** + * @group hal + */ +class ShortcutSetHalJsonAnonTest extends ShortcutSetResourceTestBase { + + use AnonResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['hal']; + + /** + * {@inheritdoc} + */ + protected static $format = 'hal_json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/hal+json'; + +} diff --git a/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonBasicAuthTest.php b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonBasicAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d6cce1d89f363ce5edee52ee07eafc337eea8e0d --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonBasicAuthTest.php @@ -0,0 +1,24 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; + +/** + * @group hal + */ +class ShortcutSetHalJsonBasicAuthTest extends ShortcutSetHalJsonAnonTest { + + use BasicAuthResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + +} diff --git a/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonCookieTest.php b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonCookieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e7bbf40d2e1e980a16b672d3870b2213485f3b33 --- /dev/null +++ b/core/modules/hal/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetHalJsonCookieTest.php @@ -0,0 +1,19 @@ +<?php + +namespace Drupal\Tests\hal\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; + +/** + * @group hal + */ +class ShortcutSetHalJsonCookieTest extends ShortcutSetHalJsonAnonTest { + + use CookieResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonAnonTest.php b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonAnonTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3720ac608c1b5860dc47a42425b1dbde9a65eca9 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonAnonTest.php @@ -0,0 +1,24 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\AnonResourceTestTrait; + +/** + * @group rest + */ +class ShortcutSetJsonAnonTest extends ShortcutSetResourceTestBase { + + use AnonResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonBasicAuthTest.php b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonBasicAuthTest.php new file mode 100644 index 0000000000000000000000000000000000000000..388b9def6f3f6a9c76a5a1a6d422be0549be70a4 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonBasicAuthTest.php @@ -0,0 +1,34 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\BasicAuthResourceTestTrait; + +/** + * @group rest + */ +class ShortcutSetJsonBasicAuthTest extends ShortcutSetResourceTestBase { + + use BasicAuthResourceTestTrait; + + /** + * {@inheritdoc} + */ + public static $modules = ['basic_auth']; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'basic_auth'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonCookieTest.php b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonCookieTest.php new file mode 100644 index 0000000000000000000000000000000000000000..28df3ddfa4c9c09e2a46f00994a1cf5d96fe93ae --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetJsonCookieTest.php @@ -0,0 +1,29 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\ShortcutSet; + +use Drupal\Tests\rest\Functional\CookieResourceTestTrait; + +/** + * @group rest + */ +class ShortcutSetJsonCookieTest extends ShortcutSetResourceTestBase { + + use CookieResourceTestTrait; + + /** + * {@inheritdoc} + */ + protected static $format = 'json'; + + /** + * {@inheritdoc} + */ + protected static $mimeType = 'application/json'; + + /** + * {@inheritdoc} + */ + protected static $auth = 'cookie'; + +} diff --git a/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php new file mode 100644 index 0000000000000000000000000000000000000000..97ae1a66aa15241c637d3da3527f7a28ba71f3e7 --- /dev/null +++ b/core/modules/rest/tests/src/Functional/EntityResource/ShortcutSet/ShortcutSetResourceTestBase.php @@ -0,0 +1,88 @@ +<?php + +namespace Drupal\Tests\rest\Functional\EntityResource\ShortcutSet; + +use Drupal\shortcut\Entity\ShortcutSet; +use Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase; + +/** + * ResourceTestBase for ShortcutSet entity. + */ +abstract class ShortcutSetResourceTestBase extends EntityResourceTestBase { + + /** + * {@inheritdoc} + */ + public static $modules = ['shortcut']; + + /** + * {@inheritdoc} + */ + protected static $entityTypeId = 'shortcut_set'; + + /** + * {@inheritdoc} + */ + protected static $patchProtectedFieldNames = []; + + /** + * The ShortcutSet entity. + * + * @var \Drupal\shortcut\ShortcutSetInterface + */ + protected $entity; + + /** + * {@inheritdoc} + */ + protected function setUpAuthorization($method) { + switch ($method) { + case 'GET': + $this->grantPermissionsToTestedRole(['access shortcuts']); + break; + + case 'POST': + case 'PATCH': + $this->grantPermissionsToTestedRole(['access shortcuts', 'customize shortcut links']); + break; + + case 'DELETE': + $this->grantPermissionsToTestedRole(['administer shortcuts']); + break; + } + } + + /** + * {@inheritdoc} + */ + protected function createEntity() { + $set = ShortcutSet::create([ + 'id' => 'llama_set', + 'label' => 'Llama Set', + ]); + $set->save(); + return $set; + } + + /** + * {@inheritdoc} + */ + protected function getExpectedNormalizedEntity() { + return [ + 'id' => 'llama_set', + 'uuid' => $this->entity->uuid(), + 'label' => 'Llama Set', + 'status' => TRUE, + 'langcode' => 'en', + 'dependencies' => [], + ]; + } + + /** + * {@inheritdoc} + */ + protected function getNormalizedPostEntity() { + // @todo Update in https://www.drupal.org/node/2300677. + } + +} diff --git a/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php index b5ce0e81eb23130ced6568b2ad5d7864b8b8a568..3a55f74999ee1dbf42e343a05e1a8f4ab9c4d41e 100644 --- a/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php +++ b/core/modules/shortcut/src/ShortcutSetAccessControlHandler.php @@ -19,6 +19,8 @@ class ShortcutSetAccessControlHandler extends EntityAccessControlHandler { */ protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) { switch ($operation) { + case 'view': + return AccessResult::allowedIf($account->hasPermission('access shortcuts'))->cachePerPermissions(); case 'update': if ($account->hasPermission('administer shortcuts')) { return AccessResult::allowed()->cachePerPermissions();