Create View with base table of node revisions.

If we have Node revisions: Title field and check "Link this field to its node revision" we have all links as node/$nid/revisions/$vid/view.

If the node has only one revision we will get access denied error clicking on this link because of _node_revision_access() denies access to this path if there is only one revision exists for the node.

Comments

ygerasimov’s picture

Status: Active » Needs review
StatusFileSize
new1.53 KB

I propose to have a check of access with _node_revision_access() and if access is denied change link to node/$nid to display the revision. Please review the patch.

merlinofchaos’s picture

Assigned: Unassigned » dawehner

dereine, can you review this?

dawehner’s picture

The question is what should happen if the user has no access to the revision. Shouldn't the link disappear totally?
This could be configurable.

The code looks fine beside

+      $node_access = (object)array(

(the missing space)

ygerasimov’s picture

StatusFileSize
new1.54 KB

Thank you for the review. I have changed (object)array.

ygerasimov’s picture

StatusFileSize
new3.33 KB

I have added options to substitute link with link to node if user has no access to node revision. Please review the patch.

ygerasimov’s picture

StatusFileSize
new3.37 KB

Tabs problem in patch fixed.

dawehner’s picture

Assigned: dawehner » Unassigned
Status: Needs review » Needs work

Current usage of the handler will brake. You should either convert the existing settings or create other options. Thanks


+      if (!_node_revision_access($node_access, 'view')) {
+		if (!empty($this->options['link_to_node_revision']['substitute'])) {
+		  $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']};
+		}
+		else {
+		  $this->options['alter']['make_link'] = FALSE;
+		}
+      }

Please use spaces instead of tabs here.

The rest looks fine in general.

ygerasimov’s picture

Status: Needs work » Needs review
StatusFileSize
new2.88 KB

Thank you for the review. Please check attached patch. I only add new option 'link_to_node_revision_replace' so I hope it will not break anything existing.

merlinofchaos’s picture

+    $form['link_to_node_revision']['#tree'] = TRUE;
     $form['link_to_node_revision'] = array(
       '#title' => t('Link this field to its node revision'),
       '#description' => t('This will override any other link you have set.'),
       '#type' => 'checkbox',
       '#default_value' => !empty($this->options['link_to_node_revision']),
     );

That can't work. I suspsect the #tree isn't need in the latest patch anyway?


+        if (!empty($this->options['link_to_node_revision_replace'])) {
+          $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']};
+        } else {
+          $this->options['alter']['make_link'] = FALSE;
+        }

Should be

  }
  else {

Also, while it's not your code, but since you're patching this already and it needs to go back for one more reroll, can you fix the code style on this?

       $this->options['alter']['path'] = "node/" . $values->{$this->aliases['nid']} . '/revisions/' . $values->{$this->aliases['vid']} .'/view';

The . operator on the last bit should have spaces to either side. Not sure how I keep letting these little things slip through.

merlinofchaos’s picture

Status: Needs review » Needs work
ygerasimov’s picture

Status: Needs work » Needs review
StatusFileSize
new2.85 KB

Thank you for the review. I also removed second empty line in the end of the file and added empty line before

function option_definition() {

Please review attached patch.

dawehner’s picture

Status: Needs review » Needs work

We could work a bit on the description

If you keep this checkbox unchecked and user has no access to revision link will not be shown.

What about

If you keep this checkbox unchecked and the current user has no access to the revision the link will be hidden.

The rest looks fine.

ygerasimov’s picture

Status: Needs work » Needs review
StatusFileSize
new2.87 KB

Yes, this description looks better.

dawehner’s picture

Status: Needs review » Reviewed & tested by the community

So.

Perhaps you could find a even better one.

merlinofchaos’s picture

Version: 6.x-2.x-dev » 6.x-3.x-dev
Status: Reviewed & tested by the community » Needs work

Patch does not apply to 3.x branch.

NOte that this is a new feature and as such I am unlikely to commit it to 2.x, so let's redo this against 3.x only.

keyano’s picture

Thank you for this patch!

In the latest version of views instead of $values->{$this->aliases['nid']}
$nid = $this->get_value($values, 'nid'); is used, but everything seems to work as expected.

johnv’s picture

Version: 6.x-3.x-dev » 7.x-3.x-dev
Status: Needs work » Closed (duplicate)

This is still the case in D7.

IMO root cause is Drupal core, which disables the page when only one revision exists. It should be dealt with there.
Tagging this as a duplicate of #808730: Show the Revisions tab/page even when only one revision exists.