操作方法
在 ArcGIS Online 中重新分配项目的所有权时,先决条件是在更改或重新分配所有权之前从特殊群组(例如所有成员均具有更新权限的群组)取消共享项目。 将与更新群组共享的多个项目的所有权重新分配将耗费大量时间。 因此,使用 Python 脚本自动化该过程将很有帮助。
要自动化工作流,请使用以下独立 Python 脚本:
from arcgis.gis import * gis = GIS("https://maps_sample.arcgis.com", "username", "password")
orig_userid = "First_User" new_userid = "Second_User" olduser = gis.users.get(orig_userid)
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("Groups has been transferred!") #传输文件夹中的项目 folders = olduser.folders for folder in folders: gis.content.create_folder(folder['title'], new_userid) folderitems = olduser.items(folder=folder['title']) for item in folderitems: itemgroup=item.shared_with item.unshare(groups=itemgroup['groups']) item.reassign_to(new_userid, target_folder=folder['title']) item.share(groups=itemgroup['groups'], allow_members_to_edit=True) print("Folder content has been transferred!") userrootcontent = olduser.items() rootfoldername=olduser.username+"_RootFolder" gis.content.create_folder(rootfoldername, new_userid)
for item in userrootcontent: itemgroup=item.shared_with item.unshare(groups=itemgroup['groups']) item.reassign_to(new_userid, target_folder=rootfoldername) item.share(groups=itemgroup['groups'], allow_members_to_edit=True) print("Root folder content has been transferred!")
以下代码演示了完整脚本。
from arcgis.gis import * gis = GIS("https://maps_sample.arcgis.com/", "username", "password") #识别用户 orig_userid = "User1" new_userid = "User2" olduser = gis.users.get(orig_userid) #传递群组所有权 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("Groups has been transferred!") #传输文件夹中的项目 folders = olduser.folders for folder in folders: gis.content.create_folder(folder['title'], new_userid) folderitems = olduser.items(folder=folder['title']) for item in folderitems: itemgroup=item.shared_with item.unshare(groups=itemgroup['groups']) item.reassign_to(new_userid, target_folder=folder['title']) item.share(groups=itemgroup['groups'], allow_members_to_edit=True) print("Folder content has been transferred!") #传输根文件夹中的项目 userrootcontent = olduser.items() rootfoldername=olduser.username+"_RootFolder" gis.content.create_folder(rootfoldername, new_userid) for item in userrootcontent: itemgroup=item.shared_with item.unshare(groups=itemgroup['groups']) item.reassign_to(new_userid, target_folder=rootfoldername) item.share(groups=itemgroup['groups'], allow_members_to_edit=True) print("Root folder content has been transferred!")
获取来自 ArcGIS 专家的帮助
下载 Esri 支持应用程序