gpt4 book ai didi

c# - 集会 API : Adding Users to a Project

转载 作者:太空宇宙 更新时间:2023-11-03 16:23:34 26 4
gpt4 key购买 nike

我是 Rally 世界的新手,正在努力了解如何使用 RallyRestAPI。有许多示例说明如何查询 Rally 以获取我认为最有帮助的相关信息。我想要做的是创建一个 C# 命令行工具来将用户添加到项目中。看来我使用 RallyRestAPI.Create("projectpermission",some dynamic json object) 接口(interface)来完成创建。我的问题是理解“一些动态 json 对象”部分。我不确定如何正确设置它。如果有人有一个如何设置它的小例子,我将不胜感激。

最佳答案

这是一个代码示例,说明了如何执行此操作。请注意:

  • 运行代码以创建权限的用户 ID 必须是工作区或订阅管理员
  • 用户必须已经在工作区中拥有权限(即成为工作区用户)才能成功创建 ProjectPermission

    命名空间 RestExample_AddUsersToProject { 类(class)计划 { 静态无效主要(字符串[]参数) {

            String userName = "user@company.com";
    String userPassword = "topsecret";
    String serverUrl = "https://rally1.rallydev.com";
    String wsapiVersion = "1.38";

    RallyRestApi restApi = new RallyRestApi(
    userName,
    userPassword,
    serverUrl,
    wsapiVersion
    );

    restApi.Headers[RallyRestApi.HeaderType.Vendor] = "Rally Software";
    restApi.Headers[RallyRestApi.HeaderType.Name] = "RestExample_AddUsersToProject";

    // Query for Project for which we want to add permissions
    Request projectRequest = new Request("project");
    projectRequest.Fetch = new List<string>()
    {
    "Name",
    "Owner",
    "State",
    "Description"
    };
    String projectName = "Avalanche Hazard Mapping";

    projectRequest.Query = new Query("Name", Query.Operator.Equals, projectName);
    QueryResult queryProjectResults = restApi.Query(projectRequest);
    var myProject = queryProjectResults.Results.First();
    String myProjectReference = myProject["_ref"];

    Console.WriteLine("Project Name: " + myProject["Name"]);
    Console.WriteLine("State: " + myProject["State"]);

    // Query for User for whom we wish to add ProjectPermission
    Request userRequest = new Request("user");
    userRequest.Fetch = new List<string>()
    {
    "UserName",
    "Subscription",
    "DisplayName"
    };


    // User needing the permissions
    userRequest.Query = new Query("UserName", Query.Operator.Equals, "\"boromir@midearth.com\"");
    QueryResult queryUserResults = restApi.Query(userRequest);

    var myUser = queryUserResults.Results.First();
    String myUserReference = myUser["_ref"];

    Console.WriteLine("Username: " + myUser["UserName"]);
    Console.WriteLine("Display Name: " + myUser["DisplayName"]);
    Console.WriteLine("Subscription: " + myUser["Subscription"]);

    // Setup required ProjectPermission data
    DynamicJsonObject newProjectPermission = new DynamicJsonObject();

    newProjectPermission["User"] = myUser;
    newProjectPermission["Project"] = myProject;
    newProjectPermission["Role"] = "Editor";

    // Create the permission in Rally
    CreateResult addProjectPermissionResult = restApi.Create("ProjectPermission", newProjectPermission);

    DynamicJsonObject fetchedProjectPermission = restApi.GetByReference(addProjectPermissionResult.Reference, "Name");
    Console.WriteLine("Created ProjectPermission with Role: " + fetchedProjectPermission["Name"]);
    }
    }

关于c# - 集会 API : Adding Users to a Project,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13241881/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com