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

carnage_ - July 21, 2008 - 16:31

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

nicholas.alipaz - February 4, 2009 - 05:24

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

#3

nicholas.alipaz - February 4, 2009 - 10:12

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

#4

SMonsen - February 9, 2009 - 14:17

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

SMonsen - February 9, 2009 - 14:17

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

cYu - February 12, 2009 - 21:29
Category:support request» feature request

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

cYu - February 13, 2009 - 16:34
Version:6.x-1.3» 6.x-1.4
Status:active» needs review

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.

AttachmentSize
rebuild_permissions.patch 2.7 KB

#8

deekayen - February 13, 2009 - 16:50
Status:needs review» fixed

Patch committed

#9

System Message - February 27, 2009 - 17:00
Status:fixed» closed

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

#10

xarbot - May 26, 2009 - 13:51

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

deekayen - May 26, 2009 - 13:56
Status:closed» postponed (maintainer needs more info)

Please note your Drupal version.

#12

xarbot - May 26, 2009 - 13:59

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

cYu - May 26, 2009 - 14:06

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

xarbot - May 26, 2009 - 14:12

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

xarbot - May 26, 2009 - 14:29

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

Thanks

Xarbot

#16

xarbot - May 26, 2009 - 15:23

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

deekayen - May 26, 2009 - 15:27
Status:postponed (maintainer needs more info)» needs work

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

xarbot - May 26, 2009 - 15:31
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

#19

cYu - May 26, 2009 - 16:29

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

xarbot - May 26, 2009 - 17:19

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

xarbot - May 26, 2009 - 17:54

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

rimu - July 14, 2009 - 09:52

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

 
 

Drupal is a registered trademark of Dries Buytaert.