Hello all,
Is there a way to easily assign a new role to ALL users?
We have a situation in which we have 1300 users and we have to add a specific role to ALL.
Thanks a lot
Hello all,
Is there a way to easily assign a new role to ALL users?
We have a situation in which we have 1300 users and we have to add a specific role to ALL.
Thanks a lot
Ciao Marco Ballarin,
I don't think there is a way to do this "easily".
The only thing I can think of is to write a script that will loop through your users records and for each one add the known role_id.
You can do this using the bean if working within the Sugar framework (perhaps with a one-off custom Scheduler):
$link = 'aclroles'; if($userBean->load_relationship($link)){ $userBean->$link->add($role_id); }
You can use SugarQuery to get the user ids, and to get the role_id by name if you don't want to hard-code the role_id.
You could also add a relationship using a POST /Users/:record/link/aclroles/:role_id if you want to do this from outside Sugar.
In bocca al lupo,
FrancescaS
Long time ago in version 6.0 I wrote two logic_hooks on the event after_save in modules Users and ACLRoles which did the following:
1. if a new role was created which starts with "#" all non admin users were linked to this role.
2. if a new non admin user was created, all roles starting with "#" were linked to this user.
By these two hooks we made sure that no new users were created without any role restriction.
One of the #-roles war READONLY which gave only read access to some basic modules.
When a user found out that he had only some basic read access he was ready for the initial CRM training.
Thanks a lot, probably opting for this solution
Harald Kuske thanks for the solution, probably for this scenario i'll continue with the other idea but yours is very smart for other scenarios. For sure i'll use it!
Hello Marco Ballarin
If you are able to access your database you can do the following SQL instruction
INSERT INTO acl_roles_users
(id, role_id, user_id, date_modified, deleted)
SELECT id, :role_id role_id, id user_id, CURRENT_TIMESTAMP() date_modified, 0 deleted FROM users u
so you can skid creating a program you only use once
Have a nice day
While direct inserts may well work, you need to be very cautious and know exactly what you are skipping by doing that.
For example, any associated logic hooks, and I assume process definitions, that would fire when using the proper bean factory would be skipped with direct insert.
Also, in general, there is always the potential for entering garbage into fields via direct insert (though that's true for beans too as things like dropdown lists and required fields are not checked when doing field value assignments), it's what makes API use so challenging and dangerous (see Idea: https://portal.sugarondemand.com/#supp_Bugs/91894 )
There could also be other processes behind the bean that would trigger with BeanFactory use but be skipped with direct insert.
Francesca
Completely right.
That's a good Best Practice I'll take into account from now on.
Thanks