# Requires admin role. import csv, time from agoTools.admin import Admin agoAdmin = Admin('<username>') # Replace <username> with your admin username. outputFile = 'c:/temp/users.csv' users = agoAdmin.getUsers() roles = agoAdmin.getRoles() #Make a dictionary of the roles so we can convert custom roles from their ID to their associated name. roleLookup = {} for role in roles: roleLookup[role["id"]] = role["name"] with open(outputFile, 'wb') as output: dataWriter = csv.writer(output, delimiter=',', quotechar='"', quoting=csv.QUOTE_MINIMAL) # Write header row. dataWriter.writerow(['Full Name', 'Email', 'Username', 'Role', 'Date Created']) # Write user data. for user in users: #get role name from the id. If it's not in the roles, it's one of the standard roles so just use it. roleID = user['role'] roleName = roleLookup.get(roleID,roleID) dataWriter.writerow([user['fullName'].encode('utf-8'), user['email'].encode('utf-8'), user['username'].encode('utf-8'),
import sys sys.path.append(r"..\..") from agoTools.admin import Admin if sys.argv[1]=='css': agoAdmin = Admin("user_name_here",password="******") groups=['group_ID_1', 'group_ID_2', 'group_ID_3', 'group_ID_4'] if sys.argv[1]=='sb': agoAdmin = Admin("user_name_here",password="******") groups = ['group_ID_1', 'group_ID_2'] # Enter <groupIDs> of groups to which you want to add new users # User parameters: orgUsers= agoAdmin.getUsers() #group=groups[0] for group in groups: groupUsers= agoAdmin.getUsersInGroup(group) groupUsers= groupUsers["users"] addUsers=[] print len(addUsers) for user in orgUsers: if not user["username"] in groupUsers: print user["username"] addUsers.append(user["username"]) agoAdmin.addUsersToGroups(addUsers, [group])
# Obtain AGOL instance credentials from a non-repo file in this directory. try: from credentials import * except: print "./credentials.py missing" sys.exit(0) # Generate AGOL instance URL from AGOL subdomain. portalURL = 'https://' + agolSubdomain + '.maps.arcgis.com' # Specify credit quota creditQuota = 5000 # Get users agolAdmin = Admin(username,portalURL,password) # Replace <username> with your admin username. users = agolAdmin.getUsers() # Look for users where assignedCredits is -1, and set a quota for them. for user in users: # Does the user have an assignedCredits value assigned? If not, then there is a problem... if u'assignedCredits' in user: # Has no credit quota been set for the user? (-1 means no quota.) if user[u'assignedCredits'] = -1: # Set credit quota print u'Setting creit quota for' + user[u'username'] # TODO: Set the actual quota... else: print user[u'username'] + u'has no assignedCredits value!'
# Requires admin role. import csv, time, datetime from agoTools.admin import Admin # User parameters: agoAdmin = Admin(<username>) # Replace <username> with your admin username. daysToCheck = 7 # Replace with number of days to check...1 checks past day, 7 checks past week, etc. groups = [<groupID1>, <groupID2>, ...] # Enter <groupIDs> of groups to which you want to add new users # Find the group ID with this tool: http://developers.arcgis.com/en/javascript/samples/portal_getgroupamd/ outputDir = 'c:/temp/' # Replace with path for report file outputDate = datetime.datetime.now().strftime("%Y%m%d") # Current date prefixed to filename. outputFile = outputDir + outputDate + '_AddNewUsers2Groups.csv' newUsers = agoAdmin.getUsers(daysToCheck=daysToCheck) userSummary = agoAdmin.addUsersToGroups(newUsers, groups) # print userSummary # Uncomment this line to see a summary of the group additions. # Reports false-negatives as of Nov 5, 2013. with open(outputFile, 'wb') as output: dataWriter = csv.writer(output, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) # Write header row. dataWriter.writerow(['Full Name', 'Email', 'Username', 'Role', 'Date Created']) # Write user data. for user in newUsers: dataWriter.writerow([user['fullName'], user['email'], user['username'], user['role'], time.strftime("%Y-%m-%d", time.gmtime(user['created']/1000))])
from agoTools.admin import Admin try: ##1) Enter ago org admin credentials as comandline parameter or enter them below in after the else###### if len(sys.argv) > 1: adminUsername = sys.argv[1] adminPassword = sys.argv[2] else: adminUsername = "******" adminPassword = "******" ##2) set userType to 'both' to enable Esri Access or 'arcgisonly' to disable userType = "both" -##3) Set constrainDays to a number greater than 0 to filter users created in the last n days. ## Leave set to 0 in to use default 10000 days - constrainDays = 0 #################################### agoAdmin = Admin(adminUsername,password=adminPassword) ##users = agoAdmin.getUsers() if constrainDays: users=agoAdmin.getUsers(daysToCheck=constrainDays) else: users= agoAdmin.getUsers() print str(len(users)) + " users found." for user in users: userName=user["username"] print userName response=agoAdmin.setUserType(userName, userType) except Exception as e: print e