def share_items(portal, userItemsPath, newItems, origItemSourceIDs, originGroupToDestGroups):
    #newItems - info on the items that were added to portal
    #origItemSourceIDs - the original source ids of the newItems, order of ids must match
    #   order of newItems

    print "Sharing items..."
    
    for x in range(0, len(origItemSourceIDs)):
        newItem = newItems[x]
        newID = newItem["id"]
        origID = origItemSourceIDs[x]

        itemIdfolder = os.path.join(userItemsPath,str(origID))
        
        if not os.path.exists(itemIdfolder):
            continue
        
        # Load sharing json file
        os.chdir(itemIdfolder)
        sharing = json.load(open('sharing.json'))
        
        new_group_ids = []
        new_group_names = []
        everyone = False
        org = False
        
        if sharing:
            #TODO: check if owner belongs to the groups being shared to??
            # swap stored group ids with portal group ids??
            old_group_ids = sharing['groups']
            for g in old_group_ids:
                if g in originGroupToDestGroups.keys():
                    new_group_id = originGroupToDestGroups[g]
                    new_group_ids.append(new_group_id)
                    new_group_names = destGroupID_GroupName[new_group_id] #EL used for display
            
            if len(new_group_ids) == 0:
                new_group_ids = None
            
            print "\tSharing item " + str(newItem.get("title")) + \
                "[" + str(newItem.get("type")) + "] with: " + \
                sharing['access'] + ", " + str(new_group_names) + "..."
            
            if sharing['access'].lower() == "public":
                everyone = True
                org = True
            elif sharing['access'].lower() == "org":
                everyone = False
                org = True
            
            #TODO: should this function be located outside the if sharing statement...
            resp = portal.share_item(newID, new_group_ids, org, everyone)

        else:
            pass # nothing to share??
        del sharing
dataset/ETHPy150Open Esri/ops-server-config/Publish/Portal/PortalContentPost.py/share_items/original