简体   繁体   中英

Assign multiple roles to a user programmatically in SugarCRM

I am trying to find out how can I assign multiple roles to a user in SugarCRM programmatically. By doing some research I found out that I can utilise role->set_user_relationship() function to do so partially. But it doesn't allow me to pass multiple roles as a parameter.

Ideally I am looking forward for a behavior that allows me to pass an array of role ids. After executing this method it should replace all of the existing assigned roles to user with the new ones. But it seems that this behviour is not supported out of the box, so any guidance/variations int this direction are completely fine.

I had a look at various api resources, but have been unable to find anything useful. Can anyone provide me with suggestions?

Thanks.

I neither used nor viewed codes of this CRM but if you want to set role 1 and role 2 to a new user in a CRM, you should define a new role as role3 , because role usages logic is this. And i guess in the coding side there would be so many parts to be changed to use multiple roles for a new user, so my advice is defining as many roles as you need for every requested authorization level.

This is what I use for add an specific role to an user.

    $role = new ACLRole();
    $role->retrieve($sugar_config['role']['boss']);

    if (!$current_user->check_role_membership($role->name)) {
        // Add user to role, if he/she is not already a member
        $role->set_relationship(
            'acl_roles_users',
            array(
                'role_id' => $role->id,
                'user_id' => $current_user->id
            ),
            false
        );
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM