[development] Assigning user to roles programatically

Mark Fredrickson mfredrickson at ppmns.org
Fri Jan 27 14:57:35 UTC 2006


These functions should be in core. It would make addressing

http://drupal.org/node/40546

trivial. As a general thought, I think roles should be given "first class
status" next to users and nodes. Providing a "role API" would allow the
graceful improvement of the role system, behind the scenes.

In the current scenario roles are usually just treated as attributes of
users, not separate and worthy equals.

Of course, this is just my $.02. I'll spend some time pondering this - I
think 4.8 could make some major gains in this area.

-M

>> 
>> Here are two functions that I used for a customer project that do just that:
>> 
>> function mymodule_role_join($uid, $rid) {
>>    db_query("INSERT INTO {users_roles} (rid, uid) VALUES ('%d',
>> '%d')", $rid, $uid);
>> }
>> 
>> function mymodule_role_leave($uid, $rid) {
>>   db_query("DELETE FROM {users_roles} WHERE rid = %d AND uid = %d", $rid,
>> $uid);
>> }
>> 
>>   



More information about the development mailing list