Hello,

I have well over a thousand nodes on my installation. I have setup all my defaults as follows:
Anon Users: Deny All by default (only 4 pages or so are actually viewable without logging in)
Auth Users: Blank Everything by default (We have more categorized groups)
Paid Users: View all but NO editing
Site Updaters: View, Update Everything, Delete Permissions, And update roles
SuperUser: Same As above

Is there any way to retroactively go back and set these defaults on all of my current nodes? Or do I have to go one by one on each of these? I previously used Taxonomy Access Module, but that module currently doesn't work with D6, so I moved over to this module.

Thanks,
Ram0135

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

carnage_’s picture

i believe that going onto administer >> content settings >> post settings and hitting rebuild permissions will apply permissions to nodes based on their defaults.

This is how I've been getting around it on the site I'm building. I don't know how this will work on a live site though, so might be worth testing on a dev copy first.

nicholas.alipaz’s picture

The rebuild permissions option does not work for forum topics, at least on my site. Anyone have other ideas?

nicholas.alipaz’s picture

When looking the table "drup_node_privacy_byrole" I found that about 1000 nodes from before I installed this module had the incorrect permissions applied to them. Rebuilding would not fix the issue.

I ended up just having to write a quick query and run it on the database to fix the issue on my older content. The newer content is getting it's permissions set properly.

Here is one of the queries I ran. I DON'T SUGGEST RUNNING THIS UNLESS YOU KNOW WHAT YOU ARE DOING!

It simply looks at the 'drup_node' table and checks what type it has assigned then sets the permissions in 'drup_node_privacy_byrole'. Of course there are 3 different columns there 'grant_view', 'grant_update', and 'grant_delete' so I had to run the query 3 times for each role and each content type combination I wanted to alter in mass. But it saved me from editing 1000 nodes.

UPDATE drup_node_privacy_byrole p, drup_node pp
SET p.grant_view = 1
WHERE pp.nid = p.nid
AND pp.type = 'button_post'
AND p.gid = 1
SMonsen’s picture

We have an intranet that has well over 100 posts. I have no idea how to do what nicholas suggested. Is there any other way to update the previous posts?

SMonsen’s picture

We have an intranet that has well over 100 posts. I have no idea how to do what nicholas suggested. Is there any other way to update the previous nodes?

cYu’s picture

Category: support » feature

This could be a feature request for Node Privacy By Role to have a utility that restores all existing nodes to the NPBR default permissions or applies default permissions to all existing nodes when it is enabled, but it is by design that Rebuild Permissions does not set all permissions back to defaults.

Rebuild Permissions is important to use if, for instance, you temporarily use any other module which handles node access but then decide to remove it and want to remove all access that it had given. What you won't want in this case, though, is for all non-default NPBR access to be lost.

cYu’s picture

Version: 6.x-1.3 » 6.x-1.4
Status: Active » Needs review
FileSize
2.7 KB

Attached is a patch which adds a checkbox under the 'Rebuild Permissions' button so that you can save a setting which dictates whether or not NPBR permissions will revert to content type defaults or not during a rebuild.

deekayen’s picture

Status: Needs review » Fixed

Patch committed

Status: Fixed » Closed (fixed)

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

xarbot’s picture

Sorry but this path don't work for me, I check the button that says When rebuilding permissions, reset the node privacy by role permissions on all nodes to the content type defaults.but it don't do nothing, some suggestion?

Thanks in advanced

Xarbot

deekayen’s picture

Status: Closed (fixed) » Postponed (maintainer needs more info)

Please note your Drupal version.

xarbot’s picture

Sorry :P

My Drupal version is 6.10 with npbr last build and with this patch and of course i don't use taxonomy access control ;)

Thanks

Xarbot

cYu’s picture

This might be a matter of usability. Are you checking the checkbox, saving the settings form, and then clicking Rebuild Permissions? If you check the box and then click Rebuild Permissions it will not work. And when you say "it don't do nothing" what are you expecting to happen that is not happening?

xarbot’s picture

Ok, i don't do it correctly. Now i'm check the checkbox and then save it.

After this i rebuild the permissions and.... the system delete all of the permissions of the nodes! Don't rebuild them in function of the permissions defined in content types!

Thanks in advanced

Xarbot

xarbot’s picture

I don't know if i explain correctly my problem now....

Thanks

Xarbot

xarbot’s picture

Ok in this function

