Why can't A Drupal user edit a node they created?

Why can't a Drupal user edit a node they created?

Symptoms: An authorized Drupal user loses "edit" access to nodes they've created, even if they have appropriate node (or other module) access permissions. Or, user cannot edit a node that should be editable by them, based on access control or node access settings. No errors or warnings appear in the Drupal log.

Possible Cause: The user does not have permission to use the input filter assigned to the node. (Input filter permissions may have been changed since the node was created. As a result, the user never had, or no longer has permission to use the input filter associated with the node.)

This excerpt from Drupal node.module node_access() function tells the tale:




function node_access($op, $node = NULL, $uid = NULL) {
// Convert the node to an object if necessary:
if ($op != 'create') {
$node = (object)$node;
}

// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
return FALSE;
}

So, if a node is created by a user with an input filter they once had access to, and the admin later removes access to that filter for the user (or edits the node and selects an input filter that the node owner/creator/editor cannot access), then the user will not be able to edit the node.

No warnings, no watchdog entries, nothing. An associated custom module (if any) hook_access is NOT called with $op='update'. The user just won't see the edit tab, or if the user tries to edit the node by visiting node/x/edit, user will see "access denied" messages.

Solution/workaround: Restore permission for the user to access the filter used when the content was first created (or last edited) OR, have a user (admin) who has access to the filters associated with the node edit the node and set the filter to one that the node creator/owner has access to. This will restore the update permission.

Here's a quick SQL query that shows content created using the nondefault filter and the user ids who created/own them.


SELECT nid, uid, title, format FROM {node_revisions} WHERE format <> {default_filter_id} AND uid <> 1;

Proposal for Drupal Core mod: At a minimum, node_access() function should create a watchdog entry when it rejects an update based on filter_access() returning FALSE. An example enhancement:


// If the node is in a restricted format, disallow editing.
if ($op == 'update' && !filter_access($node->format)) {
watchdog('node_access', "update access rejected for node $node->nid user lacks access to node's current input filter ($node->format)");
return FALSE;
}

Also, when an admin changes filter access permissions, it might be nice to let them know that this may cause users to lose edit access to some or all existing content.

Status: Drupal issue #91663 created

Posted by: Mike on Fri, 10/27/2006 at 12:17pm

Thank you!!!

Thank you for this information!!! I was all confused in my Drupal because none of my users could edit any of their content and I had no idea why, but then when I gave them "administer filters" permission, they were magically able to edit their pages again. Thank you!!!

Stephanie (not verified) – Wed, 05/23/2007 – 12:02pm

Dangerous

Assigning 'administer filters' permission is a dangerous solution - it means that your users can change filter settings. I recommend that you give the users access to the filters used in the specific content, or changing the input filter for the content in question to one that is accessible to the particular users.

Mike – Fri, 05/25/2007 – 10:13pm

still an issue with Drupal 5.1

I thought you might want to know this is still an issue, at least up to version 5.1. Thanks a lot for posting about it because you saved me a lot of troubleshooting time! I suspect it would have taken me a while to figure out the root cause. Luckily it was only a couple dozen pages, so it wasn't too hard to go back and fix manually.

Matt V. (not verified) – Mon, 09/24/2007 – 1:20pm

Yes, it appears to be the case

I submitted an issue on the drupal.org site, and it's still open as far as I can see. I've just updated the issue to suggest a solution. I'll try to come up with a patch.

Mike – Mon, 09/24/2007 – 1:30pm

Thank you so much,

You provided the right solution to a problem I've been trying to solve for a long time!

Philipp (not verified) – Sat, 01/12/2008 – 6:50am

Awesome Post

I just saved myself a ton of headaches with this solution that I was pounding my head against the wall on. Thank you so much. Still an issue up to 5.7

Kenny Silanskas (not verified) – Wed, 06/25/2008 – 6:07pm

Yes, it puzzles me why it's not been fixed...

as far as I can see it's still a problem in 6.x, scheduled for a fix in D7...

Mike – Wed, 06/25/2008 – 7:05pm

Wow, thank you

I've been caught by this twice. Once when I changed the input filter for a particular node (and then found this post), and once when I changed the default filter selection.

The second time, it was part of a big series of site configuration changes, and suddenly none of my users could edit content. It took me an hour before I ended up looking through a diff of MySQL dumps to realize that this was what caused it.

Konstantin (not verified) – Tue, 07/01/2008 – 9:19pm

thank you!

This was EXACTLY what I was looking for. You showed up on the first page for the google search "drupal 6 cannot edit event".

chris (not verified) – Wed, 08/20/2008 – 3:08pm

Thank you!!!

I cannot tell you how much I appreciate your post on this problem. I'm not sure if/when I would have figured it out on my own. Thank you!!

Guest (not verified) – Thu, 09/04/2008 – 6:42am

Thank you

Hi, thank you for this discovery. I just had this problem and didnt figure it out :)

Guest (not verified) – Mon, 11/03/2008 – 3:02am

Post new comment

This helps us decide if you are a human, and not just some visiting bot.
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <h3> <h4> <br> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Lines and paragraphs break automatically.
More information about formatting options