Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I get a list of users assigned to a project?

Using python-redmine module, is there a way to list all users assigned to a project through the Redmine API?

I've found that I'm able to request information about individual users, and that may API Key user is only assigned to a specific project and it can only see other users on the project. So I can do the following but it is hugely inefficient:

from redmine import Redmine
redmine = Redmine("https://myserver.net/", key="blahblah")

my_users = []
for x in range(1, 301):
    try:
        user = redmine.user.get(str(x))
        my_users.append(user.id)
    except:
        print "",

The above code gets me what I want, a list of the users on a project... but takes way too long to be practical. Plus there may be user IDs higher than any range I pick.

Update: Here is what I got to work, thnx @njzk2

my_users = []
project = redmine.project.get('myproject')
for membership in project.memberships:
    my_users.append(membership.user.id)
like image 284
paxos1977 Avatar asked Jan 09 '23 14:01

paxos1977


1 Answers

The answer by njzk2 is good but it still makes 2 separate API calls:

  1. redmine.project.get('my_project')
  2. redmine.project.get('my_project').memberships

So if you need to get all available details of the project first and all the members of the project second, then it's the best available option. But if you only need to get the members, you can do it in one API call via:

redmine.project_membership.filter(project_id='my_project') (docs)

You're probably wondering why there are so many ways to do one thing, well, because there can be different use cases and python-redmine tries it's best to provide different ways to achieve things. So you'll have to look through documentation thoroughly and find the best available way that works for your exact case.

like image 59
Max Tepkeev Avatar answered Jan 17 '23 08:01

Max Tepkeev