ArcGIS API for Python GIS module - User object properties - check if user is disabled

257
6
Jump to solution
03-01-2021 05:46 AM
DavidPike
MVP Regular Contributor

Portal 10.6.1, running from IDE, GIS module  - class arcgis.gis.User(gis, username, userdict=None)

I'm testing some Python API functionality to automate some listing of users, groups, access etc. and wanted to programmatically assess users which have had their access to the Portal disabled.

This is part of a larger aim, but at the moment I just want to be able to test if a user has been disabled or not, when that works, I'm happy with the rest of the coding. 

using the API reference for the User class- https://developers.arcgis.com/python/api-reference/1.6.1/arcgis.gis.toc.html#user

the 'disabled' property when queried seems to return the correct True/False on my test accounts - although the documentation (also for the REST API) states - disabled - 'disables access to the organisation by the user') 

I seem to be getting the correct boolean returned but I just wanted to be sure, as the documentation is a bit weak or misleading on this one (something I've found consistently across the API documentation).

trying the disable() method just to test it out also doesn't work.

#connect to portal, it connects fine
gis = GIS(url, username, password)
#search for user testeditor2
user = gis.users.search(query="username: testeditor2")

#check if user is disabled
print(user[0].disabled)
#returns False

#access testeditor2 from user list index 0 and try disable method
user[0].disable()
#returns
#File "C:\Users\username\.conda\envs\py377\lib\urllib\request.py", line 649, #in http_error_default
    #raise HTTPError(req.full_url, code, msg, hdrs, fp)

 

Tags (3)
1 Solution

Accepted Solutions
jcarlson
Regular Contributor II

Yeah, disabled is a boolean property. I hadn't noticed the API docs before now, but it does look like they've got the method description listed next to the property. I put in an issue on their GitHub repo to get it fixed.

And yes, the syntax is either a list of username strings or a selection of users returned from something like UserManager.search().

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
6 Replies
jcarlson
Regular Contributor II

Running in 10.8.1, I also receive an error when attempting to call disable() on individual accounts. I am able to accomplish the task using the bulk operation arcgis.gis.UserManager.diable_users().

Oddly, checking user.disabled still returned "False" on my test accounts initially after the bulk action. It updated after a couple of minutes, as though the bulk action was asynchronous.

Once bulk-disabled, using enable() on a per-user basis worked just fine. I suspect this is a bug.

EDIT: Doesn't even work from the rest directory, either. (.../portal/sharing/rest/community/users/johndoe/disable)

- Josh Carlson
Kendall County GIS
0 Kudos
DavidPike
MVP Regular Contributor

Glad it's not just me - are we in the same mindset that user.disabled is a boolean property for the user's disabled status - which has a poor description?

Is this the right syntax for the bulk op?

 

arcgis.gis.UserManager.disable_users(["testeditor2"])

 

Thanks J

0 Kudos
jcarlson
Regular Contributor II

Yeah, disabled is a boolean property. I hadn't noticed the API docs before now, but it does look like they've got the method description listed next to the property. I put in an issue on their GitHub repo to get it fixed.

And yes, the syntax is either a list of username strings or a selection of users returned from something like UserManager.search().

- Josh Carlson
Kendall County GIS

View solution in original post

0 Kudos
DavidPike
MVP Regular Contributor

Cheers J

0 Kudos
jcarlson
Regular Contributor II

@DavidPike one of the devs resolved the bug, said it should hit the API docs w/in the next week.

- Josh Carlson
Kendall County GIS
0 Kudos
DavidPike
MVP Regular Contributor

Wow that's exceptionally fast.  Thanks for your help and insight J.

0 Kudos