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
df2865ff0e
commit
37c7dfa47c
|
@ -119,22 +119,31 @@ class NodeRevisionAccessCheck implements AccessInterface {
|
||||||
$this->access[$cid] = FALSE;
|
$this->access[$cid] = FALSE;
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
// If the revisions checkbox is selected for the content type, display the
|
||||||
// There should be at least two revisions. If the vid of the given node
|
// revisions tab.
|
||||||
// and the vid of the default revision differ, then we already have two
|
$bundle_entity_type = $node->getEntityType()->getBundleEntityType();
|
||||||
// different revisions so there is no need for a separate database check.
|
$bundle_entity = \Drupal::entityTypeManager()->getStorage($bundle_entity_type)->load($bundle);
|
||||||
// Also, if you try to revert to or delete the default revision, that's
|
if ($bundle_entity->shouldCreateNewRevision() && $op === 'view') {
|
||||||
// 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;
|
$this->access[$cid] = TRUE;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// First check the access to the default revision and finally, if the
|
// There should be at least two revisions. If the vid of the given node
|
||||||
// node passed in is not the default revision then access to that, too.
|
// and the vid of the default revision differ, then we already have two
|
||||||
$this->access[$cid] = $this->nodeAccess->access($this->nodeStorage->load($node->id()), $op, $account) && ($node->isDefaultRevision() || $this->nodeAccess->access($node, $op, $account));
|
// 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 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||||
$node->save();
|
$node->save();
|
||||||
|
|
||||||
$this->drupalGet("node/" . $node->id() . "/revisions");
|
$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);
|
$this->assertResponse(403);
|
||||||
|
|
||||||
// Create a new revision and new log message.
|
// Create a new revision and new log message.
|
||||||
|
@ -261,7 +272,10 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||||
$node->save();
|
$node->save();
|
||||||
|
|
||||||
$this->drupalGet("node/" . $node->id() . "/revisions");
|
$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.
|
// Add a translation in 'DE' and create a new revision and new log message.
|
||||||
$translation = $node->addTranslation('de');
|
$translation = $node->addTranslation('de');
|
||||||
|
|
|
@ -70,7 +70,8 @@ class NodeRevisionsUiBypassAccessTest extends NodeTestBase {
|
||||||
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
|
$this->drupalPostForm('node/' . $node->id() . '/edit', $edit, 'Save');
|
||||||
|
|
||||||
$this->assertUrl($node->toUrl());
|
$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.
|
// Verify the checkbox is checked on the node edit form.
|
||||||
$this->drupalGet('node/' . $node->id() . '/edit');
|
$this->drupalGet('node/' . $node->id() . '/edit');
|
||||||
|
@ -82,6 +83,40 @@ class NodeRevisionsUiBypassAccessTest extends NodeTestBase {
|
||||||
|
|
||||||
$this->assertUrl($node->toUrl());
|
$this->assertUrl($node->toUrl());
|
||||||
$this->assertLink(t('Revisions'));
|
$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'));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue