Beispiel #1
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])
# 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))])
Beispiel #3
0
if "group" in group:
    groupId = group["group"]["id"]
    arcpy.AddMessage("Creating Users...")
    print "Creating Users..."
    i = 1
    users = []

    while i <= accountNum:
        username = userPrefix + str(i)
        arcpy.AddMessage("creating " + username + "...")
        print "creating " + username + "..."
        agoAdmin.createUser(username, userPassword, userFirstName,
                            userLastName, userEmail, description, roleId,
                            provider)
        users.append(username)
        i += 1
    arcpy.AddMessage("Adding New Users to Group...")
    print "Adding Users to Group..."
    agoAdmin.addUsersToGroups(users, [groupId])
    if instructorAccount:
        arcpy.AddMessage("Reassigning group ownership to " +
                         instructorAccount + "...")
        print "Reassigning group ownership to " + instructorAccount + "..."
        agoAdmin.reassignGroupOwnership(groupId, instructorAccount)
    print "Done"
else:
    arcpy.AddError("Failed to create group")
    arcpy.AddError(group["error"]["details"])
    print "Failed to create group: " + group["error"]["details"]
group = agoAdmin.createGroup(className,classSnippet)
description = "Lab account for " + className

if "group" in group:
    groupId = group["group"]["id"]
    arcpy.AddMessage("Creating Users...")
    print "Creating Users..."
    i = 1
    users = []

    while i <= accountNum:
        username =userPrefix + str(i)
        arcpy.AddMessage("creating " + username + "...")
        print "creating " + username + "..."
        agoAdmin.createUser(username,userPassword,userFirstName,userLastName,userEmail,description,roleId,provider)
        users.append(username)
        i+=1
    arcpy.AddMessage("Adding New Users to Group...")
    print "Adding Users to Group..."
    agoAdmin.addUsersToGroups(users,[groupId])
    if instructorAccount:
        arcpy.AddMessage("Reassigning group ownership to " + instructorAccount + "...")
        print "Reassigning group ownership to " + instructorAccount + "..."
        agoAdmin.reassignGroupOwnership(groupId,instructorAccount)
    print "Done"
else:
    arcpy.AddError("Failed to create group")
    arcpy.AddError(group["error"]["details"])
    print "Failed to create group: " + group["error"]["details"]