Esri / hub-py

Python interface to ArcGIS Hub
https://github.com/esri/hub-py/wiki
Apache License 2.0
42 stars 13 forks source link

Page list should skip pages that aren't available #141

Closed ajturner closed 9 months ago

ajturner commented 11 months ago

Describe the bug When getting all the pages of a site - if any of the pages are not accessible then the entire function throws an exception. Instead, the function should return the pages that are available.

from arcgis.gis import GIS
gis = GIS()
myHub = gis.hub
siteId = "b907a83b8d3947bb8e318a7b93abadf8" # OpenData DC
site = myHub.sites.get(siteId)

pages = site.pages.search()

Error

File /opt/homebrew/lib/python3.9/site-packages/arcgis/apps/hub/pages.py:566, in PageManager.search(self, title, owner, created, modified, tags)
    559     items = []
    560     # for page in pages:
    561     #     try:
    562     #         items.append(self._gis.content.get(page["id"]))
    563     #     except:
    564     #         # user doesn't have access to a particular page, skip it
    565     #         pass
--> 566     items = [self._gis.content.get(page["id"]) for page in pages]
    567 # Build search query
    568 else:
    569     query = "typekeywords:hubPage"

File /opt/homebrew/lib/python3.9/site-packages/arcgis/apps/hub/pages.py:566, in <listcomp>(.0)
    559     items = []
    560     # for page in pages:
    561     #     try:
    562     #         items.append(self._gis.content.get(page["id"]))
...
   1051 )
-> 1052 raise Exception(errormessage)

Exception: You do not have permissions to access this resource or perform this operation.

Solution

suggestion - change pages.py search to something like this

        if self._site is not None:
            pages = self._site.definition["values"]["pages"]
            items = []
            for page in pages:
                try:
                    items.append(self._gis.content.get(page["id"]))
                except:
                    # user doesn't have access to a particular page, skip it
                    pass