Commit 37c7dfa4 authored by larowlan's avatar larowlan

Issue #808730 by awm, Anushka-mp, dpagini, Jo Fitzgerald, catch, johnv,...

Issue #808730 by awm, Anushka-mp, dpagini, Jo Fitzgerald, catch, johnv, venugopp, kim.pepper, kscheirer, miro_dietiker, Berdir, alexpott: Show the Revisions tab/page even when only one revision exists
parent df2865ff
......@@ -119,22 +119,31 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
$this->access[$cid] = FALSE;
return FALSE;
}
// There should be at least two revisions. If the vid of the given node
// and the vid of the default revision differ, then we already have two
// different revisions so there is no need for a separate database check.
// Also, if you try to revert to or delete the default revision, that's
// not good.
if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op == 'update' || $op == 'delete')) {
$this->access[$cid] = FALSE;
}
elseif ($account->hasPermission('administer nodes')) {
// If the revisions checkbox is selected for the content type, display the
// revisions tab.
$bundle_entity_type = $node->getEntityType()->getBundleEntityType();
$bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($bundle);
if ($bundle_entity->shouldCreateNewRevision() && $op === 'view') {
$this->access[$cid] = TRUE;
}
else {
// First check the access to the default revision and finally, if the
// node passed in is not the default revision then access to that, too.
$this->access[$cid] = $this->nodeAccess->access($this->nodeStorage->load($node->id()), $op, $account) && ($node->isDefaultRevision() || $this->nodeAccess->access($node, $op, $account));
// There should be at least two revisions. If the vid of the given node
// and the vid of the default revision differ, then we already have two
// different revisions so there is no need for a separate database
// check. Also, if you try to revert to or delete the default revision,
// that's not good.
if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op === 'update' || $op === 'delete')) {
$this->access[$cid] = FALSE;
}
elseif ($account->hasPermission('administer nodes')) {
$this->access[$cid] = TRUE;
}
else {
// First check the access to the default revision and finally, if the
// node passed in is not the default revision then check access to
// that, too.
$this->access[$cid] = $this->nodeAccess->access($this->nodeStorage->load($node->id()), $op, $account) && ($node->isDefaultRevision() || $this->nodeAccess->access($node, $op, $account));
}
}
}
......
......@@ -239,6 +239,17 @@ public function testRevisions() {
$node->save();
$this->drupalGet("node/" . $node->id() . "/revisions");
// Verify revisions is accessible since the type has revisions enabled.
$this->assertResponse(200);
// Check initial revision is shown on the node revisions overview page.
$this->assertText('Simple revision message (EN)');
// Verify that delete operation is inaccessible for the default revision.
$this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/delete");
$this->assertResponse(403);
// Verify that revert operation is inaccessible for the default revision.
$this->drupalGet("node/" . $node->id() . "/revisions/" . $node->getRevisionId() . "/revert");
$this->assertResponse(403);
// Create a new revision and new log message.
......@@ -261,7 +272,10 @@ public function testRevisions() {
$node->save();
$this->drupalGet("node/" . $node->id() . "/revisions");
$this->assertResponse(403);
// Verify revisions is accessible since the type has revisions enabled.
$this->assertResponse(200);
// Check initial revision is shown on the node revisions overview page.
$this->assertText('Simple revision message (EN)');
// Add a translation in 'DE' and create a new revision and new log message.
$translation = $node->addTranslation('de');
......
......@@ -70,7 +70,8 @@ public function testDisplayRevisionTab() {
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
$this->assertUrl($node->toUrl());
$this->assertNoLink(t('Revisions'));
// Verify revisions exist since the content type has revisions enabled.
$this->assertLink(t('Revisions'));
// Verify the checkbox is checked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
......@@ -82,6 +83,40 @@ public function testDisplayRevisionTab() {
$this->assertUrl($node->toUrl());
$this->assertLink(t('Revisions'));
// Unset page revision setting 'create new revision'. This will mean new
// revisions are not created by default when the node is edited.
$type = NodeType::load('page');
$type->setNewRevision(FALSE);
$type->save();
// Create the node.
$node = $this->drupalCreateNode();
// Verify the checkbox is unchecked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked");
// Submit the form without changing the checkbox.
$edit = [];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
$this->assertUrl($node->toUrl());
// Verify that no link to revisions is displayed since the type
// has the 'create new revision' setting unset.
$this->assertNoLink(t('Revisions'));
// Verify the checkbox is unchecked on the node edit form.
$this->drupalGet('node/' . $node->id() . '/edit');
$this->assertNoFieldChecked('edit-revision', "'Create new revision' checkbox is unchecked");
// Check the 'create new revision' checkbox and save the node.
$edit = ['revision' => TRUE];
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
$this->assertUrl($node->toUrl());
// Verify that the link is displayed since a new revision is created and
// the 'create new revision' checkbox on the node is checked.
$this->assertLink(t('Revisions'));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment