Ejemplo n.º 1
0
def _handle_response(res, stype, gis, as_dict):
    """
    Handles returning the data in the proper format

    ================    ===============================================================
    **Argument**        **Description**
    ----------------    ---------------------------------------------------------------
    res                 Required Dict.  The response dictionary from the query call.
    ----------------    ---------------------------------------------------------------
    stype               Required String. The search type to find. This tells the
                        internal method what type of return object should be used.
    ----------------    ---------------------------------------------------------------
    gis                 Required GIS. The connection object.
    ----------------    ---------------------------------------------------------------
    as_dict             Required Boolean. If True, the response comes back as a dictionary.
    ================    ===============================================================

    :returns: List

    """
    if as_dict:
        return res['results']
    elif str(stype).lower() in {"content", "item", "items", "group_content"}:
        return [Item(itemid=r['id'], itemdict=r, gis=gis) for r in res['results']]
    elif str(stype).lower() in ["user", "users", "accounts", "account"]:
        return [User(gis=gis, username=r['username'], userdict=res) for r in res['results']]
    elif str(stype).lower() in ["groups", 'group']:
        return [Group(groupdict=r, groupid=r['id'], gis=gis) for r in res['results']]
    return res['results']
Ejemplo n.º 2
0
def updateUser(userList, userLevel, userGroup, markedForDeletion):
    user = None

    def updateUserLevels():
        try:            
            user.update_level('2')
            user.update_role('org_user')
            print('Full name: ' + userID.fullName)
            print('User name: ' + userID.username)
            print('Email: ' + userID.email)
            print('Applying change to user level: ' + userID.email)
        except Exception as e:
            print('An error occurred: ' + e.args[0] + ' updating user')


    def addUserToGroup(grpObj):
        try:
            UpdateGroup(grpObj, user)
        except Exception as e:
            print('An error occurred adding the user to group: ' + grpObj)


    def runUpdate():
        try:
            if userLevel:
                updateUserLevels()
            if userGroup:
                if isinstance(uids, dict):
                    for id, grps in uids.items():
                        if isinstance(grps, list):
                            for grp in grps:
                                if id == user.email:
                                    addUserToGroup(grp)
                        else:
                            if id == user.email:
                                addUserToGroup(grps) 
                if isinstance(uids, list):
                    grpObj = getGroups(None, None, None)
                    addUserToGroup(grpObj)
        except Exception as e:
            print('An error occurred updating user \n' + e.args[0]) 
    try:
        for userID in userList:
            user = User(gis, userID.username)
            if markedForDeletion:
                deleteUser(user)
            if userID.username != portalOwner and not markedForDeletion:                
                runUpdate()
    except Exception as e:
        print('An error occurred retrieving user - ' + e.args[0])
Ejemplo n.º 3
0
def getGroupMembers(grpObj):
    try:        
        group = grpObj
        grpMembers = group.get_members()
        print('Group Managers: ')
        grpUsers = []
        for grpAdmin in grpMembers['admins']:
            user = User(gis, grpAdmin)
            print('Username: '******' - Full Name: ' + user.fullName +
                  ' - Email: ' + user.email)
            grpUsers.append(user)

        print('Group Users: ')
        for grpUser in grpMembers['users']:
            user = User(gis, grpUser)
            print('Username: '******' - Full Name: ' + user.fullName +
                  ' - Email: ' + user.email)
            grpUsers.append(user)

        return grpUsers
    except Exception as e:
        print('An Error occurred getting Group members - ' + e.args[0])
Ejemplo n.º 4
0
def _assert_privileges_access(user: User) -> None:
    """Helper function determining if can access user privileges."""
    assert 'privileges' in user.keys(), f'Cannot access privileges of {user.username}. Please ensure either this is ' \
                                        'your username, or you are logged in as an administrator to be able to ' \
                                        'view privileges.'
Ejemplo n.º 5
0
        USR, P, BOXDIR = f.read().split('\n')
except ValueError:
    print(ValueError)
    pass


# we connect to my arcgis account using the previous credentials
def connect_to_arcgis(_profile):
    gis = GIS(profile=_profile)
    print('Connected successfully to the [' + gis.properties.name +
          '] organization\n')
    return gis


GIS = connect_to_arcgis('geogeeks')
USER = User(GIS, USR, userdict=None)

ARCGISBOXDIR = os.path.normpath(str(Path.home()) + BOXDIR)
logging.info(ARCGISBOXDIR)

# we make sure the the arcgisbox dir do not previously exists and delete it if so
if Path(ARCGISBOXDIR).exists():
    shutil.rmtree(ARCGISBOXDIR)

os.mkdir(ARCGISBOXDIR)


# we recursively loop through each folder downloading the items type given in file_types
def create_folder_structure(_user):
    """ This function replicate the folder structure of the user account """
    flds = _user.folders
Ejemplo n.º 6
0
        txt = open(
            r"C:\data\gtg-data\projects\_agol-slicer\AGO_items_by_group.json"
        ).read()
        item_types = json.loads(txt)

        print('getting credentials...')
        creds = getUserCreds()

        url = creds[0]
        un = creds[1]
        pw = creds[2]
        out_xlsx = creds[3]

        print('accessing AGO...')
        gis = GIS(url, un, pw)
        user = User(gis, un)
        ## future ref- can use gis.users.search() to get list
        ## of all users in org. Loop all users through the
        ## getContent funct to get whole org's content.
        ## consider new tab/df for each user

        print('getting user' 's content...')
        item_dict = getContent(user)
        print('organizing content by type...')
        apps, maps, lyrs, data = sortContent(item_dict, item_types)
        print('creating XLSX...')
        wb, sh = createWorkbook(out_xlsx, un)
        print('writing to XLSX...')
        writeItems(wb, sh, apps, maps, lyrs, data)

    except KeyError as e: