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')
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)