Skip to content
Snippets Groups Projects
Commit 2dad9ec0 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2821716 by flocondetoile, anish.a, amateescu, Thew: Fatal error when...

Issue #2821716 by flocondetoile, anish.a, amateescu, Thew: Fatal error when viewing node with content moderation enabled if a module which implements hook_node_grants() is enabled
parent 11b40d7d
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
...@@ -98,7 +98,7 @@ public function convert($value, $definition, $name, array $defaults) { ...@@ -98,7 +98,7 @@ public function convert($value, $definition, $name, array $defaults) {
$latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']); $latest_revision = $this->entityManager->getTranslationFromContext($latest_revision, NULL, ['operation' => 'entity_upcast']);
} }
if ($latest_revision->isRevisionTranslationAffected()) { if ($latest_revision instanceof EntityInterface && $latest_revision->isRevisionTranslationAffected()) {
$entity = $latest_revision; $entity = $latest_revision;
} }
} }
......
...@@ -117,7 +117,9 @@ public function validate($value, Constraint $constraint) { ...@@ -117,7 +117,9 @@ public function validate($value, Constraint $constraint) {
protected function isFirstTimeModeration(EntityInterface $entity) { protected function isFirstTimeModeration(EntityInterface $entity) {
$original_entity = $this->moderationInformation->getLatestRevision($entity->getEntityTypeId(), $entity->id()); $original_entity = $this->moderationInformation->getLatestRevision($entity->getEntityTypeId(), $entity->id());
$original_id = $original_entity->moderation_state; if ($original_entity) {
$original_id = $original_entity->moderation_state;
}
return !($entity->moderation_state && $original_entity && $original_id); return !($entity->moderation_state && $original_entity && $original_id);
} }
......
...@@ -9,6 +9,37 @@ ...@@ -9,6 +9,37 @@
*/ */
class NodeAccessTest extends ModerationStateTestBase { class NodeAccessTest extends ModerationStateTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = [
'content_moderation',
'block',
'block_content',
'node',
'node_access_test_empty',
];
/**
* Permissions to grant admin user.
*
* @var array
*/
protected $permissions = [
'administer content moderation',
'access administration pages',
'administer content types',
'administer nodes',
'view latest version',
'view any unpublished content',
'access content overview',
'use editorial transition create_new_draft',
'use editorial transition publish',
'bypass node access',
];
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
...@@ -17,6 +48,10 @@ protected function setUp() { ...@@ -17,6 +48,10 @@ protected function setUp() {
$this->drupalLogin($this->adminUser); $this->drupalLogin($this->adminUser);
$this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE); $this->createContentTypeFromUi('Moderated content', 'moderated_content', TRUE);
$this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content'); $this->grantUserPermissionToCreateContentOfType($this->adminUser, 'moderated_content');
// Rebuild permissions because hook_node_grants() is implemented by the
// node_access_test_empty module.
node_access_rebuild();
} }
/** /**
...@@ -38,7 +73,24 @@ public function testPageAccess() { ...@@ -38,7 +73,24 @@ public function testPageAccess() {
$edit_path = 'node/' . $node->id() . '/edit'; $edit_path = 'node/' . $node->id() . '/edit';
$latest_path = 'node/' . $node->id() . '/latest'; $latest_path = 'node/' . $node->id() . '/latest';
// Now make a new user and verify that the new user's access is correct.
$user = $this->createUser([
'use editorial transition create_new_draft',
'view latest version',
'view any unpublished content',
]);
$this->drupalLogin($user);
$this->drupalGet($edit_path);
$this->assertResponse(403);
$this->drupalGet($latest_path);
$this->assertResponse(403);
$this->drupalGet($view_path);
$this->assertResponse(200);
// Publish the node. // Publish the node.
$this->drupalLogin($this->adminUser);
$this->drupalPostForm($edit_path, [], t('Save and Publish')); $this->drupalPostForm($edit_path, [], t('Save and Publish'));
// Ensure access works correctly for anonymous users. // Ensure access works correctly for anonymous users.
...@@ -58,12 +110,6 @@ public function testPageAccess() { ...@@ -58,12 +110,6 @@ public function testPageAccess() {
'title[0][value]' => 'moderated content revised', 'title[0][value]' => 'moderated content revised',
], t('Save and Create New Draft')); ], t('Save and Create New Draft'));
// Now make a new user and verify that the new user's access is correct.
$user = $this->createUser([
'use editorial transition create_new_draft',
'view latest version',
'view any unpublished content',
]);
$this->drupalLogin($user); $this->drupalLogin($user);
$this->drupalGet($edit_path); $this->drupalGet($edit_path);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment