Create Users with Python API - Using up licenses during creation of users.

375
5
Jump to solution
03-26-2024 01:56 PM
SGTomlins
New Contributor III

I am using the source code from the API page for cloning.

Clone Portal users, groups and content | ArcGIS API for Python

My particular problem is that the user creation by default sets my "type" to "Creator".  The "New Member Defaults" setting on the target portal is type:"Viewer" and role:"Viewer".

The API documentation I am following:arcgis.gis module | ArcGIS API for Python

The area I am working with:

create(usernamepasswordfirstnamelastnameemailroledescription=Noneprovider='arcgis'idp_username=Nonelevel=2thumbnail=Noneuser_type=Nonecredits=- 1groups=Noneemail_text=None)

Code being executed:

target_user = target_portal.users.create(source_user.username, password, first_name, last_name,
source_user.email, source_user.description , source_user.role)

All this runs and creates the users ("Members") in the portal.  but uses the "Creator" and NOT the "Viewer" type.  The source information evidences that the user is "arcgisonly" among everything else.  This is a listing from the dictionary values from the output of: 

source_users = source.users.search('!esri_ & !admin',max_users=260)
for user in source_users:
print(user.username + "\t:\t" + str(user.role))
for key, value in user.__dict__.items():
print(f"{key}: {value}")

aldermant@ci.janesville.wi.us : org_user
_gis: GIS @ https://maps.ci.janesville.wi.us/portal version:8.2
_portal: <arcgis.gis._impl._portalpy.Portal object at 0x0000020091F49588>
_user_id: aldermant@ci.janesville.wi.us
thumbnail: None
_workdir: C:\Users\tomlinss\AppData\Local\Temp
_hydrated: True
username: aldmant@ci.janesville.wi.us
id: 29209e609def4612998914944768e99d
fullName: Trderman
firstName: Tra
lastName: rman
preferredView: None
description: None
email: aldeant@ci.janesille.wi.us
userType: arcgisonly
idpUsername: aldeant@ci.janelle.wi.us
favGroupId: 47210944c0fc4783b1dfc0bbdb0a882a
lastLogin: -1
mfaEnabled: False
validateUserProfile: True
access: public
storageUsage: 22101499
storageQuota: 10995116277760
orgId: 0123456789ABCDEF
role: org_user
privileges: ['portal:user:joinGroup', 'portal:user:viewOrgGroups', 'portal:user:viewOrgItems', 'portal:user:viewOrgUsers', 'premium:user:demographics', 'premium:user:elevation', 'premium:user:geocode', 'premium:user:networkanalysis']
adminCategories: []
roleId: iAAAAAAAAAAAAAAA
level: 1
userLicenseTypeId: viewerUT
disabled: False
tags: []
culture: en-US
cultureFormat: us
region: None
units: english
created: 1683063913118
modified: 1683063943058
provider: enterprise
groups: [{'id': 'c5aa36caa6534a8dbf3cd6bdfff83870', 'title': 'City Employees Maps and Apps', 'isInvitationOnly': True, 'owner': 'GIS_Admin', 'description': None, 'snippet': 'City Employees Maps and Apps. Our current Geocortex Essentials City Employees website requires an individual portal user for each staff member in order to access the site.\n', 'tags': ['City Employees', 'Geocortex Essentials'], 'phone': None, 'sortField': 'title', 'sortOrder': 'asc', 'isViewOnly': False, 'thumbnail': None, 'created': 1683063248170, 'modified': 1683226178816, 'access': 'org', 'capabilities': [], 'isFav': False, 'isReadOnly': False, 'protected': True, 'autoJoin': False, 'notificationsEnabled': False, 'provider': None, 'providerGroupName': None, 'leavingDisallowed': True, 'hiddenMembers': True, 'membershipAccess': 'org', 'displaySettings': {'itemTypes': ''}, 'userMembership': {'username': 'aldermant@ci.janesville.wi.us', 'memberType': 'member'}}]

 

These are the setting of my source and destination portals.

source   {'role': 'iAAAAAAAAAAAAAAA', 'userLicenseType': 'viewerUT', 'groups': ['e63f5cd74ea04cd691a05e4c84922236'], 'userType': None, 'apps': [], 'appBundles': []}

target    {'role': 'iAAAAAAAAAAAAAAA', 'userLicenseType': 'viewerUT', 'groups': ['19c30fa791c24145ad417115fcb2bbab'], 'userType': None, 'apps': [], 'appBundles': []}

 

Can someone please point me to why the creation of new users is ignoring the defaults, and possible why the cloning operation is ignoring the source user type and role..

Thank you...

1 Solution

Accepted Solutions
SGTomlins
New Contributor III

I got this to work, but it forces all created users to be type: "Viewer" and role: "Viewer".

This is a workaround solution... not an actual cloning..

target_user = target_portal.users.create(source_user.username,
password,
first_name,
last_name,
source_user.email,
source_user.description,
role = "iAAAAAAAAAAAAAAA",
user_type = "Viewer"
)

Still wondering on how to get source users values to actually "clone" the environment.  

I will look at the dictionary values and see if I can grab the right ones? ? ? ? ? ? 

View solution in original post

0 Kudos
5 Replies
HenryLindemann
Esri Contributor

Hi @SGTomlins in your script you have level=2 this is a creator type.

Kind Regards

Henry

0 Kudos
SGTomlins
New Contributor III

Hi Henry,

The level=2 in the code snippet is from the ESRI API example.  I tried level=1 during the many run-break-fix cycles.  It failed too.  I tried this:

target_user = target_portal.users.create(source_user.username,
password,
first_name,
last_name,
source_user.email,
source_user.description,
source_user.role,
user_type= "Viewer"
)

But I get the following:

The user's role does not allow the specified user type to be set.
(Error Code: 500)
Unable to create user balcha@ci.janesville.wi.us

My user role returns "org_user".   I can't find a lower role with the presumption that "org_user" is a step above "org_viewer".  hence not being able to have a role of Viewer with a user that can edit.

Why does the user creation ignore the defaults when I specify neither role or type?

How can I avoid the conflict of user/role in the target using the "users.create" ?

The source portal users are type: viewer and role: viewer.  The values returned to apply to the target portal users do not appear to match....  ???  

-Steve

0 Kudos
SGTomlins
New Contributor III

I got this to work, but it forces all created users to be type: "Viewer" and role: "Viewer".

This is a workaround solution... not an actual cloning..

target_user = target_portal.users.create(source_user.username,
password,
first_name,
last_name,
source_user.email,
source_user.description,
role = "iAAAAAAAAAAAAAAA",
user_type = "Viewer"
)

Still wondering on how to get source users values to actually "clone" the environment.  

I will look at the dictionary values and see if I can grab the right ones? ? ? ? ? ? 

0 Kudos
JakeSkinner
Esri Esteemed Contributor

@SGTomlins you can take a look at the scripts here.  They have examples of creating users accounts.

SGTomlins
New Contributor III

Thanks Jake..  I will take a look at those....   🙂

0 Kudos