Administration: Validate user profiles

  • 👟 Ready To Run!
  • 🗃️ Administration
  • 👤 User Management

Requirements

  • 🔒 Administrator Privileges

Some organizations require member profiles to contain values beyond the minumum required attributes necessary to create a valid user in an ArcGIS Online Organization or ArcGIS Enterprise. For instance, in order to comply with policies and regulations, an organization may require a profile picture or a brief description. This notebook will check attribute values for users of the organization to monitor profiles.

To get started, let's import the necessary libraries and connect to our GIS.

import os
import datetime as dt

import pandas as pd

from arcgis.gis import GIS
gis = GIS("home")

Then, let's create a list containing strings that represent all the values that your organization requires (beyond the required attributes for a valid user profile).

access_type refers to the User.access property of a user and it indicates the level of access of the user: private, org, or public.

While access_type may not be a requirement for your organization to validate a user profile, we have added it here to demonstrate how other useful properties can also be extracted for each user profile to learn more about them.

complete_profile = ['description', 'thumbnail', 'access', 'access_type']

We'll define a function that loops through the list we created and inspects a user object for the values of these attributes. We'll create a list of True/False values for each user regarding the necessary attributes.

def get_missing_profile_attrs(member):
    non_compliance = []
    for attr in complete_profile:
        if attr=='access_type':
            non_compliance.append(member.access)
        else:
            if getattr(member, attr) == None:    
                non_compliance.append(False)
            else:
                non_compliance.append(True)
    return non_compliance

Now we can create a list of users in the GIS and loop through them, calling the function written above to inspect each user object. This will create a dictionary with usernames as the key and the list of True/False status for the required attributes as values.

user_profile_status = {}
for user in gis.users.search("NOT esri_*"):
    missing_profile_atts = get_missing_profile_attrs(user)
    user_profile_status[user.username] = missing_profile_atts

The pandas library can be used to create a dataframe from the above dictionary.

user_profile_df = pd.DataFrame(data=user_profile_status, index=complete_profile).T
user_profile_df.head()
descriptionthumbnailaccessaccess_type
achapkowski_geosaurusFalseFalseTrueorg
amani_geosaurusTrueTrueTruepublic
andrew57TrueTrueTrueprivate
api_data_ownerFalseFalseTrueorg
arcgis_pythonTrueTrueTruepublic

This dataframe can then be written to a .csv. file on your fileshare,

output_dir = "/arcgis/home/"
current = str(int(dt.datetime.now().timestamp()))
out_file = "output_org_user_profile" + "_" + current + ".csv"

user_profile_df.to_csv(os.path.join(output_dir, out_file), index_label='username')

and the dataframe can be written to a .csv file item on your Organization.

gis.content.add({}, output_dir + out_file)
output_org_user_profile_1686349431
CSV by MMajumdar_geosaurus
Last Modified: June 09, 2023
0 comments, 0 views

You may download this item if you wish, and if you decide to delete this item after having used it, you may run the script below by updating the item_id with the id of this file in your organization.

item = gis.content.get(item_id)
item.delete()

Conclusion

This notebook checked attribute values for an organization's users and wrote the results to a .csv file. This file can then be analyzed to validate that all user profiles contain the minimum required attributes as defined by any policies or regulations.

Your browser is no longer supported. Please upgrade your browser for the best experience. See our browser deprecation post for more details.