parser.add_argument('-folder', '--folder')

args = parser.parse_args()

if args.user == None:
    args.user = _raw_input("Username:"******"Portal: ")

args.portal = str(args.portal).replace("http://","https://")

if args.folder == None:
    args.folder = _raw_input("Folder (optional): ")

agoAdmin = Admin(args.user,args.portal,args.password)

if args.url == None:
    args.url= _raw_input("Query URL: ")

if args.file == None:
    args.file = _raw_input("Output CSV: ")

folderid = None
if args.folder!= None and args.folder!='':
    fid = agoAdmin.getFolderID(args.folder)
    args.folder=fid
    folderid = '/' + args.folder

catalog = agoAdmin.findItemsWithURLs(args.url,folderid)
Example #2
0
#### Search for all content owned by a specific user (admin view)

from agoTools.admin import Admin
import agoTools.utilities

myAgo = Admin(username=<username>, password=<password>) # replace with your username and password
search = agoTools.utilities.searchPortal(myAgo.user.portalUrl, query='owner: username', token=myAgo.user.token)

print search
Example #3
0
#### Migrate person to a new account within the same Org

# Requires admin role
# Useful when migrating to Enterprise Logins.
# Reassigns all items/groups to new owner and
# adds userTo to all groups which userFrom is a member.'''

from agoTools.admin import Admin
myAgol = Admin('<username>')  # Replace <username> your ADMIN account

# for migrating a single account...
myAgol.migrateAccount(myAgol, '<userFrom>', '<userTo>')   # Replace with usernames between which you are moving items

# for migrating a batch of accounts...
myAgol.migrateAccounts(myAgol, <path to user mapping CSV>)   # Replace with path to CSV file with col1=userFrom, col2=userTo
Example #4
0
### Lists out the admins and members of the first group found by the 
### specified search term.

from agoTools.admin import Admin

username = '******'
password = '******'
groupSearch = 'Mission Operations'

myAdmin = Admin(username=username, password=password)
groupInfo = myAdmin.findGroup(groupSearch)
groupMembers = myAdmin.getUsersInGroup(groupInfo['id'])

print('Users in {}'.format(groupInfo['title']))
for admin in groupMembers['admins']:
    print('    {} - Admin'.format(admin))
for user in groupMembers['users']:
    print('    {} - Member'.format(user))
Example #5
0
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])
Example #6
0
    ##  Basic = desktopBasicN
    ##  Standard = destkopStdN
    ##  Advanced = desktopAdvN
    ##Extensions (add all that apply):
    ##   Spatial Analyst = SpatialAnalystN
    ##   3D Analyst = 3DAnalystN
    ##   Network Analyst = 3DnetworkAnalystN
    ##   Geostatistical Analyst = geostatAnalystN
    ##   Data Reviewer: dataReviewerN
    ##   Workflow Manager: workflowMgrN
    ##   Data Interoperability: dataInteropN
    ####################################
    userEntitlements = ["desktopAdvN","3DAnalystN","dataReviewerN","geostatAnalystN","networkAnalystN","spatialAnalystN","workflowMgrN","dataInteropN"]


    agoAdmin = Admin(adminUsername,password=adminPassword)

    users = agoAdmin.getUsers()
    ents = agoAdmin.getEntitlements()
    newUsers = []
    for user in users:
        if overwriteAll == False:
            found = False
            for ent in ents:
                if user["username"] == ent["username"]:
                    found = True
                    break
            if found == False:
                newUsers.append(user)
           ## print user["username"]
        else:
Example #7
0
##Unicode is not encoding properly so convert all arcpy params
adminAccount = str(adminAccount)
adminPassword = str(adminPassword)
className = str(className)
classSnippet = str(classSnippet)
userPrefix = str(userPrefix)
userPassword = str(userPassword)
userEmail = str(userEmail)
userFirstName = str(userFirstName)
userLastName = str(userLastName)
userRole = str(userRole)
provider = str(provider)

arcpy.AddMessage("Logging in...")
try:
    agoAdmin = Admin(adminAccount, password=adminPassword)
except:
    arcpy.AddError(
        "Login failed. Please re-enter your admin username and password.")
    sys.exit()

##Get roles from the portal so we can translate the user-entered name to the role id that the api needs.
##Also confirm that the user-entered role is valid.
allRoles = agoAdmin.getRoles()
##getRoles doesn't return predefined system roles, so we'll add those
roles = {
    'Administrator': 'org_admin',
    'Publisher': 'org_publisher',
    'Author': 'org_author',
    'User': '******'
}
Example #8
0
# 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!'
Example #9
0
# 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'), roleName,
Example #10
0
# Requires admin role.
import csv, time, urllib, json
from agoTools.admin import Admin
 
agoAdmin = Admin('oevans') # Replace <username> with your admin username.
token = agoAdmin.user.token
 
# Requests first 100 invitations, script must be modified if >100 needed
request = 'https://www.arcgis.com/sharing/rest/portals/self/invitations?f=json&start=1&num=100&token=' + token
response = urllib.urlopen(request).read()
invites = json.loads(response)['invitations']
 
outputFile = 'c:/temp/ArcGISOnline_PendingInvitations.csv'
 
with open(outputFile, 'wb') as output:
    dataWriter = csv.writer(output, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
    # Write header row.
    dataWriter.writerow(['Email', 'Username (if pre-defined)', 'Role', 'Invited by', 'Date Invited'])
    # Write user data.
    for invite in invites:
        dataWriter.writerow([invite['email'], invite['username'], invite['role'], invite['fromUsername'], time.strftime("%Y-%m-%d",time.gmtime(invite['created']/1000))])