Select to view content in your preferred language

Notebook to check group sharing

583
2
Jump to solution
03-25-2024 12:21 PM
Labels (2)
AFackler_NAPSG
Frequent Contributor

Hey everyone,

I am working on a larger notebook but have ran into a stumbling block. Basically, the end result of the notebook is to check the sharing level of all layers in a webmap and see what layers are shared publicly OR shared to a specific group; in this case, the group is called "NSARGC 3 SARCOP Partnered Collaboration Internal Group - 41484b". I figured out the public sharing part but haven't been able to figure out the group sharing in line 8. For ease of reading, I simplified the script to print "Shared Correctly" or "Not Shared Correctly" since I can get the script to run from there. Does anyone have any ideas on how to look at a specific group? Thanks!

wm=WebMap(webmap_item)
for lyr in wm.layers:
if "itemId" in lyr:
lyr_item = gis.content.get(lyr.itemId)
print(f"Layer {lyr.title} sharing: {lyr_item.shared_with}")
if lyr_item.shared_with['everyone'] is True:
print("Shared Publicly")
if lyr_item.shared_with["NSARGC 3 SARCOP Partnered Collaboration Internal Group - 41484b"] is True:
print("Shared to group")
else:
print("Not Shared Correctly") 

 

0 Kudos
1 Solution

Accepted Solutions
JakeSkinner
Esri Esteemed Contributor

Hi @AFackler_NAPSG,

You can use the group ID and then check if the item is shared with the group based off that.  Ex:

 

groupID = 'c901a2470db24abfb92a079f14186c1e'
lyr_item = gis.content.get('db6680d8e14d4f2bba5236752d44efc3')
for group in lyr_item.shared_with['groups']:
    if group.id == groupID:
        print("Shared with group")
    else:
        print("Not shared with group")

View solution in original post

2 Replies
JakeSkinner
Esri Esteemed Contributor

Hi @AFackler_NAPSG,

You can use the group ID and then check if the item is shared with the group based off that.  Ex:

 

groupID = 'c901a2470db24abfb92a079f14186c1e'
lyr_item = gis.content.get('db6680d8e14d4f2bba5236752d44efc3')
for group in lyr_item.shared_with['groups']:
    if group.id == groupID:
        print("Shared with group")
    else:
        print("Not shared with group")
AFackler_NAPSG
Frequent Contributor

Thanks Jack!

I ended up having to modify it a bit to look at layers in the map instead of the map itself, but overall, this solved what I needed!

I ended up needing to append the group ID's into their own list and checking from there since the snippet above would look at each group as a new iteration (at least from what I could tell) and succeed and fail depending on each group. Since all the layers are shared to many groups, it would eventually get to the right group... after "failing" 3 times prior. Maybe this is a roundabout way of doing it, but it works for what I need it to

webmap_item = gis.content.get("466b1d08ab8d4dcb9905e7c3a32eba27")
wm=WebMap(webmap_item)
groupID = "8e95e3c576304ab49f5fc8396f41484b"
for lyr in wm.layers:
sharedInto = []
if "itemId" in lyr:
lyr_item = gis.content.get(lyr.itemId)
for group in lyr_item.shared_with['groups']:
sharedInto.append(group.id)
if groupID in sharedInto:
print(f"{lyr_item.title} is Shared to group\n")
else:
print(f"{lyr_item.title} is NOT SHARED\n")

 

0 Kudos