I am trying to query for all my users and get their email, Role and UserType
item.usertype does not exist
item.role returns something that is not what I am expecting
Role |
org_user |
org_user |
org_user |
org_user |
org_admin |
org_user
|
I am expecting the name of my Roles as seen below... they are custom roles and I need that to eventually set them up..
How do I get the UserName, UserType, UserRole, UserEmail???
user_list = gis.users.search(query=search_user, max_users=200)
with open(output_csv, 'w', encoding='utf-8') as file:
csvfile = csv.writer(file, delimiter=',', lineterminator='\n')
csvfile.writerow(["Name", # these are the headers; modify according to whatever properties you want in your report
"Role",
"UserType",
"Email"
])
for item in user_list:
csvfile.writerow([item.username, # modify according to whatever properties you want in your report
item.role,
item.usertype,
item.email
])
I do this I get this...
I need the actual text that I am going to provide another script that will create the users.
So I need the Actual User Type of Creator, or Mobile Worker
So I need the Actual Role of Administrator, VDOT_User, VDOT_Publisher of which they are assigned.
the result of 'both' does not tell me anything
for item in user_list:
csvfile.writerow([item.username, # modify according to whatever properties you want in your report
item.role,
item.userType,
item.email
])
I can do this and it actually gives me the correct names.... with the 4th one a custom role
What am I missing.. are they stored differently?
If I was to write and create a user I am assuming I would have to provide one of these role names... But I cannot get them when I am querying for the current users.
<Role name: Viewer, description: Viewer>
<Role name: Data Editor, description: Data Editor>
<Role name: Facilitator, description: Facilitator>
<Role name: Data Editor_VDOT, description: This type of account is meant for data editors.>
rolesList = gis.users.roles.all(max_roles=50)
for role in rolesList:
print(role)
When I print out a list of user roles using user.role it only shows org_user/org_admin where the default "User" and "Admin" roles are being used, and for all of our custom roles it is printing the name correctly. Are you running this from a notebook in ArcGIS Online? And I'm assuming you've gone through the full list of user roles that have been output in your csv and confirmed that there's nothing other than org_user/org_admin/org_viewer?
I am running this from a simple .py file that is being launched by a .bat file. We do not use any default roles. Everything is a custom role. The python file is doing much more than this, but this is part of it
I need a list of the UserName, LastName, Email, userType, Role as seen in the image below.
AND A LIST that I could be able to user to come back and create, modify or delete these users in AGOL.
org_user or org_admin does not tell me the users Role name which is a custom name. Getting a list from gis.users.roles.all is worthless because it’s just a list of available Roles and NOT user specific.
It appears that what is being stored in AGOL User store is NOT what I am seeing in my original post.
It appears I can query the RoleId... This example should how to retrieve the description of the RoleId but NOT the Role ID itself...uggggg
What is the attribute of the Role Object that will give me the actual name
searched_role = gis.users.roles.get_role(item.roleId)
roleName = searched_role.description
print(roleName)
RESULT
"This type of account is meant for data editors, including mobile/field data collectors. This account cannot create content or groups, but can participate in groups, view VDOT content, and edit data shared with them."
BUT
how do I get the Role Name as you can see below <Role name: role1, description: role1>,
I tried:
roleName = searched_role.RoleName
roleName = searched_role.roleName
roleName = searched_role.Role Name
Querying the roleId property of a User returns you the custom roles' ID. You can use this to search for that role to know more details or create another user with the same role:
tiles_pub_user.roleId
'rYzfnni7g5AvFsRz'
searched_role = gis.users.roles.get_role(tiles_pub_user.roleId) searched_role.description
'User that can publish tile layers'
When migrating users from one org to another or even to duplicate an org on new infrastructure, you would go through the process of cloning the users and their roles. For this, you can get the list of roles using the all() method on the RolesManager resource object:
gis.users.roles.all(max_roles=50)
[<Role name: Viewer, description: Viewer>, <Role name: tiles_publisher, description: User that can publish tile layers>, <Role name: role1, description: role1>, <Role name: role1, description: role1>, <Role name: role1, description: role1>, <Role name: role1, description: role1>]
I was going to suggest accessing it via the roleId, if we can get that to work! It should just be
searched_role.name
to return the role name once you have the role object!
Did you ever figure this out? I'm hitting the same wall you were in this post.
Seeing the same issue, but with some success using csv writer to write the role names. Testing with f strings in Python window returns the actual role name for me.
portal_users = gis.users.search(max_users=1000)
for user in portal_users:
print(f"{user.username} - {user.role")
Has this been solved yet? I am running into a similar issue, however, when I have user.role calling to gather the role information, I can see my orgs custom roles associated with the different permission levels. When I include any sort of groups information in my code, that is when the role field starts to just show org_user, org_admin, org_publisher.