demo_add_participants_as_admins

Portal administration demo

Add participants of this course as administrators to an ArcGIS Enterprise running on Amazon AWS infrastructure.

In [8]:
import pandas as pd
from arcgis.gis import *
from getpass import getpass
In [9]:
url='https://esriwebgis.webgistesting.net/portal'
username='admin'
password = getpass()
········
In [11]:
#sign in to ArcGIS Enterprise
gis = GIS('https://esriwebgis.webgistesting.net/portal', username, password)
gis.users.search()
Out[11]:
[<User username:admin>,
 <User username:Alexander.Mogollon>,
 <User username:atma.mani>,
 <User username:Burt.McAlpine>,
 <User username:Christina.Kellum>,
 <User username:Cynthia.Davis>,
 <User username:David.Mutibul>,
 <User username:David.Pastizzo>,
 <User username:Derek.Hoshijo>,
 <User username:Ellie.Maclin>,
 <User username:esri_boundaries>,
 <User username:esri_demographics>,
 <User username:esri_livingatlas>,
 <User username:esri_nav>,
 <User username:Heinrich.Langenhoven>,
 <User username:Hunter.Allen>,
 <User username:Jeremy.Fontenault>,
 <User username:Kalyana.Nissankarao>,
 <User username:Kanne.Ikwuezunma>,
 <User username:Mathias.Gieser>,
 <User username:Nathan.Heick>,
 <User username:Paul.Haakma>,
 <User username:Rajaram.Gudipudi>,
 <User username:Samuel.Valdez>,
 <User username:Shaunak.Vairagare>,
 <User username:Stan.Shelton>,
 <User username:Timothy.Zimmer>,
 <User username:Vassilo.Walluschnig>,
 <User username:Will.Allender>]

Read the csv with participant names

In [12]:
csv = pd.read_csv('participants.csv')
csv.head()
Out[12]:
First Name Last Name Registrant Company Name Registrant E-Mail Address Unnamed: 4
0 Christina Kellum WA Dept. of Ecology user@test.com NaN
1 Derek Hoshijo E & J Gallo Winery user@test.com NaN
2 Rajaram Gudipudi County of Fresno user@test.com NaN
3 Kalyana Nissankarao Fresno County Sheriff’s Office user@test.com NaN
4 Stan Shelton LOJIC user@test.com NaN
In [5]:
csv
Out[5]:
First Name Last Name Registrant Company Name Registrant E-Mail Address Unnamed: 4
0 Christina Kellum WA Dept. of Ecology user@test.com NaN
1 Derek Hoshijo E & J Gallo Winery user@test.com NaN
2 Rajaram Gudipudi County of Fresno user@test.com NaN
3 Kalyana Nissankarao Fresno County Sheriff’s Office user@test.com NaN
4 Stan Shelton LOJIC user@test.com NaN
5 Mathias Gieser Basin Electric Power Cooperative user@test.com NaN
6 Timothy Zimmer Shelby County 911 District user@test.com NaN
7 Alexander Mogollon Esri Colombia user@test.com NaN
8 Christina Kellum Washington State Dept. of Ecology user@test.com NaN
9 David Pastizzo City of Medford user@test.com NaN
10 Cynthia Davis City of Corona user@test.com NaN
11 David Mutibul esri BeLux user@test.com NaN
12 Kanne Ikwuezunma Allworld Project Management, LLC user@test.com NaN
13 Jeremy Fontenault RPS ASA user@test.com NaN
14 Paul Haakma GPS-it user@test.com NaN
15 Nathan Heick Los Angeles County Sanitation Districts user@test.com NaN
16 Burt McAlpine JULIE Inc. user@test.com NaN
17 Samuel Valdez City and County of San Francisco user@test.com NaN
18 Vassilo Walluschnig Esri South Africa user@test.com NaN
19 Shaunak Vairagare TBG @ NOAA user@test.com NaN
20 Will Allender E. & J. Gallo Winery user@test.com NaN
21 Heinrich Langenhoven GISCOE user@test.com NaN
22 Ellie Maclin Allworld Project Management, LLC user@test.com NaN
23 Hunter Allen NOAA Climate Program Office user@test.com NaN
24 NaN NaN NaN NaN NaN
In [13]:
csv.shape
Out[13]:
(25, 5)

Create users

We are using ‘1’+email address for password

In [7]:
for index, row in csv.iterrows():
    try:
        print('Creating user : {}.{}'.format(row['First Name'], row['Last Name']))
        result = gis.users.create(username = row['First Name'] + "." + row['Last Name'],
                                 password= "1"+ row['First Name']+"."+row['Last Name'],
                                 firstname= row['First Name'],
                                 lastname= row['Last Name'],
                                 email= row['Registrant E-Mail Address'],
                                 role = 'org_admin')
    except Exception as ex:
        print("error: " + str(ex))
Creating user : Christina.Kellum
Creating user : Derek.Hoshijo
Creating user : Rajaram.Gudipudi
Creating user : Kalyana.Nissankarao
Creating user : Stan.Shelton
Creating user : Mathias.Gieser
Creating user : Timothy.Zimmer
Creating user : Alexander.Mogollon
Creating user : Christina.Kellum
java.lang.Exception: The server at 'https://10.0.0.157:7443/arcgis/sharing/rest/community/createUser' returned an error. The user already exists.  Please check the username and try again. []
error: java.lang.Exception: The server at 'https://10.0.0.157:7443/arcgis/sharing/rest/community/createUser' returned an error. The user already exists.  Please check the username and try again. []
(Error Code: 500)
Creating user : David.Pastizzo
Creating user : Cynthia.Davis
Creating user : David.Mutibul
Creating user : Kanne.Ikwuezunma
Creating user : Jeremy.Fontenault
Creating user : Paul.Haakma
Creating user : Nathan.Heick
Creating user : Burt.McAlpine
Creating user : Samuel.Valdez
Creating user : Vassilo.Walluschnig
Creating user : Shaunak.Vairagare
Creating user : Will.Allender
Creating user : Heinrich.Langenhoven
Creating user : Ellie.Maclin
Creating user : Hunter.Allen
Creating user : nan.nan
error: unsupported operand type(s) for +: 'float' and 'str'
Clean up
In [ ]:
for user in gis.users.search():
    # delete user's contents
    for item in user.items():
        try:
            item.delete()
        except:
            print("error deleting " + item.title)
            continue
    #now delete the user
    try:
        user.delete()
    except:
        print("error deleting " + user.username)
        continue
Unable to delete user. Admins cannot delete themselves.
error deleting admin
In [33]:
gis.users.search()
Out[33]:
[<User username:admin>,
 <User username:esri_boundaries>,
 <User username:esri_demographics>,
 <User username:esri_livingatlas>,
 <User username:esri_nav>]
In [ ]: