JIRA SOAP API:获取用户列表 [英] JIRA SOAP API : get the list of users

查看:235
本文介绍了JIRA SOAP API:获取用户列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作在C#中一个工具,接口JIRA SOAP API。我已阅读文档可以在这里找到:的http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html

I'm working on a tool in C# that interfaces the JIRA SOAP API. I have read the doc one can find here: http://docs.atlassian.com/software/jira/docs/api/rpc-jira-plugin/latest/index.html

有谁知道我能得到的所有分配的用户列表为特定项目?我一直没能找到如何做到这一点尚未...

Does anyone know how I could get the list of all the assignable users for a specific project? I haven't been able to find how to do that yet...

推荐答案

好吧,我必须在更好的形状所以今天在这里是我的问题的一个解决方案。

Ok I must be in better shape today so here is a solution of my problem

    /// <summary>
    /// object interface to the JIRA API
    /// </summary>
    private readonly JiraSoapServiceClient _JiraService;

    /// <summary>
    /// authentication token returned by the login method 
    /// that can be used on all other SOAP methods
    /// </summary>
    private readonly string _Token;

    /// <summary>
    /// name of the RemoteProjectRole "Developers"
    /// </summary>
    private const string DEVELOPER_ROLE = "Developers";

    /// <summary>
    /// id of the RemoteProjectRole "Developers"
    /// </summary>
    private static long? _DeveloperId;

    /// <summary>
    /// return the list of the names of all the users who have
    /// the role "Developers" in a project
    /// </summary>
    /// <param name="project"></param>
    /// <returns></returns>
    public List<string> GetUsersForProject(string project)
    {
        List<string> users = new List<string>();
        try
        {
            // get the RemoteProject
            RemoteProject rp = _JiraService.getProjectByKey(_Token, project);

            // get the "Developers" Prject Role
            RemoteProjectRole developerRole = getDeveloperRole();

            if (developerRole != null)
            {
                // we can use this method only if the user logged in is an administrator
                RemoteRoleActors actors = _JiraService.getProjectRoleActors(_Token, developerRole, rp);
                foreach (RemoteRoleActor actor in actors.roleActors)
                {
                    foreach (RemoteUser user in actor.users)
                    {
                        users.Add(user.name);
                    }
                }
            }
        }
        catch (Exception ex)
        {
            // TODO log the error

            users.Clear();
        }
        users.Sort();
        return users;
    }

    /// <summary>
    /// return the RemoteProjectRole "Developers"
    /// </summary>
    /// <returns></returns>
    private RemoteProjectRole getDeveloperRole()
    {
        RemoteProjectRole developerRole = null;
        if (_DeveloperId == null)
        {
            // the first time we call this function we don't know the id of this role
            // that's why we are obliged to find it with a foreach on all the project roles
            foreach (RemoteProjectRole role in _JiraService.getProjectRoles(_Token))
            {
                if (role.name == DEVELOPER_ROLE)
                {
                    developerRole = role;
                    _DeveloperId = role.id;
                    break;
                }
            }
        }
        else
        {
            // we have the id so we can get directly the RemoteProjectRole from the JIRA SOAP API
            developerRole = _JiraService.getProjectRole(_Token, (long)_DeveloperId);
        }

        return developerRole;
    }

意见是值得欢迎的。
显然,我们可以使用不同的作用方式相同。一个只是有以确保用户用于登录在JIRA API有一些管理员权限

comments are welcome. Obviously, we can use the same way for different role. One just has to be sure that the user used to log in the JIRA api has some admin rights

这篇关于JIRA SOAP API:获取用户列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