HOW TO
Bei der Neuzuweisung des Besitzes von Elementen in ArcGIS Online besteht ein erforderlicher Schritt darin, die Freigabe von Elementen für bestimmte Gruppen, wie beispielsweise Gruppen mit Aktualisierungsfunktionen für alle Mitglieder, aufzuheben, bevor der Besitz geändert oder neu zugewiesen wird. Dies ist zeitaufwendig, wenn der Besitz mehrerer Elemente, die für Gruppen mit Aktualisierungsfunktionen freigegeben wurden, neu zugewiesen werden soll. Es ist daher hilfreich, den Vorgang mit einem Python-Skript zu automatisieren.
Verwenden Sie zur Automatisierung des Workflow das folgende Python-Skript. In diesem Artikel werden die Schritte des Skripts beschrieben.
Dieses Skript kann in Jupyter Notebook, ArcGIS Notebook oder als eigenständiges Skript in Ihrer Python-Umgebung ausgeführt werden.
from arcgis.gis import * import itertools gis = GIS("https://<shortname>.maps.arcgis.com/", "<admin_username>", "<admin_password>")
#Identifying users and siging into AGOL (Both users need to have Administrator role) orig_userid = "<Username of the current owner of content and groups>" new_userid = "<Username of the user who will take the ownership of content and groups>" olduser = gis.users.get(orig_userid)
#Transferring the ownership of ALL GROUPS owned by the old user print("\n***Transferring the ownership of groups...") usergroups = olduser.groups for group in usergroups: grp = gis.groups.get(group['id']) if (grp.owner == orig_userid): grp.reassign_to(new_userid) else: grp.add_users(new_userid) grp.remove_users(orig_userid) print("The ownership of groups was successfully transferred!")
#Transferring items in folders print("\n***Transferring the ownership of items in selected folders...") folders = olduser.folders num_list=[] for folder in folders: gis.content.create_folder(folder['title'], new_userid) folderitems = olduser.items(folder=folder['title']) num_items=int(len(folderitems)) num_list.append(num_items) print("Transferring "+ str(num_items) + " item(s) from folder: "+folder['title']) for item in folderitems: itemsharing=item.shared_with item.unshare(groups=itemsharing['groups']) item.reassign_to(new_userid, target_folder=folder['title']) item.share(everyone=itemsharing['everyone'], org=itemsharing['org'], groups=itemsharing['groups'], allow_members_to_edit=True) def sum_list(num_list): sum = 0 for x in num_list: sum += x return sum total_items=sum_list(num_list) print("\nThe ownership of " +str(total_items) + " items was successfully transferred!")
#Transferring items in the root folder print("\n***Transferring the ownership of items in the root folder...") userrootcontent = olduser.items() num_root_items=int(len(userrootcontent)) rootfoldername=olduser.username+"_RootFolder" gis.content.create_folder(rootfoldername, new_userid) root_groups_list=[] for item in userrootcontent: rootitemsharing=item.shared_with root_group=rootitemsharing['groups'] root_groups_list.append(root_group) valueToBeRemoved = [] try: while True: root_groups_list.remove(valueToBeRemoved) except ValueError: pass root_groups= list(itertools.chain(*root_groups_list)) for group in root_groups: grop = gis.groups.get(group['id']) if (grop.owner == orig_userid): grop.reassign_to(new_userid) else: grop.add_users(new_userid) grop.remove_users(orig_userid) item.unshare(groups=rootitemsharing['groups']) item.reassign_to(new_userid, target_folder=rootfoldername) item.share(everyone=rootitemsharing['everyone'], org=rootitemsharing['org'], groups=rootitemsharing['groups'], allow_members_to_edit=True) print("The ownership of "+ str(num_root_items)+" items in Root Folder was transferred successfully!")
print ("\nTotal number of items transferred: "+str(total_items+num_root_items)+" items")
Nachfolgend finden Sie das vollständige Skript.
from arcgis.gis import * import itertools gis = GIS("https://<shortname>.maps.arcgis.com/", "<admin_username>", "<admin_password>") #Identifying users and siging into AGOL (Both users need to have Administrator role) orig_userid = "<Username of the current owner of content and groups>" new_userid = "<Username of the user who will take the ownership of content and groups>" olduser = gis.users.get(orig_userid) #Transferring the ownership of ALL GROUPS owned by this user print("\n***Transferring the ownership of groups...") usergroups = olduser.groups for group in usergroups: grp = gis.groups.get(group['id']) if (grp.owner == orig_userid): grp.reassign_to(new_userid) else: grp.add_users(new_userid) grp.remove_users(orig_userid) print("The ownership of groups was successfully transferred!") #Transferring items in folders print("\n***Transferring the ownership of items in selected folders...") folders = olduser.folders num_list=[] for folder in folders: gis.content.create_folder(folder['title'], new_userid) folderitems = olduser.items(folder=folder['title']) num_items=int(len(folderitems)) num_list.append(num_items) print("Transferring "+ str(num_items) + " item(s) from folder: "+folder['title']) for item in folderitems: itemsharing=item.shared_with item.unshare(groups=itemsharing['groups']) item.reassign_to(new_userid, target_folder=folder['title']) item.share(everyone=itemsharing['everyone'], org=itemsharing['org'], groups=itemsharing['groups'], allow_members_to_edit=True) def sum_list(num_list): sum = 0 for x in num_list: sum += x return sum total_items=sum_list(num_list) print("\nThe ownership of " +str(total_items) + " items was successfully transferred!") #Transferring items in the root folder print("\n***Transferring the ownership of items in the root folder...") userrootcontent = olduser.items() num_root_items=int(len(userrootcontent)) rootfoldername=olduser.username+"_RootFolder" gis.content.create_folder(rootfoldername, new_userid) root_groups_list=[] for item in userrootcontent: rootitemsharing=item.shared_with root_group=rootitemsharing['groups'] root_groups_list.append(root_group) valueToBeRemoved = [] try: while True: root_groups_list.remove(valueToBeRemoved) except ValueError: pass root_groups= list(itertools.chain(*root_groups_list)) for group in root_groups: grop = gis.groups.get(group['id']) if (grop.owner == orig_userid): grop.reassign_to(new_userid) else: grop.add_users(new_userid) grop.remove_users(orig_userid) item.unshare(groups=rootitemsharing['groups']) item.reassign_to(new_userid, target_folder=rootfoldername) item.share(everyone=rootitemsharing['everyone'], org=rootitemsharing['org'], groups=rootitemsharing['groups'], allow_members_to_edit=True) print("The ownership of "+ str(num_root_items)+" items in Root Folder was transferred successfully!") print ("\nTotal number of items transferred: "+str(total_items+num_root_items)+" items") print("\n***Process was completed!***")
Unterstützung durch ArcGIS-Experten anfordern
Esri Support App herunterladen