Error accessing properties of group that hosted feature layer is shared to using shared_with property: 403, Content Management

404
0
01-12-2024 10:31 AM
ColForbin
Occasional Contributor

I was attempting to modify the sharing settings of a hosted feature layer in AGO using the Python api (version 2.2.0.1) and encountered a strange error.  The feature layer is shared to 5 groups as well as "Everyone".  I am connecting to the AGO organization with an administrator user, so should have access to the sharing properties of all items.  Here is the code snippet that causes the error:

fs = gis.content.get(ago_item_id)
shared_with_dict = fs.shared_with
shrGroups = shared_with_dict['groups']
for group in shrGroups:
    try:
        print((group.title, group.owner, group.access))
    except Exception as e:
        print(str(e))


For the last group, the script goes into exception and prints this error:

You do not have permissions to access this resource or perform this operation.
(Error Code: 403)

If I change the script to use print(vars(group)) like this, I get a list of all the groups the item is shared to:

fs = gis.content.get(ago_item_id)
shared_with_dict = fs.shared_with
shrGroups = shared_with_dict['groups']
for group in shrGroups:
    try:
        print(vars(groups))
    except Exception as e:
        print(str(e))


This script prints 6 groups.  Checking the group ID of each one I can see that 5 of the groups are included in my organization in AGO, and one is not.  Using the group ID, when I try to go to the group overview page I see the error: 

The group you requested cannot be found. It may have been deleted or you don't have permission to access it.

I then unshared the item to Everyone, and re-shared it to Everyone.  When I run the script above, it returns only 5 groups, all of them within my organization.

I then used my personal free ArcGIS Online account to search for the item.  I then added it to my favorites list.  When I run the script above, it shows 6 groups again with the one that I cannot access.  If I remove the item from my personal account favorites list and then run the script, it shows 5 groups again that are all within my organization.

It seems that if there is a publicly shared item that an external AGO user adds to their favorites list, then the item is being added to some external group that the owner of the item does not have access to.

So I guess the question is, is this expected behaviour that an external user adding an item to their favorites list would restrict the owner of the item from accessing the shared group properties?

If I want to compose a list of groups that this item is shared to, I use this script as a workaround and it seems to work:

fs = gis.content.get(ago_item_id)
shared_with_dict = fs.shared_with
shrGroups = shared_with_dict['groups']
groupList = []
for group in shrGroups:
    try:
        groupName = group.title
        groupList.append(group)
    except Exception as e:
        print(str(e))

print(str(groupList))

 

0 Kudos
0 Replies