Retroactive Permissions?
ram0135 - July 19, 2008 - 06:04
| Project: | node privacy byrole |
| Version: | 6.x-1.4 |
| Component: | Code |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | postponed (maintainer needs more info) |
Description
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

#1
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.
#2
The rebuild permissions option does not work for forum topics, at least on my site. Anyone have other ideas?
#3
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 ppSET p.grant_view = 1
WHERE pp.nid = p.nid
AND pp.type = 'button_post'
AND p.gid = 1
#4
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?
#5
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?
#6
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.
#7
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.
#8
Patch committed
#9
Automatically closed -- issue fixed for 2 weeks with no activity.
#10
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
#11
Please note your Drupal version.
#12
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
#13
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?
#14
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
#15
I don't know if i explain correctly my problem now....
Thanks
Xarbot
#16
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
#17
needs code style and sql string replacement
http://drupal.org/patch
http://drupal.org/coding-standards
http://api.drupal.org/api/function/db_query/6
#18
Ok, i do only something to resolve my problem, and if someone could use this code then .... :)
Thanks
Xarbot
#19
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?
#20
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
#21
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
#22
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