Add role to active user

I’ve gone looking but can’t seem to fine the method or proper syntax, to edit a user role assignment. I need to assign a specific role to them.

I see this in the manual

# Retrieve the user we're going to edit.
userToChange = system.user.getUser("default", "george")
 
# Make a change to the user. In this case, we're adding some contact info.
contactInfo = {"email":"ignition_user@mycompany.com","sms": "5551212"}
userToChange.addContactInfo(contactInfo)
 
# Edit the user. Because the user object we're passing in has a user name, the function
# already knows which user to edit.
system.user.editUser("default", userToChange)

Is it as simple as user.addRoles()? if so do I pass in a singular role or do I have to pass in the updated role sequence?

This page in the manual has some relevant examples: system.user.getNewUser - Ignition User Manual 8.1 - Ignition Documentation

Relevant snippet:

# We can add a role. If the role doesn't already exist, user save will fail, depending on user source.
user.addRole("mechanic")
  
# We can add a lot of roles.
roles = ["Administrator", "prisoner"]
user.addRoles(roles)
  
# We can remove a role.
user.removeRole("prisoner")
1 Like

It’s nice that you guys give prisoners login rights

2 Likes