Select to view content in your preferred language

Role Permissions - Possible to get a description of each individual permission?

329
1
01-09-2024 01:48 PM
Labels (1)
Mike_Quetel
Frequent Contributor

I'm attempting to inventory the permissions that have been enabled for roles in our enterprise portal.  It's straightforward to get the permissions for a given role, and I end up with a list of what seem to be permission id's. For example, one of our roles returns this when I print the permissions:

['features:user:edit', 'portal:user:joinGroup', 'portal:user:viewOrgGroups', 'portal:user:viewOrgItems', 'portal:user:viewOrgUsers', 'premium:user:demographics', 'premium:user:elevation', 'premium:user:geocode', 'premium:user:networkanalysis']

These permission ids correspond with tables in the developer documentation Role: ArcGIS API for Python and include an easy to understand description of what the permission actually does (example below). 

My question is:  Are these descriptions accessible from the API anywhere?  I'd like my script to be able to output these descriptions so the inventory is more readable.

Thank you in advance!

 

MikeQuetel1_0-1704836832839.png

 

 

1 Reply
Kristen
Occasional Contributor

If there is a way to do this within the API for Python or REST API, I would like to know. In the meantime I scraped the info from the REST documentation page. This will work until they change the format of the web page.

from bs4 import BeautifulSoup
import requests
import pandas as pd

def get_privilege_descriptions():
    """Web scrape descriptions for role privileges"""
    response = requests.get("https://developers.arcgis.com/rest/users-groups-and-items/privileges")
    html = response.text
    soup = BeautifulSoup(html, "lxml")
    all_rows = []
    for tr in soup.select('table'):
        if tr.find_previous('h4'):
            h1 = tr.find_previous('h2').get_text(strip=True)
            h2 = tr.find_previous('h3').get_text(strip=True)
            h3 = tr.find_previous('h4').get_text(strip=True)
            headers = []
            row_data = []
            for i, row in enumerate(tr.find_all('tr')):
                if i == 0:
                    headers = [el.text.strip() for el in row.find_all('th')]
                else:
                    row_data = [el.text.strip() for el in row.find_all('td')]
                if headers == ['Privilege', 'Description']:
                    if row_data:
                        all_rows.append([h1, h2, h3] + row_data)
    df = pd.DataFrame(all_rows, columns = ['Org_Type', 'General_or_Admin', 'Privilege_Type', 'Privilege', 'Description'])
    return df

# get dataframe of privilege and description
privilege_df = get_privilege_descriptions()

# display dataframe in jupyter notebook
from IPython.display import HTML
HTML(privilege_df.to_html())

 

0 Kudos