Example #1
0
def copy_groups_sample():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    groups = source.groups(q='Administration')
    copied_groups = copy_groups(groups, source, target, 'wmathot')
    for sourceid in copied_groups.keys():
        print 'Copied ' + sourceid + ' to ' + copied_groups[sourceid]
Example #2
0
def copy_user_with_groups_and_items():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    source_owner = source.logged_in_user()['username']
    target_owner = target.logged_in_user()['username']

    # Copy the groups
    groups = source.groups(q='owner:' + source_owner)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    copied_items = copy_user_contents(source, source_owner, target,
                                      target_owner)
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]
        if sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                if id in copied_groups]
            target.share_items(target_owner, [target_item_id], target_group_ids,\
                               sharing['access'] == 'org',\
                               sharing['access'] == 'public')
Example #3
0
def copy_user_with_groups_and_items():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    source_owner = source.logged_in_user()['username']
    target_owner = target.logged_in_user()['username']

    # Copy the groups
    groups = source.groups(q='owner:' + source_owner)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    copied_items = copy_user_contents(source, source_owner, target, target_owner)
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]
        if sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                if id in copied_groups]
            target.share_items(target_owner, [target_item_id], target_group_ids,\
                               sharing['access'] == 'org',\
                               sharing['access'] == 'public')
Example #4
0
def create_user_group_item_reports():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    item_fields = ['id', 'title', 'owner', 'numViews']
    items = portal.search(item_fields,
                          sort_field='numViews',
                          sort_order='desc')
    csvfile = csv.writer(open('items-report.csv', 'wb'))
    csvfile.writerow(item_fields)
    for item in items:
        row = [item[field] for field in item_fields]
        csvfile.writerow(row)

    groups_fields = ['id', 'title', 'owner']
    groups = portal.groups(groups_fields)
    csvfile = csv.writer(open('groups-report.csv', 'wb'))
    csvfile.writerow(groups_fields)
    for group in groups:
        row = [group[field] for field in groups_fields]
        csvfile.writerow(row)

    user_fields = ['username', 'fullName', 'email', 'role']
    users = portal.org_users(user_fields)
    csvfile = csv.writer(open('users-report.csv', 'wb'))
    csvfile.writerow(user_fields)
    for user in users:
        row = [user[field] for field in user_fields]
        csvfile.writerow(row)
Example #5
0
def copy_groups_sample():
    source = Portal('http://portaldev.arcgis.com', 'wmathot', 'wmathot')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    groups = source.groups(q='Administration')
    copied_groups = copy_groups(groups, source, target, 'wmathot')
    for sourceid in copied_groups.keys():
        print 'Copied ' + sourceid + ' to ' + copied_groups[sourceid]
Example #6
0
def create_user_group_item_reports():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')

    item_fields = ['id', 'title', 'owner', 'numViews']
    items = portal.search(item_fields, sort_field='numViews', sort_order='desc')
    csvfile = csv.writer(open('items-report.csv', 'wb'))
    csvfile.writerow(item_fields)
    for item in items:
        row = [item[field] for field in item_fields]
        csvfile.writerow(row)

    groups_fields = ['id', 'title', 'owner']
    groups = portal.groups(groups_fields)
    csvfile = csv.writer(open('groups-report.csv', 'wb'))
    csvfile.writerow(groups_fields)
    for group in groups:
        row = [group[field] for field in groups_fields]
        csvfile.writerow(row)

    user_fields = ['username', 'fullName', 'email', 'role']
    users = portal.org_users(user_fields)
    csvfile = csv.writer(open('users-report.csv', 'wb'))
    csvfile.writerow(user_fields)
    for user in users:
        row = [user[field] for field in user_fields]
        csvfile.writerow(row)
Example #7
0
def hide_user():
    portal = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    user_to_hide = 'wmathot'
    portal.update_user(user_to_hide, {'access': 'private'})
    groups = portal.groups(['id'], 'owner:' + user_to_hide)
    for group in groups:
        portal.update_group(group['id'], {'access': 'private'})
    items = portal.search(['id'], 'owner:' + user_to_hide)
    portal.share_items(user_to_hide, items, None, False, False)
Example #8
0
def hide_user():
    portal = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    user_to_hide = 'wmathot'
    portal.update_user(user_to_hide, {'access': 'private'})
    groups = portal.groups(['id'], 'owner:' + user_to_hide)
    for group in groups:
        portal.update_group(group['id'], {'access': 'private'})
    items = portal.search(['id'], 'owner:' + user_to_hide)
    portal.share_items(user_to_hide, items, None, False, False)
Example #9
0
def copy_group_with_shared_content():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    target_owner = target.logged_in_user()['username']
    group_id = '2394b887a80347fb8544610cfa30489c'

    # Copy the groups
    groups = source.groups(q='id:' + group_id)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    items = source.search(q='group:' + group_id)
    copied_items = copy_items(items, source, target, target_owner,
                              'Copied Items (' + group_id + ')')
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]

        # If we have access to the full sharing properties of the source
        # item, then copy all of them, otherwise just share with the group
        if sharing and sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups'] \
                                if id in copied_groups]
            share_org = (sharing['access'] == 'org')
            share_public = (sharing['access'] == 'public')
            if not target.is_multitenant():
                share_public = (share_public or share_org)
            target.share_items(target_owner, [target_item_id],
                               target_group_ids, \
                               share_org or share_public, \
                               share_public)
        else:
            target_item_id = copied_items[item_id]
            target_group_id = copied_groups[group_id]
            target.share_items(target_owner, [target_item_id], \
                               [target_group_id])
Example #10
0
def copy_group_with_shared_content():
    source = Portal('http://www.arcgis.com')
    target = Portal('http://wittm.esri.com', 'admin', 'esri.agp')
    target_owner = target.logged_in_user()['username']
    group_id = '2394b887a80347fb8544610cfa30489c'

    # Copy the groups
    groups = source.groups(q='id:' + group_id)
    copied_groups = copy_groups(groups, source, target)
    print 'Copied ' + str(len(copied_groups)) + ' groups'

    # Copy the items
    items = source.search(q='group:' + group_id)
    copied_items = copy_items(items, source, target, target_owner,
                              'Copied Items (' + group_id + ')')
    print 'Copied ' + str(len(copied_items)) + ' items'

    # Share the items in the target portal
    for item_id in copied_items.keys():
        sharing = source.user_item(item_id)[1]

        # If we have access to the full sharing properties of the source
        # item, then copy all of them, otherwise just share with the group
        if sharing and sharing['access'] != 'private':
            target_item_id = copied_items[item_id]
            target_group_ids = [copied_groups[id] for id in sharing['groups'] \
                                if id in copied_groups]
            share_org = (sharing['access'] == 'org')
            share_public = (sharing['access'] == 'public')
            if not target.is_multitenant():
                share_public = (share_public or share_org)
            target.share_items(target_owner, [target_item_id],
                               target_group_ids, \
                               share_org or share_public, \
                               share_public)
        else:
            target_item_id = copied_items[item_id]
            target_group_id = copied_groups[group_id]
            target.share_items(target_owner, [target_item_id], \
                               [target_group_id])
Example #11
0
def copy_users():
    source = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    owners = ['admin', 'wmathot']
    target_owner = target.logged_in_user()['username']
    for owner in owners:
        groups = source.groups(q='owner:' + owner)
        copied_groups = copy_groups(groups, source, target, target_owner)
        copied_items = copy_user_contents(source, owner, target, target_owner)
        for item_id in copied_items.keys():
            sharing = source.user_item(item_id)[1]
            if sharing['access'] != 'private':
                target_item_id = copied_items[item_id]
                target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                    if id in copied_groups]
                share_org = (sharing['access'] == 'org')
                share_public = (sharing['access'] == 'public')
                if not target.is_multitenant():
                    share_public = (share_public or share_org)
                target.share_items(target_owner, [target_item_id],
                                   target_group_ids,\
                                   share_org or share_public,\
                                   share_public)
Example #12
0
def copy_users():
    source = Portal('http://portaldev.arcgis.com', 'admin', 'esri.agp')
    target = Portal('http://wittm.esri.com', 'wmathot', 'wmathot')
    owners = ['admin', 'wmathot']
    target_owner = target.logged_in_user()['username']
    for owner in owners:
        groups = source.groups(q='owner:' + owner)
        copied_groups = copy_groups(groups, source, target, target_owner)
        copied_items = copy_user_contents(source, owner, target, target_owner)
        for item_id in copied_items.keys():
            sharing = source.user_item(item_id)[1]
            if sharing['access'] != 'private':
                target_item_id = copied_items[item_id]
                target_group_ids = [copied_groups[id] for id in sharing['groups']\
                                    if id in copied_groups]
                share_org = (sharing['access'] == 'org')
                share_public = (sharing['access'] == 'public')
                if not target.is_multitenant():
                    share_public = (share_public or share_org)
                target.share_items(target_owner, [target_item_id],
                                   target_group_ids,\
                                   share_org or share_public,\
                                   share_public)
Example #13
0
def list_group_ids():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    groups = portal.groups(['title', 'id'])
    pprint(groups, indent=2, width=120)
Example #14
0
def list_group_ids():
    portal = Portal('http://portaldev.esri.com', 'admin', 'esri.agp')
    groups = portal.groups(['title', 'id'])
    pprint(groups, indent=2, width=120)