function node_privacy_byrole_rebuild_submit($form, &$form_state) {

i add this piece of code

$sql = "SELECT * FROM {node}";
$result = db_query($sql);
while ($row = db_fetch_array($result)) {

$default_permsv =NULL;
$default_permse =NULL;
$default_permsd =NULL;
$default_permsv = _node_privacy_byrole_get_default_roles($row["type"], "view");
$default_permse = _node_privacy_byrole_get_default_roles($row["type"], "edit");
$default_permsd = _node_privacy_byrole_get_default_roles($row["type"], "delete");

$sql2 = "SELECT * FROM {role}";
$result2 = db_query($sql2);
while ($row2 = db_fetch_array($result2)) {
if (in_array ($row2["rid"], $default_permsv)){
$view=1;
}else{
$view=0;
}
if (in_array ($row2["rid"], $default_permse)){
$edit=1;
}else{
$edit=0;
}
if (in_array ($row2["rid"], $default_permsd)){
$delete=1;
}else{
$delete=0;
}
$result3 = db_query("INSERT INTO {node_privacy_byrole} (nid,gid,realm,grant_view,grant_update,grant_delete) VALUES
('".$row["nid"]."','".$row2["rid"]."','node_privacy_byrole','".$view."','".$edit."','".$delete."')");
}
}

after the first line of the function. It's this

db_query('DELETE FROM {node_privacy_byrole}');

probably someone could do a more efficient of code, but i'm not an expert of php :)

and i don't know how can i do a patch, so if someone would like to do....

Bye

Xarbot

deekayen’s picture

Status: Postponed (maintainer needs more info) » Needs work
xarbot’s picture

Status: Needs work » Postponed (maintainer needs more info)

Ok, i do only something to resolve my problem, and if someone could use this code then .... :)

Thanks

Xarbot

cYu’s picture

Xarbot, the code you are writing looks like it intends to delete node_privacy_byrole permissions entirely, deleting both the defaults for the content type as well as the permissions applied to individual nodes. If you'd like to do that, you can disable and uninstall the module.

Am I understanding your intentions correctly or is there something else you are trying to do?

xarbot’s picture

no, the patch submited in this thread delete all the node_privacy_byrole table (see the function node_privacy_byrole_rebuild_submit in the patch).

The only thing i do is rebuild all the table node_privacy_byrole inserting the default values you submit in the content type. I don't know if i explain, my english is not very good :XP

Thanks

Xarbot

xarbot’s picture

I have a bit of time, so i try to explain the code

function node_privacy_byrole_rebuild_submit($form, &$form_state) {
  //Delete all the permissions of all nodes
  db_query('DELETE FROM {node_privacy_byrole}');

  //Select all nodes of the site
  $sql = "SELECT * FROM {node}";
  $result = db_query($sql);
  while ($row = db_fetch_array($result)) {
     //For each node we try to put the default permissions
     //defined in the content type
                $default_permsv =NULL;
                $default_permse =NULL;
                $default_permsd =NULL;
                //We need to know what are the permissions for the type of the node
                //for each default action (view, edit or delete)
                $default_permsv = _node_privacy_byrole_get_default_roles($row["type"], "view");
                $default_permse = _node_privacy_byrole_get_default_roles($row["type"], "edit");
                $default_permsd = _node_privacy_byrole_get_default_roles($row["type"], "delete");

                $sql2 = "SELECT * FROM {role}";
                $result2 = db_query($sql2);
                while ($row2 = db_fetch_array($result2)) {
                        //Now we select all the roles of the site and
                        //for each we see if this role are in the default permissions for this type
                        //Ok, this part could be better, but when i write i hadn't time :P
                        if (in_array ($row2["rid"], $default_permsv)){
                                $view=1;
                        }else{
                                $view=0;
                        }
                        if (in_array ($row2["rid"], $default_permse)){
                                $edit=1;
                        }else{
                                $edit=0;
                        }
                        if (in_array ($row2["rid"], $default_permsd)){
                                $delete=1;
                        }else{
                                $delete=0;
                        }
                        //Now we know for this role what permissions need for this node
                        //based on the permissions defined for this content type
                        $result3 = db_query("INSERT INTO {node_privacy_byrole} (nid,gid,realm,grant_view,grant_update,grant$
                                ('".$row["nid"]."','".$row2["rid"]."','node_privacy_byrole','".$view."','".$edit."','".$del$
                }
  }

}

I said before. The code could be better, and if someone wants to make a patch based in that, i don't have any problem!

Thanks

Xarbot

rimu’s picture

Thank you so much for this feature :) I used to have many many old nodes hidden through my wiki that anonymous users could edit... With predictable problems. No more! :D

ypfuquen’s picture

Hey all,

so is there a patch for this problem??
I'm no sure that wnat I want is to restore my permission to default..

My problem : I create some pages.. then I update my permissions, create roles and give them permissions.. Then i create more pages... When my users log , all permission to the recent pages ( the ones I create after configuring permissions ) are working fine.. but old pages( my initial content) seems not to be taken any change at all.. those pages only my admin can edit them..

How do I apply permissions to my old content??

Helpppp...

AlexisWilke’s picture

Title: Retroactive Permissions? » Retroactive & Default Permissions?
Version: 6.x-1.4 » 6.x-1.5
Category: feature » bug

Hi guys,

Note that in the patch, the npbr_default_permissions variable is handled in the form. It is never checked to know whether the permissions should be rebuilt.

Also as pointed out the permissions were not rebuilt before. They just get deleted. Then when you edit a node it looks like you've got the default permissions, but you actually need to save to really get the permissions in the database.

In other words, thus far this patch was really bad. 8-)

It looks like #21 is close to what would be necessary.

Outside of that, the error that I just mentioned, the defaults not being shown properly exists whenever you

  • add a new role
  • go to your content type and give that role some default permissions
  • edit an existing node of the same type
  • that new role default permissions are shown in the node, but they are actually NOT in the database

In other words, you get a totally wrong feedback from the module.

Saving the node at that point fixes the problem. But you'll have to do that for all the nodes, I'm afraid...

Thank you.
Alexis

AlexisWilke’s picture

Status: Postponed (maintainer needs more info) » Active
FileSize
24.42 KB

Just in case, I am attaching an image when what I see (wrong, on the left side) and what I would expect (since that's what it really is, the users in the marketer role cannot see the nodes until I edit + save them all.)

Thank you.
Alexis

1kenthomas’s picture

Has there been any progress here?

Has this module been duplicated/overlapped by nodeaccess at this point?

AlexisWilke’s picture

1kenthomas,

Looks like someone's working on a 7.x version, but nothing for 6.x... 8-(

Thank you.
Alexis

apprayo’s picture

It seems 6.x-1.6 can set default permission on existing nodes, using these steps: set default permission for a content type, then run "rebuild permission".