_node_revision_access() hides the revisions tab if there's only one revision of a node. pwolanin mentioned at Drupalcon that this had been flagged as confusing (not sure who by so this is a bit anecdotal but it doesn't surprise me) - sometimes the tab is there, sometimes it's not. The page works fine if there's only one revision - just lists a single revision, and that way you know that revisions are enabled / that you have access to them etc.

It also saves us a COUNT() query on the node table when viewing nodes.
screenshot_022.png

Comments

catch’s picture

StatusFileSize
new2.08 KB

Patch would help.

catch’s picture

Component: menu system » node system
Bojhan’s picture

Component: node system » menu system

This is a very questionable usability win, I could agree that sometimes it does show up sometimes it doesn't is going to cause some confusion. However the distraction of a somewhat useless tab, when there are no revisions other then the current is just as important. Although I can imagine with large sites or multiple development environments this could be more annoying, still to the user it could cause uneccairy distraction.

Bojhan’s picture

Version: 7.x-dev » 8.x-dev
Component: menu system » node system

Lets see if we can fix this properly in D8.

catch’s picture

Moving this to D8.

arianek’s picture

subscribe (i would love to see this come to fruition, i just found myself scratching my head over why a node lacked a revisions tab, and it took me a few minutes to discover this was the reason.)

kscheirer’s picture

StatusFileSize
new783 bytes

Still seems like a good idea to me too, patch rerolled for HEAD. Saving a database query is always helpful.

johnv’s picture

Title: Always show the revisions tab on node/n pages if users have access to it » Show the node revisions tab/page even when only one revision exists.

Patch #7 works.

Showing the tab is not the only use case:
#940242: Node revision link access
- Views has a "Node revisions: ..." view with links as node/$nid/revisions/$vid/view, which doesn't work for nodes with only one revision.
#138454: "Access Denied" on nodes with no revisions
- This issue handles symptoms if modules Diff and Revision Moderation even back in D5 & D6
#792202: Revisions access denied
- This issue handles the symptom in module Content moderation

johnv’s picture

As Bojhan said

However the distraction of a somewhat useless tab, when there are no revisions other then the current is just as important

Patch #7 now shows the tab for Every node, even if not even one node of that Content Type has a revision. So, for those content types, the Tab 'Revisions' indeed is an overkill.
The Tab only is necessary for entity types for which Revisions are actually used in the site.

Perhaps we need to enhance the "Create new revision" checkbox in the Content type settings:
Change the checkbox to a group of radiobuttons "Create new revision":
- Disabled
- Enabled
or even:
- Disabled
- Enabled, optional, (do not set "Create new revision" to yes on the when editing a node/entity)
- Enabled, optional, (set "Create new revision" to yes on the when editing a node/entity)
- Required (set "Create new revision" to yes - user cannot unset this option)

Or is there a way that you can enter the page from 'outside' and NOT have the tab on the node page when the node only has 1 revision?

johnv’s picture

Another option is to create a more granular permission per node type:
Another issue handles the addition of new permissions to create a more granular permission per node type:
- < Node type: > View content revisions
- < Node type: > Revert content revisions
- < Node type: > Delete content revisions

#880940: view/revert/delete revisions per content type

johnv’s picture

Title: Show the node revisions tab/page even when only one revision exists. » Show the Revisions tab/page even when only one revision exists.
StatusFileSize
new2.7 KB

The initial patch from #7 shows a Revisions tab also for node types that have no revisions at all, which is not desireable - we need some extra work there to fetch the node type. That requires substantial rework of the function, but will be adequately handled by #880940: view/revert/delete revisions per content type.
Attached patch adds a differentiation between list and view :
- node/%node/revisions : list still only access with +1 revisions (this is the Revisions tab)
- node/%node/revisions/%/view : view now allows access, even with only 1 revision (this is accessed from contrib revision links)
- node/%node/revisions/%/revert : as before: only the revision is not the current one
- node/%node/revisions/%/delete: as before: only the revision is not the current one
The patch also saves a DB-query.

#1439336: _node_revision_access is executing an unnecessary query when $op equals 'delete' or 'update' changes the same line of code, and has extensive testing.

Status: Needs review » Needs work

The last submitted patch, node_808730_11_revisions_access.patch, failed testing.

catch’s picture

Issue summary: View changes
berdir’s picture

Issue tags: +Performance

A COUNT() query that is currently badly indexed (at least in D8(, so this would be a performance improvement.

miro_dietiker’s picture

We stumbled upon this issue while porting the diff module. While reviewing the diff port UI, i was confused by the tab behavior.
See also related contrib task: #2424249: Node revision tab visible with only one revision

Anushka-mp’s picture

Status: Needs work » Needs review
StatusFileSize
new1.1 KB

Starting this from the scratch..
Why we just cant remove the check for multiple revisions in the NodeRevisionAccessCheck::checkAccess() ? since all nodes can have revisions. It's not required to check the box "Create new revisions" when creating node content in order to create a revision later. So can we display the revisions tab regardless of it or do we have to depend on the revisions ID?

miro_dietiker’s picture

Uff... So the problem here is that every content type supports revision.
And if we always show the tab, it also appears although revisions are never created (by default) because the "Create new revision" checkbox is never checked.

What we possibly need is
- a "Support revisions" checkbox instead that enables the revisions tab.
-- Without this checkbox set, no one can create a revision per node.
- a second checkbox "Create new revision (by default)" that controls if revisions are created.
-- Still a user can disable this when creating content. Similar to the current checkbox.

berdir’s picture

That would be a new feature then IMHO, which isn't going to happen for 8.0.x.

The only alternative that I can think of is that we show it all the time if revisions are enabled by default, and fall back to the query only if it is not, and then show it only if there are revisions, as it will be the exception.

We still have the query then, but only when it is really needed.

miro_dietiker’s picture

we show it all the time if revisions are enabled by default

Yeah that makes sense to avoid the feature problem...
So trying to summarise the facts:

  • For creating / updating nodes:
    • A node revision is created if this checkbox "create new revision" is set.
    • The checkbox is only visible if a user has "administer nodes" permission.
    • Unprivileged users will create revisions, based on the content type setting "create new revision"
  • Display revision tab...
    • If content type enables revision by default and
      • user has "view all revisions"
      • or user has "view $bundle revisions"
      • or user has "administer nodes"
    • If there is more than one revision stored

Downside is that only if for every single node create/update new revisions are created, we get rid of the count() query pointed out by Berdir.

The proposal above makes the revision tab no more language specific, so there are extra lines to remove in checkAccess.

berdir’s picture

Yes, I'm not sure what the language check there is supposed to do exactly? The revisions are shown/shared across translations, so showing it or not based on the language doesn't make sense?

gábor hojtsy’s picture

Berdir is right, revisions overall are not language specific, so access checking should not depend on language.

berdir’s picture

Ok, the language stuff is because the same access check is used for viewing a specific revision, which would be shown in a specific language then. That makes sense.

Then we should try something similar as the old patches with, with a list operation for overview, where we don't care about the language...

Anushka-mp’s picture

StatusFileSize
new3.11 KB

As discussed with Berdir,
If the revisions checkbox is enabled in content type, then display the revisions tab. unless fall back to the query and checking multiple revisions.

Anushka-mp’s picture

StatusFileSize
new3.01 KB
catch’s picture

I think revisions should be on/off per bundle, not per-save-of-entity, but last attempt to do that died in the quagmire of #218755: Support revisions in different states.

#23 looks OK for now, but a new issue to review the current UI would be nice to look at for 8.1.x.

miro_dietiker’s picture

Still applies. And #24 also looks fine to me as a status quo.

miro_dietiker’s picture

This patch also still applies. Does "OK for now" mean we should set it to RTBC?

shwetaneelsharma’s picture

StatusFileSize
new124.78 KB

Patch "show_the_revisions-808730-24.patch" passes testing.
Result: For both article and basic page content type, revisions tab is displayed only when the "Create new revision" checkbox is checked. The basic problem is also addressed that is revisions tab is displayed only if there is one revision. Attaching screenshot.

gábor hojtsy’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Tests should be updated to reflect the new behavior, so we can be sure we keep it that way. (Like with every behavioral change).

juanse254’s picture

This patch is not working as expected, When creating a revision and the node at the same time the instance the tab doesnt show up. The create revision button is always present as well. Once you delete a previous revision then the tab is shown even if there is only one revision.

juanse254’s picture

Version: 8.0.x-dev » 8.1.x-dev

After discussion with @Berdir and @miro_dietiker this patch would create a new issue since if we enforce the revision tab all the time then if the user didn't enable revisions the issue would not be solved therefore we must enforce that revisions are always active, following CRAP. But this might be a feature that will no be needed all the time. Then this might me worth for discussion on 8.1.x in any case.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.0-beta1 was released on March 2, 2016, which means new developments and disruptive changes should now be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

venugopp’s picture

StatusFileSize
new2.67 KB

patch#11 rerolled for HEAD of 7.x

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

NoRandom’s picture

Any news about this bug/feature for Drupal 7?

In my 7.56 installation I see that the tab is hidden when there is only the initial revision (and that's pretty reasonable in my opinion). The problem is that it's been suggested that this behaviour could be the root cause for links to revisions not working in views:

https://www.drupal.org/project/views/issues/940242

Regards

awm’s picture

StatusFileSize
new1.36 KB

re-rolling for 8.6

awm’s picture

Status: Needs work » Needs review

The last submitted patch, 34: show_the_revisions-808730-34.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 41: show_the_revisions-808730-35.patch, failed testing. View results

awm’s picture

StatusFileSize
new2.61 KB
awm’s picture

Status: Needs work » Needs review
awm’s picture

StatusFileSize
new2.49 KB

The last submitted patch, 45: show_the_revisions-808730-36.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 47: show_the_revisions-808730-37.patch, failed testing. View results

awm’s picture

StatusFileSize
new3.3 KB
awm’s picture

StatusFileSize
new2.81 KB
awm’s picture

Status: Needs work » Needs review
awm’s picture

Status: Needs review » Needs work

The last submitted patch, 51: show_the_revisions-808730-39.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

awm’s picture

StatusFileSize
new6.53 KB

fixing some tests

awm’s picture

StatusFileSize
new9.37 KB

addressing test failures

awm’s picture

StatusFileSize
new9.43 KB

Views was failing the tests because part of the test suit is to create a view of revisions and test the revision link and revision delete handlers.
I Addressed the views test failures by:

  • Link the delete revision to node delete when it's the default revision (original).
  • do not render the revert link for default revision: not an ideal but I could not figure out a better solution
awm’s picture

Status: Needs work » Needs review
dpagini’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs tests
StatusFileSize
new18.66 KB
new16.23 KB
new19.34 KB

Removing "Needs tests" tag b/c I believe that has been addressed.

Code generally looks good to me, and I decided to play around with this a little on simplytest. I created two sites, one with the patch and one without. On both sites, I created a "basic page" with a commit message, published, and my results are below...

On the current 8.6 site, you can see there is no "Revisions" tab listed.

On the patched 8.6 site, you can now see there is a Revisions tab listed when you create the node...

And here is the actual revisions page with the 1 revision:

I believe this patch is accomplishing what the issue summary states, so I'm going to move to RTBC status to get the next round of reviews on the patch.

awm’s picture

Issue tags: -Performance +Performance views integration

added views integration tag.

awm’s picture

Issue tags: -Performance views integration +Performance, +views integration
awm’s picture

StatusFileSize
new9.42 KB
new1.95 KB

fixed few styling issues and comments.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/node/src/Plugin/views/field/RevisionLinkDelete.php
    @@ -20,7 +20,9 @@ class RevisionLinkDelete extends RevisionLink {
    -    return Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $node->getRevisionId()]);
    +    return !$node->isDefaultRevision() ?
    +      Url::fromRoute('node.revision_delete_confirm', ['node' => $node->id(), 'node_revision' => $node->getRevisionId()]) :
    +      Url::fromRoute('entity.node.delete_form', ['node' => $node->id()]);
    

    This feels like quite a big change and not entirely related to issue. Why don't we take the same approach as with the revert and not present a link if it's the default revision. Also if this is the correct behaviour then we need to add a test for this.

  2. +++ b/core/modules/node/src/Plugin/views/field/RevisionLinkRevert.php
    @@ -20,7 +20,24 @@ class RevisionLinkRevert extends RevisionLink {
    +      // @todo: A link to default view node is not an ideal solution.
    

    We need to link a drupal.org issue to address this. Otherwise the @todo will remain there forever.

  3. I think if possible this patch should only make changes that solve the problem of the revision tab being hidden when there is only one revision.
awm’s picture

I see. 1 & 2 can be addressed but as for:

I think if possible this patch should only make changes that solve the problem of the revision tab being hidden when there is only one revision.

Tests would fail without addressing the views issue. So I am not sure what the best course of action is. Should we let the tests fail and open another issue to address views integration?

alexpott’s picture

@awm why do the tests fail?

awm’s picture

@alexpott part of views test is set up a revisions view and test for the delete and revert link handlers. The view can be found here.
As far as I could tell, the test fail because the delete/revert/view links are printed for the default revision:

node/1/revisions/id/delete
node/1/revisions/id/revert

So without changing the views handlers we end up with a view like:
Screenshot: https://i.imgur.com/Wpu8tHK.png

awm’s picture

Status: Needs work » Needs review
berdir’s picture

Status: Needs review » Needs work
+++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php
@@ -119,22 +119,30 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
-      // not good.
-      if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op == 'update' || $op == 'delete')) {
-        $this->access[$cid] = FALSE;
-      }

This part is moved into the else of if shouldCreateNewRevision().

That's the problem. update/delete access is never allowed on the default revision. If views is the only thing that is failing then we seem to have insufficient test coverage.

awm’s picture

StatusFileSize
new6.88 KB

@Berdir, you are right, thank you. This is why views test started failing. I am attaching an updated patch. In it:
1. Added to check if $op == 'view'.
2. I removed views integration added in previous patch.
3. Added testes to verify node/defaulatNodeId/revisions/[revert|delete] are inaccessible.

awm’s picture

Status: Needs work » Needs review
Issue tags: -views integration
awm’s picture

Pascal-’s picture

patch in #69 worked for me on 8.5.3
also working for 8.5.4

awm’s picture

Status: Needs review » Reviewed & tested by the community

putting it in reviewed & tested since it's been tested by #72.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 69: show_the_revisions-808730-69.patch, failed testing. View results

awm’s picture

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

Status: Reviewed & tested by the community » Needs review

Just some nits here, looking great

  1. +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php
    @@ -119,22 +119,30 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
    +      if ($bundle_entity->shouldCreateNewRevision() && $op == 'view') {
    

    Nit, can we use === here because a) we know they're strings and b) this is access code so let's be safe

  2. +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php
    @@ -119,22 +119,30 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
    +        // different revisions so there is no need for a separate database check.
    

    dreditor is showing this as >80 chars

  3. +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php
    @@ -119,22 +119,30 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
    +        if ($node->isDefaultRevision() && ($this->nodeStorage->countDefaultLanguageRevisions($node) == 1 || $op == 'update' || $op == 'delete')) {
    

    same here on ===, I realise this is existing code, but while we're moving it around

  4. +++ b/core/modules/node/src/Access/NodeRevisionAccessCheck.php
    @@ -119,22 +119,30 @@ public function checkAccess(NodeInterface $node, AccountInterface $account, $op
    +          // node passed in is not the default revision then access to that, too.
    

    this one showing as > 80 chars too

dpagini’s picture

StatusFileSize
new6.89 KB
new2.11 KB

Fixing nits. Not changing the status here, but should this really have gone from RTBC > Needs review? Should it go back to RTBC now? I am changing no (minimal, == to ===) logic with the nit fixes.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Yeah, it should've come back to needs work actually. RTBC is only for issues that can go in without any more changes, since this needed changes, Needs work should've been the correct status.

Anyway, back to RTBC!

The last submitted patch, 69: show_the_revisions-808730-69.patch, failed testing. View results

larowlan’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

Can we get a change record here please? thanks

dawehner’s picture

Status: Needs review » Reviewed & tested by the community
Issue tags: -Needs change record
larowlan’s picture

Status: Reviewed & tested by the community » Needs review

Thanks, looks like someone else created one too, but didn't re-rtbc.

I merged the two

Updating issue credits for @miro_dietiker and @Berdir whose input and mentoring shaped the patch.

Crediting @alexpott for review

larowlan’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll

No longer applies since #2996030: Convert web tests to browser tests for node module - round 2

error: core/modules/node/src/Tests/NodeRevisionsTest.php: does not exist in index

kim.pepper’s picture

Status: Needs work » Needs review
StatusFileSize
new6.75 KB

Here's a reroll.

Status: Needs review » Needs work

The last submitted patch, 85: 808730-revisions-tab-85.patch, failed testing. View results

jofitz’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new2.02 KB
new6.93 KB

Re-rerolled #78.

awm’s picture

Status: Needs review » Reviewed & tested by the community

tested patch #87

  • larowlan committed 37c7dfa on 8.7.x
    Issue #808730 by awm, Anushka-mp, dpagini, Jo Fitzgerald, catch, johnv,...
larowlan’s picture

Status: Reviewed & tested by the community » Fixed

Committed as 37c7dfa and pushed to 8.7.x.

Published change record.

Only took us 8 years ;)

Status: Fixed » Closed (fixed)

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

guypaddock’s picture

In our 7.x distribution, we want users to always be able to access the "Revisions" tab even if there is only one revision. So, for our purposes, the original patch all the way back in #7 fits the bill.

Attached is a re-roll of that patch for D7, for anyone else who needs that approach.