Problem

I have 'view revisions' turned off for all but administrators, though with editable nodes for anonymous or authenticated users they are seeing the 'View changes' link.

Proposed solution

Make sure the button is only visible to users who have permission.

Comments

joelpittet created an issue. See original summary.

joelpittet’s picture

Status: Active » Reviewed & tested by the community
StatusFileSize
new604 bytes

I'm using the menu callback to aid in calling both the node type check and revision check.

joelpittet’s picture

Status: Reviewed & tested by the community » Needs review

Whoops, not instant RTBC:P

Status: Needs review » Needs work

The last submitted patch, 2: 2829781-2-hide-view-changes.patch, failed testing.

joelpittet’s picture

Status: Needs work » Needs review

Testing suite is on but there are no tests in this module. Setting back to needs review.

ERROR: No valid tests were specified.

  • Alan D. committed a920d10 on 7.x-3.x authored by joelpittet
    Issue #2829781 by joelpittet, Alan D.: 'View changes' button should...
alan d.’s picture

Status: Needs review » Fixed

Thanks. Too funny, only 5 years for someone to pick that up :)

Slightly lazy cp n paste, no other changes: ...(.., $op = 'view')

Potential risk of a PHP notice if there is code that depends on this old invalid logic, I nearly used an #access flag instead. i.e.

  $form['actions']['preview_changes'] = array(
    '#type' => 'submit',
    '#value' => t('View changes'),
    '#weight' => 12,
    '#submit' => array('diff_node_form_build_preview_changes'),
    '#access' => !empty($node->nid) && diff_node_revision_access($node, 'view'),
  );  
joelpittet’s picture

lol, yeah whoops that was lazy, but at least you know both it's value and it's param name:) named params args for the win:D

Thanks for committing that!

alan d.’s picture

Status: Fixed » Needs review

Mmm. Sorry, I was blindly rolling out patches...

Does this make sense? View changes on the node form compares the existing page and what they are about to save. So this has nothing to do with revision access so to speak.

Or am I missing something here?

Without adding more complexity, maybe a hook_permission() with a 'diff view current changes' and using this as a check.

So existing commit with new hook and slight mod.

if (!empty($node->nid) && (user_access('diff view current changes) || diff_node_revision_access($node, 'view')) {

Thoughts?

joelpittet’s picture

Ah sorry, I was confusing things, I thought it was for the page. It totally needs a new permission, 'diff view changes' maybe to be sussinct?

alan d.’s picture

StatusFileSize
new2.78 KB

Thoughts?

Status: Needs review » Needs work

The last submitted patch, 11: diff-2829781-11-view-changes-button-permission.patch, failed testing.

joelpittet’s picture

Status: Needs work » Reviewed & tested by the community

Thanks that looks more straight forward.

You could use the placeholder for the button title in the description too for consistency, leave that to your discretion.

  • Alan D. committed 79e4f34 on 7.x-3.x
    Issue #2829781 by joelpittet, Alan D.: Provide ability to restrict the '...
alan d.’s picture

Title: 'View changes' button should check if user has access to 'view revisions' » Provide ability to restrict the 'View changes' button
Category: Bug report » Feature request
Status: Reviewed & tested by the community » Fixed

I skipped without trying as I thought it would be a bit messy, but it wasn't too bad in hindsight ;)

-      '#description' => t('You can refine access using the "Access <em>View changes</em> button" permission.'),
+      '#description' => t('You can refine access using the "!perm" permission.', array(
+        '!perm' => t('Access %view button', array('%view' => t('View changes'))),
+      )),

Thanks!

  • Alan D. committed 6f2af19 on 7.x-3.x
    Issue #2829781 by joelpittet, Alan D.: Followup - Grant "View changes"...

Status: Fixed » Closed (fixed)

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

shenzhuxi’s picture

Hello...I know this issue has been closed for years. But I still believe user_access('diff view changes') should not only control the display of one button but also the access to node/%node/revisions/%/%. There should be a role-based switch for the whole diff/compare function.