[support] How to bypass permissions for node_save() ?

Metzler, David metzlerd at evergreen.edu
Wed Mar 23 20:42:32 UTC 2011


Take a look at: 

http://drupal.org/node/218104

which describes how to safely impersonate another user. 




-----Original Message-----
From: support-bounces at drupal.org [mailto:support-bounces at drupal.org] On
Behalf Of Ted
Sent: Wednesday, March 23, 2011 12:28 PM
To: Xavier Bestel
Cc: support at drupal.org
Subject: Re: [support] How to bypass permissions for node_save() ?

On 3/23/2011 12:18 PM, Xavier Bestel wrote:
>>> How can I bypass the permissions system to make node_save() work ?
>>> I'm using Drupal 6.
>> user_access caches perms, otherwise you would be able to temporarily
add
>> a role with 'administer nodes'. Instead, you'll need to swap out the
>> global $user for uid 1 temporarily (and rename your local $user var).
>> After you're done with the node_save, remember to swap the old $user
back.
> Great !
>
> Would something like that work (I'm not a true drupalist;) ?
>
> global $user;
> $usersave = $user;
> $user = user_load(1);
>
> ... do stuff with node_save() ...
>
> $user = $usersave;
At first glance that looks okay. Give it a shot!
-- 
[ Drupal support list | http://lists.drupal.org/ ]


More information about the support mailing list