Documentation
IPS_AddRoleToUser
bool IPS_AddRoleToUser (string $User, string $Role)
Parameters
| User | Name of the user (case-sensitive) |
| Role | Name of the role to be assigned (case-sensitive) |
Returns
If the function succeeds, it returns TRUE, otherwise FALSE.
Description
The function assigns the role Role to the user User. The user thereby receives all permissions of the role. If the @admin role is assigned, the user becomes an administrator. Roles are created with IPS_CreateRole.
This function is only available for licenses that include the RBAC feature (Permission Control). Otherwise it fails with "This function is only available for licenses with the RBAC feature enabled!". If there are more users than the license allows (10 users by default, the @admin user is not counted), it fails with "Your license is currently limited to 10 users. Please consider upgrading the license to more users!" (the number is the limit of the license).
The currently logged in user (see IPS_GetLoggedInUser) must be an administrator, i.e. the @admin user or a user with the @admin role. Otherwise the function fails with "Administrator permissions are required for this action!".
If the role does not exist, the function fails with "Role with name '…' does not exist"; if the user does not exist, with "User with name '…' does not exist". If the role is already assigned, it fails with "User with name '…' already has Role '…' attached". As the @admin user implicitly has all roles, the function also fails with this message for it.
See also: IPS_RemoveRoleFromUser, IPS_UserHasRole
Example
IPS_CreateRole('visu');
IPS_AddRoleToUser('anna', 'visu');