Problem/Motivation

In the patch that marks the Workspaces module as stable, we found that the workspace entity type is missing some REST and JSON:API test coverage.

Proposed resolution

Add the missing test coverage.

Remaining tasks

Review.

User interface changes

Nope.

API changes

Nope.

Data model changes

Nope.

Release notes snippet

TBD.

CommentFileSizeAuthor
#49 interdiff-49.txt4.49 KBamateescu
#49 3088870-49.patch24.84 KBamateescu
#48 interdiff-47.txt2.87 KBamateescu
#47 3088870-47.patch24.67 KBamateescu
#38 interdiff-38.txt729 bytesamateescu
#38 3088870-38.patch27.17 KBamateescu
#36 3088870-36.patch27.63 KBjofitz
#27 interdiff-27.txt562 bytesamateescu
#27 3088870-27.patch27.19 KBamateescu
#25 interdiff-25.txt1.09 KBamateescu
#25 3088870-25.patch27.02 KBamateescu
#23 interdiff-23.txt1.76 KBamateescu
#23 3088870-23.patch26.62 KBamateescu
#18 interdiff-18.txt2.07 KBamateescu
#18 3088870-18.patch25.23 KBamateescu
#18 interdiff-18-test-only.txt828 bytesamateescu
#18 3088870-18-test-only.patch24.42 KBamateescu
#16 3088870-16.patch24.97 KBWim Leers
#16 interdiff.txt1.04 KBWim Leers
#15 3088870-15.patch25.16 KBWim Leers
#15 interdiff.txt2.76 KBWim Leers
#13 interdiff-13.txt817 bytesamateescu
#13 3088870-13.patch26.06 KBamateescu
#12 interdiff-12.txt11.33 KBamateescu
#12 3088870-12.patch26.06 KBamateescu
#7 interdiff-7.txt6.89 KBamateescu
#7 3088870-7-combined.patch27.93 KBamateescu
#7 3088870-7.patch27.06 KBamateescu
#6 interdiff_2_6.txt1.22 KBSpokje
#6 3088870-6.patch21.28 KBSpokje
#2 3088870-combined.patch22.12 KBamateescu
#2 3088870.patch21.25 KBamateescu

Issue fork drupal-3088870

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

amateescu created an issue. See original summary.

amateescu’s picture

This should do it. The combined patch includes #3088643-2: Mark Workspaces as a stable core module.

The last submitted patch, 2: 3088870.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 2: 3088870-combined.patch, failed testing. View results

Spokje’s picture

+++ b/core/modules/workspaces/src/WorkspaceAccessControlHandler.php
@@ -19,23 +19,23 @@ class WorkspaceAccessControlHandler extends EntityAccessControlHandler {
    */
   protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
     /** @var \Drupal\workspaces\WorkspaceInterface $entity */
-    if ($account->hasPermission('administer workspaces')) {
-      return AccessResult::allowed()->cachePerPermissions();
-    }
+    $access_result = AccessResult::allowedIfHasPermission($account, 'administer workspaces');
 
     // @todo Consider adding explicit "publish any|own workspace" permissions in
     //   https://www.drupal.org/project/drupal/issues/3084260.
     $permission_operation = ($operation === 'update' || $operation === 'publish') ? 'edit' : $operation;
 
     // Check if the user has permission to access all workspaces.
-    $access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' any workspace');
+    $any_access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' any workspace');
+    $access_result->orIf($any_access_result);


Weirdly (at least to me) it looks like the $access_result->orIf($any_access_result); returns a AccessResultNeutral even when $access_result is AccessResultNeutral and $any_access_result is AccessResultAllowed.


I (and it looks like the code also) was expecting an AccessResultAllowed which would prevent the current fails in this test:
Drupal\workspaces\WorkspaceAccessException: The user does not have permission to view that workspace.

Note to self:
No more posting on d.o before at least 2 coffees.

Spokje’s picture

Let's see how this goes.

Only the non-combined patch for starters (seeing my previous "success" above, let's do baby steps...)

amateescu’s picture

Status: Needs work » Needs review
FileSize
27.06 KB
27.93 KB
6.89 KB

Whoa, that was very stupid of me :) Thanks, @Spokje!

This should fix the rest of the fails.

Status: Needs review » Needs work

The last submitted patch, 7: 3088870-7-combined.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Needs review

That test fail is not related to the REST and JSON:API tests and will be fixed in #3088643: Mark Workspaces as a stable core module, so the non-combined patch is ready for reviews :)

Wim Leers’s picture

Status: Needs review » Needs work
  1. +++ b/core/modules/jsonapi/jsonapi.module
    @@ -319,7 +319,7 @@ function jsonapi_jsonapi_user_filter_access(EntityTypeInterface $entity_type, Ac
    -function jsonapi_jsonapi_workspace_filter_access(EntityTypeInterface $entity_type, $published, $owner, AccountInterface $account) {
    +function jsonapi_jsonapi_workspace_filter_access(EntityTypeInterface $entity_type, AccountInterface $account) {
    

    This … must mean that we're lacking test coverage 😨

  2. +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
    @@ -920,7 +920,9 @@ public function testGetIndividual() {
    -      $this->assertResourceErrorResponse(403, $message, $url, $response, '/data', $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), FALSE, 'MISS');
    +      // MISS or UNCACHEABLE depends on data. It must not be HIT.
    +      $dynamic_cache_header_value = !empty(array_intersect(['user', 'session'], $expected_403_cacheability->getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';
    +      $this->assertResourceErrorResponse(403, $message, $url, $response, '/data', $expected_403_cacheability->getCacheTags(), $expected_403_cacheability->getCacheContexts(), FALSE, $dynamic_cache_header_value);
    

    👍 We have this pattern already in many other places in this test.

  3. +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
    @@ -1076,7 +1078,12 @@ public function testCollection() {
         // MISS or UNCACHEABLE depends on the collection data. It must not be HIT.
    -    $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS';
    +    if (!empty(array_intersect(['user', 'session'], $expected_cacheability->getCacheContexts()))) {
    +      $dynamic_cache = 'UNCACHEABLE';
    +    }
    +    else {
    +      $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS';
    +    }
    
    @@ -1089,6 +1096,13 @@ public function testCollection() {
    +    // MISS or UNCACHEABLE depends on the collection data. It must not be HIT.
    +    if (!empty(array_intersect(['user', 'session'], $expected_cacheability->getCacheContexts()))) {
    +      $dynamic_cache = 'UNCACHEABLE';
    +    }
    +    else {
    +      $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS';
    +    }
    
    @@ -1098,6 +1112,13 @@ public function testCollection() {
    +    // MISS or UNCACHEABLE depends on the collection data. It must not be HIT.
    +    if (!empty(array_intersect(['user', 'session'], $expected_cacheability->getCacheContexts()))) {
    +      $dynamic_cache = 'UNCACHEABLE';
    +    }
    +    else {
    +      $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 ? 'UNCACHEABLE' : 'MISS';
    +    }
    

    We use

        // MISS or UNCACHEABLE depends on the collection data. It must not be HIT.
        $dynamic_cache = $expected_cacheability->getCacheMaxAge() === 0 || !empty(array_intersect(['user', 'session'], $expected_cacheability->getCacheContexts())) ? 'UNCACHEABLE' : 'MISS';
    

    elsewhere in this test.

    🙏 Can you copy/paste that same code in these places, for consistency sake?

  4. +++ b/core/modules/jsonapi/tests/src/Functional/ResourceTestBase.php
    @@ -2001,6 +2024,13 @@ public function testPostIndividual() {
    +        // Entity types with string IDs have to send the entity ID when creating
    +        // the document, but our normalization excludes it from the list of data
    +        // attributes.
    +        if ($field_name === $created_entity->getEntityType()->getKey('id')) {
    +          continue;
    +        }
    

    🤔😅 I … don't understand this. Is "our normalization" the JSON:API normalization or the normalization that the Workspace JSON:API test happens to send in a POST request? It seems like it's the latter? If so, this seems like a hack? Why is it not? (I am sincerely asking, I am having a hard time understanding this — please bear with me.)

  5. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,209 @@
    +  protected static $firstCreatedEntityId = 'updated_campaign';
    ...
    +  protected static $secondCreatedEntityId = 'updated_campaign';
    

    🤔 Why are these the same? This is especially strange because \Drupal\Tests\workspaces\Functional\Rest\WorkspaceResourceTestBase uses

      protected static $firstCreatedEntityId = 'running_on_faith';
    
      protected static $secondCreatedEntityId = 'running_on_faith_2';
    
  6. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,209 @@
    +  protected function setUpAuthorization($method) {
    +    $this->grantPermissionsToTestedRole(['administer workspaces']);
    +  }
    

    🤔 Why doesn't this grant only the create workspace permission in case of POST?

  7. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,209 @@
    +  protected function getPatchDocument() {
    +    $patch_document = parent::getPatchDocument();
    +    unset($patch_document['data']['attributes']['id']);
    +    return $patch_document;
    +  }
    

    🤔 Why does this need to be unset? This is the only entity type that needs this. What makes workspace entities so special?

  8. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,209 @@
    +    $modified['data']['attributes']['id'] = strtolower($this->randomMachineName());
    

    Similar question here.

  9. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,209 @@
    +    // @see \Drupal\media\MediaAccessControlHandler::checkAccess()
    

    🤓 Wrong @see.

  10. +++ b/core/modules/workspaces/src/EntityTypeInfo.php
    @@ -86,6 +86,9 @@ public function entityTypeBuild(array &$entity_types) {
    +    // Workspace entities can not be moderated because they use string IDs.
    +    $entity_types['workspace']->setHandlerClass('moderation', '');
    

    🤔 Can we add an @see here? I can't find any other entity type with such a comment, so it's hard to figure out why string IDs are a problem.

  11. +++ b/core/modules/workspaces/src/WorkspaceAccessControlHandler.php
    @@ -19,23 +19,23 @@ class WorkspaceAccessControlHandler extends EntityAccessControlHandler {
    -    if ($account->hasPermission('administer workspaces')) {
    -      return AccessResult::allowed()->cachePerPermissions();
    -    }
    +    $access_result = AccessResult::allowedIfHasPermission($account, 'administer workspaces');
     
         // @todo Consider adding explicit "publish any|own workspace" permissions in
         //   https://www.drupal.org/project/drupal/issues/3084260.
         $permission_operation = ($operation === 'update' || $operation === 'publish') ? 'edit' : $operation;
     
         // Check if the user has permission to access all workspaces.
    -    $access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' any workspace');
    +    $any_access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' any workspace');
    +    $access_result = $access_result->orIf($any_access_result);
     
         // Check if it's their own workspace, and they have permission to access
         // their own workspace.
         if ($access_result->isNeutral() && $account->isAuthenticated() && $account->id() === $entity->getOwnerId()) {
    -      $access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' own workspace')
    +      $own_access_result = AccessResult::allowedIfHasPermission($account, $permission_operation . ' own workspace')
             ->cachePerUser()
             ->addCacheableDependency($entity);
    +      $access_result = $access_result->orIf($own_access_result);
         }
    

    🤔 These changes look great! But they also seem out of scope. This makes me suspect that this is being changed to fix a (cacheability) bug in the existing workspace access control handler. If so, that should have explicit test coverage. If you disagree: I'd love to hear why, but the argument needs to especially convince a core committer, not me :)

  12. +++ b/core/modules/workspaces/src/WorkspaceAccessControlHandler.php
    @@ -45,7 +45,7 @@ protected function checkAccess(EntityInterface $entity, $operation, AccountInter
       protected function checkCreateAccess(AccountInterface $account, array $context, $entity_bundle = NULL) {
    -    return AccessResult::allowedIfHasPermission($account, 'create workspace');
    +    return AccessResult::allowedIfHasPermissions($account, ['administer workspaces', 'create workspace'], 'OR');
       }
    

    ✅ This seems like a trivial enough bugfix/improvement to be included here.

    🤔 But … it also makes me wonder why administer workspaces does not have restrict access: true set in workspaces.permissions.yml?

  13. +++ b/core/modules/workspaces/tests/src/Functional/Hal/WorkspaceHalJsonTestBase.php
    @@ -0,0 +1,70 @@
    + * Base hal_json test class for the path_alias entity type.
    

    🤓🐛 path_aliasworkspace

    Other than that nitpick these Workspace HAL+JSON tests looks great 👍

  14. +++ b/core/modules/workspaces/tests/src/Functional/Rest/WorkspaceResourceTestBase.php
    @@ -178,16 +172,12 @@ protected function getExpectedUnauthorizedAccessMessage($method) {
         switch ($method) {
           case 'GET':
    -        return "The 'view any workspace' permission is required.";
    -      break;
    -      case 'POST':
    -        return "The 'create workspace' permission is required.";
    -      break;
           case 'PATCH':
    -        return "The 'edit any workspace' permission is required.";
    -      break;
           case 'DELETE':
    -        return "The 'delete any workspace' permission is required.";
    +        return "The 'administer workspaces' permission is required.";
    +      break;
    +      case 'POST':
    +        return "The following permissions are required: 'administer workspaces' OR 'create workspace'.";
           break;
         }
    

    🤔 These changes seem unnecessary?

Wim Leers’s picture

amateescu’s picture

Status: Needs work » Needs review
FileSize
26.06 KB
11.33 KB

@Wim Leers, awesome review, as always :)

Re #10:

  1. Indeed, the missing test coverage is added by this patch: \Drupal\Tests\jsonapi\Functional\WorkspaceTest :)
  2. 👍
  3. Done.
  4. I expanded and tried to clarify that comment. Let me know if it's still confusing.
  5. That's because \Drupal\Tests\jsonapi\Functional\ResourceTestBase::testPostIndividual() uses the return value of ::getPostDocument() for both requests that create a new entity, without explicitly setting the $firstCreatedEntityId and $secondCreatedEntityId variables for the entity ID.

    As mentioned in the expanded comment for point 3. above, entity types with string IDs need to send the ID for the new entity because they don't get a new ID assigned automatically by the database :)

    And this is different than \Drupal\Tests\workspaces\Functional\Rest\WorkspaceResourceTestBase because \Drupal\Tests\rest\Functional\EntityResource\EntityResourceTestBase::testPost() allows you to customize the data for the "second created entity", but the JSON:API counterpart doesn't provide that flexibility:

        $parseable_valid_request_body = $this->serializer->encode($this->getNormalizedPostEntity(), static::$format);
        $parseable_valid_request_body_2 = $this->serializer->encode($this->getSecondNormalizedPostEntity(), static::$format);
    
  6. For no good reason, fixed.
  7. See the reply for 4. and 5. above.
  8. Same here :)
  9. Fixed.
  10. Added a @see and an explanation.
  11. They are indeed out of scope. They were part of my (two-day) attempts to understand \Drupal\Tests\jsonapi\Functional\ResourceTestBase, but they're not really needed for this patch so I reverted them.
  12. Yeah, I hoped that small bugfix would be allowed here since it impacts this missing test coverage directly. And good point about adding restrict access: true for the general administer workspaces permission, I think it is important enough to warrant that special flag.
  13. Fixed.
  14. Yup, reverted those changes.
amateescu’s picture

Meh :)

Wim Leers’s picture

RE #10.4: Worked with @amateescu in Drupal Slack. I now finally understand why this was there. It's because the id field was aliased to drupal_internal__id and he didn't know JSON:API would also respect aliases on POST requests. (If it didn't, that'd make for one hell of a confusing user experience.)

Just making the POST request send that allows the code I was concerned about to be deleted.

That makes this patch a lot easier to understand :)

Wim Leers’s picture

+++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
@@ -0,0 +1,227 @@
+  protected function getModifiedEntityForPostTesting() {
+    $modified = parent::getModifiedEntityForPostTesting();
+    $modified['data']['attributes']['drupal_internal__id'] = strtolower($this->randomMachineName());
+    return $modified;
+  }

The previous interdiff changed this. But we shouldn't need this at all. getModifiedEntityForPostTesting() is smart enough to not generate an entity with the same value for a field that has a uniqueness constraint.

But we need to tell the base test class what fields need to be unique. So doing that. This requires knowing the JSON:API test infrastructure, @amateescu could only have figured this out by diving deeper into the existing tests. So did it for him :)

Wim Leers’s picture

Status: Needs review » Needs work

#12:

IDK about "always" but I sure try :D

  1. 👍 Right! I think it'd be helpful to post a patch without this one hunk — it should fail. That'll prove the test coverage covers this.
  1. See #15 + #16.
  2. See #15 + #16.
  3. See #15 + #16.
  4. 🙏 Ahhhh! Thanks!
  5. Sorry to hear that. 🤐 Yeah this test infrastructure is not trivial to understand, because it requires knowing both Entity/Field API intricacies and assumptions, and JSON:API spec assumptions. We then generically test across entity types where those different assumptions clash, and verify that all things are possible from both of those perspectives.

More detailed patch review based on having dealt with #15 and #16

With #15 and #16, \Drupal\Tests\jsonapi\Functional\WorkspaceTest looks much simpler, making it easier to maintain in the future. That was my goal 🙂 👍

I spotted two more things thanks to that work, and they don't require knowing this test infrastructure in detail:

  1. +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,227 @@
    +          'drupal_internal__id' => 'updated_campaign',
    +          'label' => 'Updated campaign',
    

    It's confusing that the keyword "updated" is used in here, because this is used to create a new workspace. Let's rename that?

  2. We should be able to remove
    +++ b/core/modules/jsonapi/tests/src/Functional/WorkspaceTest.php
    @@ -0,0 +1,223 @@
    +  protected function createAnotherEntity($key) {
    +    $duplicate = $this->getEntityDuplicate($this->entity, $key);
    +    $duplicate->set('id', 'duplicate');
    +    $duplicate->set('field_rest_test', 'Second collection entity');
    +    $duplicate->save();
    +    return $duplicate;
    +  }
    

    because the only reason we have this, is to ->set('id', 'duplicate').

    The proper way to fix this is by adding a createDuplicate() override to \Drupal\workspaces\Entity\Workspace. It should get something like this:

    public function createDuplicate() {
        $duplicate = parent::createDuplicate();
        $duplicate->id->value = $this->id->value . '_duplicate';
        return $duplicate;
      }
    

    That way, it works for all Entity API users, of which the JSON:API module is just one!

amateescu’s picture

@Wim Leers, thanks a lot for helping out with this patch! :)

Here's a test-only patch for #10.1 and another one that fixes both points #17.

The last submitted patch, 18: 3088870-18-test-only.patch, failed testing. View results

Wim Leers’s picture

Status: Needs review » Reviewed & tested by the community

Perfect: my last remarks were fixed and we have a failing test-only patch without the most tricky change.

Regarding that tricky change: The fact that that hasn't been reported yet means that literally nobody has ever tried to access workspace entities using JSON:API 🙃

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 18: 3088870-18.patch, failed testing. View results

Spokje’s picture

Fun stuff, can anybody explain the drupal:9.0.0 part of these failures whilst were testing against 8.9.x?

Drupal\Tests\BrowserTestBase::$defaultTheme is required in drupal:9.0.0 when using an install profile that does not set a default theme. See https://www.drupal.org/node/2352949, which includes recommendations on which theme to use.

amateescu’s picture

Category: Task » Bug report
Status: Needs work » Reviewed & tested by the community
FileSize
26.62 KB
1.76 KB

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 23: 3088870-23.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
27.02 KB
1.09 KB

Missed a spot :)

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 25: 3088870-25.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
27.19 KB
562 bytes

The fails from #25 are identical to the ones exposed by #3093757: Test is marked skipped but shouldn't be anymore, which seems to point to a flaw in JSON:API's base test class.

I'm going to mark that method as skipped just like other JSON:API tests are doing (BlockContentTest, CommentTest, ItemTest, etc.), and the issue referenced above can handle it.

Spokje’s picture

@amateescu Nice catch, was pondering what was going on there.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 3088870-27.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Random fail.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 3088870-27.patch, failed testing. View results

ravi.shankar’s picture

Status: Needs work » Reviewed & tested by the community

As mentioned in comment #30.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 27: 3088870-27.patch, failed testing. View results

jofitz’s picture

Issue tags: +Needs reroll

Patch in #27 no longer applies - Needs Reroll.

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
27.63 KB

Rerolled patch from #27.

Status: Needs review » Needs work

The last submitted patch, 36: 3088870-36.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
FileSize
27.17 KB
729 bytes

Fixed that test fail.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 3088870-38.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

I think that was a random fail.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 3088870-38.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community

Another FunctionalJavascript test failure, not related to this patch.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 38: 3088870-38.patch, failed testing. View results

amateescu’s picture

Status: Needs work » Reviewed & tested by the community
alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/workspaces/src/Entity/Workspace.php
    @@ -185,4 +185,13 @@ public static function postDelete(EntityStorageInterface $storage, array $entiti
    +  /**
    +   * {@inheritdoc}
    +   */
    +  public function createDuplicate() {
    +    $duplicate = parent::createDuplicate();
    +    $duplicate->id->value = $this->id() . '_duplicate';
    +    return $duplicate;
    +  }
    

    This change deserve it's own blocking issue. There's a decent concern we should have about the id() becoming too long - there's a max length of 128. There's also a question about whether we should fix this for all string ID entity types in \Drupal\Core\Entity\ContentEntityBase::createDuplicate()

  2. +++ b/core/modules/workspaces/src/EntityTypeInfo.php
    @@ -83,6 +83,11 @@ public function entityTypeBuild(array &$entity_types) {
    +    // Workspace entities can not be moderated because they use string IDs.
    +    // @see \Drupal\content_moderation\Entity\ContentModerationState::baseFieldDefinitions()
    +    // where the target entity ID is defined as an integer.
    +    $entity_types['workspace']->setHandlerClass('moderation', '');
    

    This seems to be of wider scope than this issue - should it be in its own issue so it can be tested?

  3. +++ b/core/modules/workspaces/workspaces.permissions.yml
    @@ -1,5 +1,6 @@
     administer workspaces:
       title: Administer workspaces
    +  restrict access: TRUE
    

    I think this should be in its own issue - if this wasn't an experimental module this would be a security issue.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

amateescu’s picture

amateescu’s picture

FileSize
2.87 KB

Forgot to attach the interdiff for #47.

amateescu’s picture

FileSize
24.84 KB
4.49 KB

About #45.1, I think my change was wrong and it is the responsibility of the caller to ensure that the entity resulting from createDuplicate() is valid. \Drupal\Tests\jsonapi\Functional\ResourceTestBase::getEntityDuplicate() kind of confirms this since it's setting the ID manually for config entity types.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

quietone’s picture

Status: Postponed » Active

This was postponed on two issues that has noe been closed, changing status.

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 10.1.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amateescu’s picture

Status: Active » Needs review

Rerolled the latest patch and turned it into a MR.

amateescu’s picture

Issue tags: -blocker

The MR is fully ready for reviews now, hiding old patches.

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: +Needs Review Queue Initiative

Using block_content json tests as references and a few other. The test coverage seems to line up with what we've done in others.

LGTM!

catch’s picture

Version: 11.x-dev » 10.3.x-dev
Status: Reviewed & tested by the community » Fixed

I looked at this two or three times and the UNCACHEABLE/MISS changes put me off committing it just yet, but... I can't think of anything else we can do here, and this is in the base class for test coverage that even the subclasses don't directly interact with, it'll make it less likely that the next entity type has to do anything special, then noticed Wim pointing out we already do the same thing elsewhere already in the test coverage. So... committed/pushed to 11.x and cherry-picked to 10.3.x, thanks!

  • catch committed 2e8d4d2a on 10.3.x
    Issue #3088870 by amateescu, Wim Leers, Spokje, jofitz, alexpott: Add...

  • catch committed c815e002 on 11.x
    Issue #3088870 by amateescu, Wim Leers, Spokje, jofitz, alexpott: Add...
catch’s picture

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.