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

查看:57
本文介绍了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天全站免登陆