Set a default role for newly created users

bsoremsugar —  October 31, 2012 — 1 Comment

Here’s a question that I’ve seen time and time again in the forums…

Is it possible to default permissions for users who are not part of a user role, that is, permissions that are also inherited by other roles as default permissions?

Situation: By default I want some fields to only be writable by a certain group of users. Everyone else should not have access to the change the field value.

I want to avoid creating a default role where I have to add all new users. If it is possible to create a role where users are automatically added, then that might be an option.

This is pretty easy to do with an after_save logic hook on the Users module, triggered each time a new user is created like so…

You can extend this method to specify a series of default roles, or conditions for default roles being applied as well.

Thanks to MrBigAllan in the forums for posting the original solution I based the above example on.

One response to Set a default role for newly created users


    The code above won’t work without this sentence on the top of the page:

    if(!defined(‘sugarEntry’) || !sugarEntry) die(‘Not A Valid Entry Point’);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s