use temp admin account
@@ -7,14 +7,14 @@ ignore_accounts = ['andrew', 'andrew.chapkowski', 'dvitale', 'david.vitale',
'rohit.singh', 'rohitgeo', 'gbochenek_python',
'system_publisher', 'admin', 'portaladmin',
'Demo_User', 'First_User', 'Second_User',
- 'api_data_owner', 'arcgis_python']
+ 'api_data_owner', 'arcgis_python', 'temp_execution']
"""accounts that you want to delete groups and items, but keep user"""
target_accounts = ['arcgis_python']
"""create GIS connection via admin credentials"""
# gis = GIS(profile='your_portal_profile', verify_cert=False)
-gis = GIS("https://pythonapi.playground.esri.com/portal","portaladmin", "esri.agp8")
+gis = GIS("https://pythonapi.playground.esri.com/portal","temp_execution", "temp_execution123")
def delete_items(user):
@@ -37,12 +37,21 @@ def delete_items(user):
def delete_groups(user):
"""deletes the user groups"""
groups_for_deletion = gis.groups.get('query=owner:' + user.username)
+ if groups_for_deletion is not None:
for group in groups_for_deletion:
try:
print("=== deleting group %s" % group.groupid)
group.delete()
except:
print("=== could not delete group %s" % group.groupid)
+
+ for grp in user.groups:
+ print("=== removing from group: %s" % grp.id)
+ if grp.owner != user.username:
+ try:
+ grp.remove_users([user.username])
+ except:
+ print("=== User cannot be removed from group: %s" % grp.id)
print("=== finished deleting groups owned by " + user.username)
@@ -65,13 +74,7 @@ def delete_for_users():
if (datetime.datetime.now() - dt).days > 90:
delete_items(user)
- for grp in user.groups:
- print("=== deleting the group: %s" % grp.id)
- if grp.owner == user.username:
- grp.delete()
- else:
- grp.remove_users([user.username])
- print("=== deleting the group finished: %s" % grp.id)
+ delete_groups(user)
try:
user.delete()
except:
