Select to view content in your preferred language

Item Sharing to Groups through the new Sharing Manager Module 2.4

145
2
Jump to solution
a month ago
Labels (1)
DavidColey
Honored Contributor

Hi - I am trying to use the new Sharing Module at 2.4 like this (I still like to use the IDLE for testing):

from arcgis.gis import GIS
from arcgis.gis._impl._content_manager import SharingLevel
gis = GIS("...myorg.net/portal", "myUsername", "myPassword", verify_cert=False)

try:
    portItems = gis.content.search(query="owner:myUsername", item_type="Feature Layer", sort_field="title", sort_order="asc", max_items=5000)
    for portItem in portItems:
        if (portItem.title == "SchoolBoardDistrict4"):
            portItem_sharing = portItem.sharing
            portItem_grp = portItem_sharing.groups
            type(portItem_grp)
            print(type(portItem_grp))
	# I am getting the correct type
	    <class 'arcgis.gis._impl._content_manager.sharing.api.SharingGroupManager'>

            org_group = ["Planning Layers Group"]
	# This works
	    portItem_sharing.sharing_level = SharingLevel.EVERYONE
	
            #portItem_grp.add(group=org_group)
            portItem_grp.remove(org_group)
	# won't remove the item from the group
            portItem_grp.list()
            print(portItem_grp.list())
	# [<Group title:"Planning Layers Group" owner:dmcoley_portal>]

except Exception:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    e = sys.exc_info()[1]
    print(e.args[0])
    print ("Line %i" % tb.tb_lineno)
    message = message + "\n" + "Line %i" % tb.tb_lineno
    message = message + "\n" + str(e)

Based on this sample from the Sharing Group Manager in the API reference:

# Usage example:
>>> from arcgis.gis import GIS
>>> gis = GIS(profile="your_organization_profile")

>>> org_item = gis.content.get("<item_id>")
>>> org_group = gis.groups.search("Storm Data Group")[0]

>>> item_sharing_mgr = org_item.sharing
>>> item_grp_sharing_mgr = item_sharing_mgr.groups
>>> item_grp_sharing_mgr.list()
[]

>>> item_grp_sharing_mgr.add(group=org_group)
True

>>> item_grp_sharing_mgr.list()
[<Group title:"Storm Data Group" owner:web_gis_user1>]

 It just doesn't seem to want to take the org_group object  I am setting up.  

Any Ideas?

@jcarlson

@JakeSkinner 

 

 

0 Kudos
1 Solution

Accepted Solutions
DavidColey
Honored Contributor

Thanks @JakeSkinner - yeah it still doesn't like it:

 or like this:

 

org_group = ['dc0c980751374bf796f3965b720154ba']
portItem_grp.remove(group=org_group)

 

But it does like this:

 

org_group = 'dc0c980751374bf796f3965b720154ba'
portItem_grp.remove(org_group)

 

This 3rd syntax removed the layer from the group. 

More than one group works like this:

 

org_group = 'dc0c980751374bf796f3965b720154ba,da28c73ec47344df87290ed58e09f533'
portItem_grp.add(org_group)

 

 

Thanks for your help!

David

 

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

@DavidColey try changing the group name to the group ID:

org_group = ["Planning Layers Group"]

 

Ex:

org_group = ['80d1821b9af64b9b9fd81dc0d4c8d991']

 

 

0 Kudos
DavidColey
Honored Contributor

Thanks @JakeSkinner - yeah it still doesn't like it:

 or like this:

 

org_group = ['dc0c980751374bf796f3965b720154ba']
portItem_grp.remove(group=org_group)

 

But it does like this:

 

org_group = 'dc0c980751374bf796f3965b720154ba'
portItem_grp.remove(org_group)

 

This 3rd syntax removed the layer from the group. 

More than one group works like this:

 

org_group = 'dc0c980751374bf796f3965b720154ba,da28c73ec47344df87290ed58e09f533'
portItem_grp.add(org_group)

 

 

Thanks for your help!

David