disable edit access for node author

Bacteria Man - December 10, 2008 - 20:57
Project:Nodeaccess
Version:6.x-1.2
Component:Miscellaneous
Category:support request
Priority:normal
Assigned:Unassigned
Status:closed
Issue tags:access control
Description

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?

#1

Bacteria Man - December 10, 2008 - 21:04

I 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.

#2

chadcf - December 10, 2008 - 21:08

You 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.

#3

Bacteria Man - December 11, 2008 - 00:00

Ok, thanks for the confirmation. I've actually got it working.

Update: Oops, spoke too soon. See below.

#4

Bacteria Man - December 10, 2008 - 23:59

Hmm... 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?

#5

chadcf - March 7, 2009 - 23:26
Status:active» closed

If drupal's core permissions allow someone to edit something, then access control modules are not consulted.

#6

magoo - March 18, 2009 - 15:48

My 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:

  • define a permission (hook_perm)
  • define an input filter and assign associated permission (i.e. NOT normal users)
  • in a nodeapi hook, change the input of the main field to the value of the previously created filter.

The result is that Drupal will not enable the edition of a node where the filter value has been set to an unauthorized value.

#7

magoo - March 20, 2009 - 16:11

I finally got time to do this:

in a module (workflow is the name of my module, change it to suite your needs):

<?php
function workflow_install() {
   
// parts taken from php code filter module
   
$format_exists = db_result(db_query("SELECT COUNT(*) FROM {filter_formats} WHERE name = 'workflow_lock'"));
    if (!
$format_exists) {
       
db_query("INSERT INTO {filter_formats} (name, roles, cache) VALUES ('workflow lock', '', 1)");
       
$format = db_result(db_query("SELECT MAX(format) FROM {filter_formats}"));
   
       
$result = db_query("SELECT * from {filters} WHERE format=%d", variable_get('format', 1));
       
        if (
db_affected_rows()){
            while (
$r = db_fetch_object($result)) {
               
db_query("INSERT INTO {filters} (format, module, delta, weight) VALUES (%d, '%s', %d, %d)",
                        
$format, $r->module, $r->delta, $r->weight);
            }
        }
       
drupal_set_message(t('An input format has been created.'));
       
variable_set('workflow_format', $format); // saving id for future uses
   
}
}
?>

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.

<?php
function workflow_perm() {
  return array(
   
'edit locked content', // roles allowed to edit locked content (published on internet or validation requested)
 
);
}

function
workflow_nodeapi(&$node, $op) {


  if (
$op == 'load') {
        if (
CONDITIONS && !user_access('edit locked content')) {
         
$node->format = variable_get('workflow_format', 1);
        }
  }
}
?>

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.

 
 

Drupal is a registered trademark of Dries Buytaert.