Help with UIResponse for system.user.editUser()

Hi!

I'm making a script where you edit the roles of a user.

# Not real code, simplified
def edit_roles(user, role_list):
  user_obj = system.user.getUser("", user)
  user_obj.addRoles(role_list)
  system.user.editUser("", user)
  return

I would like to generate a return message that contains a list of the result of each role execution. I'm not sure on how to do it. :confused:

Something like:

[
  {
    "role": "Role1",
    "result": "OK",
    "message": "Role1 was added correctly."
  },
  {
    "role": "Role2",
    "result": "NOK",
    "message": "Group 'Role2' not found"
  },
  ...
]

I know about the UIResponse, but not sure on how to link it with each role added. The functions getInfos(), getWarns() and getErrors() are not well documented, so I don't know in what case what is returned and how to set it up.

Any idea on how to do this?
Changing things in the code it's okey for me.

Thx in advance!

I asked Inductive. This is more complicated than I thought. I belive I need an inside view of how the code works.
I will post here the response.

roles = system.user.getRoles(userSource)

You may try with: