コード例 #1
0
ファイル: arcgisUM.py プロジェクト: roelofsaj/kartograafr
def addCanvasUsersToGroup(instructorLog, group, courseUsers):
    """Add new users to the ArcGIS group.  """
    groupNameAndID = util.formatNameAndID(group)
    
    logger.info("addCanvasUsersToGroup: enter")
    
    if len(courseUsers) == 0:
        logger.info('No new users to add to ArcGIS Group {}'.format(groupNameAndID))
        return instructorLog

    logger.info('Adding Canvas Users to ArcGIS Group {}: {}'.format(groupNameAndID, courseUsers))
    # ArcGIS usernames are U-M uniqnames with the ArcGIS organization name appended.
    arcGISFormatUsers = formatUsersNamesForArcGIS(courseUsers)
    logger.debug("addCanvasUsersToGroup: formatted: {}".format(arcGISFormatUsers))
    
    results = group.add_users(arcGISFormatUsers)
    logger.debug("adding: results: {}".format(results))

    usersNotAdded = results.get('notAdded')
    """:type usersNotAdded: list"""
    usersCount = len(arcGISFormatUsers)
    usersCount -= len(usersNotAdded) if usersNotAdded else 0
    logger.debug("usersCount: {}".format(usersCount))
    logger.debug("aCUTG: instructorLog 1: [{}]".format(instructorLog))
    instructorLog += 'Number of users added to group: [{}]\n\n'.format(usersCount)
    logger.debug("aCUTG: instructorLog 2: [{}]".format(instructorLog))
    if usersNotAdded:
        logger.warning('Warning: Some or all users not added to ArcGIS group {}: {}'.format(groupNameAndID, usersNotAdded))
        instructorLog += 'Users not in group (these users need ArcGIS accounts created for them):\n' + '\n'.join(['* ' + userNotAdded for userNotAdded in usersNotAdded]) + '\n\n' + 'ArcGIS group ID number:\n{}\n\n'.format(group.id)
    instructorLog += '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
    logger.debug("aCUTG: instructorLog 3: [{}]".format(instructorLog))

    logger.info("addCanvasUsersToGroup: instructorLog: [{}]".format(instructorLog))
    return instructorLog
コード例 #2
0
ファイル: main.py プロジェクト: lsloan/kartograafr
def updateGroupUsers(courseUserDictionary, course, instructorLog, groupTitle, group):
    """Add remove / users from group to match Canvas course"""
    
    # get the arcgis group members and the canvas course members.
    groupNameAndID = util.formatNameAndID(group)
    groupUsers = arcgisUM.getCurrentArcGISMembers(group, groupNameAndID)
    logger.debug('group users: {}'.format(groupUsers))
    groupUsersTrimmed = [re.sub('_\S+$', '', gu) for gu in groupUsers]
    logger.debug('All ArcGIS users currently in Group {}: ArcGIS Users: {}'.format(groupNameAndID, groupUsers))
    canvasCourseUsers = [user.login_id for user in courseUserDictionary[course.id] if user.login_id is not None]
    logger.debug('All Canvas users in course for Group {}: Canvas Users: {}'.format(groupNameAndID, canvasCourseUsers))
    
    # compute the exact sets of users to change.
    changedArcGISGroupUsers, changedCourseUsers = minimizeUserChanges(groupUsersTrimmed, canvasCourseUsers)
    # added to avoid undefined variable warning
    
    # fix up the user name format for ArcGIS users names
    changedArcGISGroupUsers = arcgisUM.formatUsersNamesForArcGIS(changedArcGISGroupUsers)
    logger.info('Users to remove from ArcGIS: Group {}: ArcGIS Users: {}'.format(groupNameAndID, changedArcGISGroupUsers))
    logger.info('Users to add from Canvas course for ArcGIS: Group {}: Canvas Users: {}'.format(groupNameAndID, changedCourseUsers))
    
    # Now update only the users in the group that have changed.
    instructorLog, results = arcgisUM.removeSomeExistingGroupMembers(groupTitle, group, instructorLog, changedArcGISGroupUsers)  # @UnusedVariable
    instructorLog = arcgisUM.addCanvasUsersToGroup(instructorLog, group, changedCourseUsers)
    
    return instructorLog
コード例 #3
0
ファイル: arcgisUM.py プロジェクト: lsloan/kartograafr
def addCanvasUsersToGroup(instructorLog, group, courseUsers):
    """Add new users to the ArcGIS group.  """
    groupNameAndID = util.formatNameAndID(group)
    
    logger.info("addCanvasUsersToGroup: enter")
    
    if len(courseUsers) == 0:
        logger.info('No new users to add to ArcGIS Group {}'.format(groupNameAndID))
        return instructorLog

    logger.info('Adding Canvas Users to ArcGIS Group {}: {}'.format(groupNameAndID, courseUsers))
    # ArcGIS usernames are U-M uniqnames with the ArcGIS organization name appended.
    arcGISFormatUsers = formatUsersNamesForArcGIS(courseUsers)
    logger.debug("addCanvasUsersToGroup: formatted: {}".format(arcGISFormatUsers))
    
    results = group.add_users(arcGISFormatUsers)
    logger.debug("adding: results: {}".format(results))

    usersNotAdded = results.get('notAdded')
    """:type usersNotAdded: list"""
    usersCount = len(arcGISFormatUsers)
    usersCount -= len(usersNotAdded) if usersNotAdded else 0
    logger.debug("usersCount: {}".format(usersCount))
    logger.debug("aCUTG: instructorLog 1: [{}]".format(instructorLog))
    instructorLog += 'Number of users added to group: [{}]\n\n'.format(usersCount)
    logger.debug("aCUTG: instructorLog 2: [{}]".format(instructorLog))
    if usersNotAdded:
        logger.warning('Warning: Some or all users not added to ArcGIS group {}: {}'.format(groupNameAndID, usersNotAdded))
        instructorLog += 'Users not in group (these users need ArcGIS accounts created for them):\n' + '\n'.join(['* ' + userNotAdded for userNotAdded in usersNotAdded]) + '\n\n' + 'ArcGIS group ID number:\n{}\n\n'.format(group.id)
    instructorLog += '- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\n'
    logger.debug("aCUTG: instructorLog 3: [{}]".format(instructorLog))

    logger.info("addCanvasUsersToGroup: instructorLog: [{}]".format(instructorLog))
    return instructorLog
コード例 #4
0
ファイル: arcgisUM.py プロジェクト: roelofsaj/kartograafr
def removeSomeExistingGroupMembers(groupTitle, group,instructorLog,groupUsers):
    """Get list of ArgGIS users to remove from group and call method to remove them."""
    results = ''
    groupNameAndID = util.formatNameAndID(group)
    logger.info('Found ArcGIS group: {}'.format(groupNameAndID))
    instructorLog += 'Updating ArcGIS group: "{}"\n'.format(groupTitle)
    
    if not groupUsers:
        logger.info('Existing ArcGIS group {} does not have users to remove.'.format(groupNameAndID))
    else:
        results = removeListOfUsersFromArcGISGroup(group, groupNameAndID, groupUsers)
        
    return instructorLog, results
コード例 #5
0
ファイル: arcgisUM.py プロジェクト: lsloan/kartograafr
def removeSomeExistingGroupMembers(groupTitle, group,instructorLog,groupUsers):
    """Get list of ArgGIS users to remove from group and call method to remove them."""
    results = ''
    groupNameAndID = util.formatNameAndID(group)
    logger.info('Found ArcGIS group: {}'.format(groupNameAndID))
    instructorLog += 'Updating ArcGIS group: "{}"\n'.format(groupTitle)
    
    if not groupUsers:
        logger.info('Existing ArcGIS group {} does not have users to remove.'.format(groupNameAndID))
    else:
        results = removeListOfUsersFromArcGISGroup(group, groupNameAndID, groupUsers)
        
    return instructorLog, results
コード例 #6
0
ファイル: main.py プロジェクト: knoopum/kartograafr
def updateGroupUsers(courseUserDictionary, course, instructorLog, groupTitle,
                     group):
    """Add remove / users from group to match Canvas course"""

    # get the arcgis group members and the canvas course members.
    groupNameAndID = util.formatNameAndID(group)
    groupUsers = arcgisUM.getCurrentArcGISMembers(group, groupNameAndID)
    logger.debug('group users: {}'.format(groupUsers))
    groupUsersTrimmed = [re.sub('_\S+$', '', gu) for gu in groupUsers]
    logger.debug(
        'All ArcGIS users currently in Group {}: ArcGIS Users: {}'.format(
            groupNameAndID, groupUsers))
    canvasCourseUsers = [
        user.login_id for user in courseUserDictionary[course.id]
        if user.login_id is not None
    ]
    logger.debug(
        'All Canvas users in course for Group {}: Canvas Users: {}'.format(
            groupNameAndID, canvasCourseUsers))

    # compute the exact sets of users to change.
    changedArcGISGroupUsers, changedCourseUsers = minimizeUserChanges(
        groupUsersTrimmed, canvasCourseUsers)
    # added to avoid undefined variable warning

    # fix up the user name format for ArcGIS users names
    changedArcGISGroupUsers = arcgisUM.formatUsersNamesForArcGIS(
        changedArcGISGroupUsers)
    logger.info(
        'Users to remove from ArcGIS: Group {}: ArcGIS Users: {}'.format(
            groupNameAndID, changedArcGISGroupUsers))
    logger.info(
        'Users to add from Canvas course for ArcGIS: Group {}: Canvas Users: {}'
        .format(groupNameAndID, changedCourseUsers))

    # Now update only the users in the group that have changed.
    instructorLog, results = arcgisUM.removeSomeExistingGroupMembers(
        groupTitle, group, instructorLog,
        changedArcGISGroupUsers)  # @UnusedVariable
    instructorLog = arcgisUM.addCanvasUsersToGroup(instructorLog, group,
                                                   changedCourseUsers)

    return instructorLog
