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

2719
9
Jump to solution
03-01-2021 05:46 AM
DavidPike
MVP Frequent 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
MVP Esteemed Contributor

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
9 Replies
jcarlson
MVP Esteemed Contributor

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 Frequent 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
MVP Esteemed Contributor

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
0 Kudos
DavidPike
MVP Frequent Contributor

Cheers J

0 Kudos
jcarlson
MVP Esteemed Contributor

@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 Frequent Contributor

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

0 Kudos
JohnMDye
Occasional Contributor III

@DavidPike@AndrewChapkowski or @RohitSingh2 am I missing something here? user.disable() is clearly documented as a method that can be used to disable a user's login access: https://developers.arcgis.com/python/api-reference/arcgis.gis.toc.html#arcgis.gis.User.disable

Yet the following code:

users = [user for user in gis.users.search(query="username: testuser")]
for user in users:
    print("Disabling " + user.fullName)
    user.disable()

results in 

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-107-0490e44c9381> in <module>
      1 users = [user for user in gis.users.search(query="username: testuser")]
      2 for user in users:
      3         print("Disabling " + user.fullName)
----> 4         user.disable()

TypeError: 'bool' object is not callable
0 Kudos
jcarlson
MVP Esteemed Contributor

What you're missing is that this thread was initially posted in March. It has since been resolved.

https://github.com/Esri/arcgis-python-api/issues/933

- Josh Carlson
Kendall County GIS
JohnMDye
Occasional Contributor III

@jcarlson thanks for the response. I realize the thread was resolved, that was why I asked on the same thread because if its resolved, then I must be doing something wrong.

Last time I checked, properties are supposed to tell you something about an object's state, while python methods are supposed actually do something. What I don't understand is why there is a documented disable() method on the user object. 

The disable method is documented in the latest version of the API documentation which I linked to above. Either I am doing something wrong in my code above, or this disable() method on the user object is not functional. I'm just trying to figure out which. 

0 Kudos