July 3rd, 2008

Helpers_user: The user API that never was

I was writing an install profile for a out-of-the-box workflow install profile to be used by media organizations today, when I ran into the rote task of adding roles and permissions.

(for reference, see my last article on workflow configuration in drupal)

So being the programmer who will write something in a day which takes an hour to run to save 5 minutes, I decided to scratch a long standing itch:

The Drupal User System API.

I love the simplicity of the drupal user system, but like many things in drupal, it wants you to use forms to admin it, and the DB model is inherently tied to the controller (not good).

So I decided to contribute this to the helpers module. It provides some simple functions like:

helpers_user_help($section)
permissions_get(unknown_type $rid)
permissions_set(unknown_type $rid, unknown_type $perms = array)
role_add(string $name)
role_get(int $rid = 0, string $name = “”)
user_add_roles($uid, $roles = array)
user_delete_roles($uid, $roles = array)

Simple stuff, but AFAIK, lacking in drupal.

In addition, I also wrote a full set of simplete tests for it which can be found in the tests directory.

The patch can be found at:
http://drupal.org/node/252058
Hope others find this helpful!

-Jacob

3 Responses to “Helpers_user: The user API that never was”

  1. Boris Mann says:

    Hi Jacob — good stuff.

    It would be great if this could instead be added to install_profile_api

    It needs porting to D6, so this code (and the tests!) could form the basis for a D6 port…

  2. Robert Douglass says:

    I like where you’re going with this. I wish that we had clear programmatic apis for doing common operations that weren’t coupled directly to forms.

  3. moshe weitzman says:

    good work.

    the user module we now enjoy was built by people like you, one patch at a time. please help make it better by contributing patches. a contrib module like this is ok as a stopgap but lets not lose sight of the goal - this API belongs in core.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

How To find me

Telephone: +1 510.277.0891 | Email: jacobsingh at gmail daht calm

Solution Graphics