コード例 #7
0
ファイル: main.py プロジェクト: zqian/kartograafr
def updateGroupUsers(courseUserDictionary, course, instructorLog, groupTitle,
                     group):
    """Add remove / users from group to match Canvas course"""

    # get the arcgis group members and the canvas course members.
    groupNameAndID = util.formatNameAndID(group)
    groupUsers = arcgisUM.getCurrentArcGISMembers(group, groupNameAndID)
    logger.debug('group users: {}'.format(groupUsers))
    groupUsersTrimmed = [re.sub('_\S+$', '', gu) for gu in groupUsers]
    logger.debug(
        'All ArcGIS users currently in Group {}: ArcGIS Users: {}'.format(
            groupNameAndID, groupUsers))
    canvasCourseUsers = [
        user.login_id for user in courseUserDictionary[course.id]
        if user.login_id is not None
    ]
    logger.debug(
        'All Canvas users in course for Group {}: Canvas Users: {}'.format(
            groupNameAndID, canvasCourseUsers))

    # Compute the exact sets of users to change.
    usersToRemove, usersToAdd = minimizeUserChanges(groupUsersTrimmed,
                                                    canvasCourseUsers)

    logger.info('Users to remove from ArcGIS: Group {}: Users: {}'.format(
        groupNameAndID, usersToRemove))
    logger.info('Users to add to ArcGIS: Group {}: Users: {}'.format(
        groupNameAndID, usersToAdd))

    # Now update only the users in the group that have changed.
    instructorLog += f"Group: {groupNameAndID} \n\n"
    instructorLog = arcgisUM.modifyUsersInGroup(group, usersToRemove, "remove",
                                                instructorLog)
    instructorLog = arcgisUM.modifyUsersInGroup(group, usersToAdd, "add",
                                                instructorLog)
    instructorLog += "- - -\n"

    return instructorLog
コード例 #8
0
def modifyUsersInGroup(group: object, users: list, mode: str,
                       instructorLog: str):
    """Depending on the mode, add or remove users from the given ArcGIS group"""

    logger.info("modifyUsersInGroup: enter")
    groupNameAndID = util.formatNameAndID(group)

    # Set mode-specific methods and variables
    if mode in MODIFY_MODES:
        modeDict = MODIFY_MODES[mode]
        verb, verbStem, verbPrep, methodName = itemgetter(
            "verb", "verbStem", "verbPrep", "methodName")(modeDict)
        modifyUsersMethod = getattr(group, methodName)
        logger.debug(modifyUsersMethod)
    else:
        logger.error("Function was called with an invalid mode: " + mode)

    if len(users) == 0:
        logger.info(
            f"No users to {verb} {verbPrep} ArcGIS Group {groupNameAndID}")
        instructorLog += f"No users were {verbStem}ed.\n\n"
        logger.debug(
            f"modifyUsersInGroup: instructorLog: [\n{instructorLog}\n]")
        return instructorLog

    logger.info(
        f"{verbStem}ing Canvas Users {verbPrep} ArcGIS Group {groupNameAndID}: {users}"
    )

    # Change Canvas usernames to the ArcGIS format
    # (ArcGIS usernames are U-M uniqnames with the ArcGIS organization name appended)
    arcGISFormatUsers = formatUsersNamesForArcGIS(users)
    logger.debug(f"modifyUsersInGroup: formatted: {arcGISFormatUsers}")

    listsOfFormattedUsernames = util.splitListIntoSublists(
        arcGISFormatUsers, 20)
    usersNotModified = []

    for listOfFormattedUsernames in listsOfFormattedUsernames:
        try:
            results = modifyUsersMethod(listOfFormattedUsernames)
            logger.debug(f"{verbStem}ing: results: {results}")
            usersNotModified += results.get(f"not{verbStem.capitalize()}ed")
        except RuntimeError as exception:
            logger.error(
                f"Exception while {verbStem}ing users {verbPrep} ArcGIS group '{groupNameAndID}': {exception}"
            )
            return None

    usersModifiedCount = len(arcGISFormatUsers) - len(usersNotModified)
    logger.debug(f"usersModifiedCount: {usersModifiedCount}")
    instructorLog += f"Number of users {verbStem}ed {verbPrep} group: [{usersModifiedCount}]\n\n"
    if usersNotModified:
        notModifiedMessage = f"Some or all users not {verbStem}ed {verbPrep} ArcGIS group"
        if mode == "add":
            notModifiedMessage += " (These users likely need ArcGIS accounts set up)"
        logger.warning(
            f"Warning: {notModifiedMessage} {groupNameAndID} : {usersNotModified}"
        )
        instructorLog += f"{notModifiedMessage}:\n" + "\n".join(
            ["* " + userNotModified
             for userNotModified in usersNotModified]) + "\n"

    logger.debug(f"modifyUsersInGroup: instructorLog: [\n{instructorLog}\n]")
    return instructorLog