Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Using nodeaccess I have configured access for the node author (of a particular content type) to view and edit their own node. However once a certain condition is meant I need to disable edit access for the node author (of a specific node.)
Any suggestions how to programmatically implement this?
Comments
Comment #1
johnhanley CreditAttribution: johnhanley commentedI should add that changing the perms via a query in hook_nodeapi is easy. I am specifically asking for info on how best to go about it with nodeaccess enabled.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedYou can't do that using the core drupal access functionality, drupal will grant permission as long as there is at least one nodeaccess permission that grants it. To do this you would need to either programatically remove their permission once a condition is met (i.e. delete it from the tables as nodeaccess does) or create another module and do what you need to do there to override it.
Comment #3
johnhanley CreditAttribution: johnhanley commentedOk, thanks for the confirmation. I've actually got it working.
Update: Oops, spoke too soon. See below.
Comment #4
johnhanley CreditAttribution: johnhanley commentedHmm... The permissions in table nodeaccess aren't being enforced.
UPDATE nodeaccess SET grant_update = 0 WHERE nid = 1 AND gid = 3
Record is correctly updated (grant_update = 0) yet the user is allowed to edit the node.
Does the author have edit access to their own node no matter what?
Comment #5
Anonymous (not verified) CreditAttribution: Anonymous commentedIf drupal's core permissions allow someone to edit something, then access control modules are not consulted.
Comment #6
magoo CreditAttribution: magoo commentedMy two cents:
Why is it then possible to configure the author permission in the nodeaccess module? If it is not consulted...
btw, the question does not concern this module in particular but it is still unanswered.
There is, however, a hack possible (just though about it and need to test it) :
in a module:
The result is that Drupal will not enable the edition of a node where the filter value has been set to an unauthorized value.
Comment #7
magoo CreditAttribution: magoo commentedI finally got time to do this:
in a module (workflow is the name of my module, change it to suite your needs):
All this creates an input format of substitution (no role should be allowed to use that format).
I copied the filters associated with the existing format 1 in case it is needed.
Users member of a role having the 'edit locked content' will be able to edit the content.
You must tailor the CONDITION to your needs.
Comment #8
eelkeblokI've tried taking this approach, but unfortunately it has one big caveat. I think it might have been because I did a clear cache between implementing the lock and actually viewing the node I had locked again (not on purpose, it just turned out like that), but I ended up with the node showing its raw input, i.e. no input filters had run. This solution relies on the rendered output being available, because if it isn't, and the input filter is changed at node load, rendering the output will not work, for obvious reasons.
Edit: actually, it seems the content is rendered every time. So, for this to work, it seems the input format needs to be identical to the one it is replacing, except for who is allowed to use it.