python-redmine icon indicating copy to clipboard operation
python-redmine copied to clipboard

Bug: Users.all() does not return all users

Open misilot opened this issue 1 year ago • 3 comments

https://python-redmine.com/resources/user.html#all does not appear to return all users. It only returns the active users. It does not include the registered or locked users.

I am trying to search for users to update their accounts from a third party system if they are in an external group, and reactive them. However since all() does not return everyone, it tries to create them instead of trying to unlock and then update them.

Thanks!

misilot avatar Aug 08 '23 21:08 misilot

As a quick fix you can use redmine.user.filter(status='') i.e. supply empty value to get all users regardless of their status. Right now redmine.user.all() returns just active users because back in the days Redmine API wasn't able to return all statuses, i.e. it didn't support this empty value hack I mentioned above. And when they finally introduced it I completely forgot to add it to a redmine.user.all() method by default, so thanks for reminding me about it, I'll introduce a fix in the next version.

maxtepkeev avatar Aug 10 '23 19:08 maxtepkeev

Thanks!

I don't think that will help me at least. Since, it doesn't return the status unfortunately. So I think I am stuck doing two requests and combining / adding a status field.

misilot avatar Aug 10 '23 21:08 misilot

Ah yes, you're right, if you need a status property then you have to make a separate request for each user anyway which isn't optimal and very slow, but that's what we get with current Redmine API.

The only thing I would mention is a refresh() method on a resource (user resource in your case) which will basically do a single request and add a status property (and other missing properties if any) to a current user resource, so you won't have to do that manually and combine different results afterwards, i.e.:

users = redmine.user.filter(status='')

for user in users:
    user.refresh()    # this is an equivalent of redmine.user.get(user.id), you can also do a u = user.refresh(itself=False) if you want to get a copy of a user resource in another variable
    print(user.status)

maxtepkeev avatar Aug 10 '23 21:08 maxtepkeev

Fixed in cece6b4723bd0d725ae687a6a2a6a09b5a790ab1

maxtepkeev avatar Mar 02 '24 17:03 maxtepkeev