gpt4 book ai didi

c# - 获取用户参与的特定项目

转载 作者:太空宇宙 更新时间:2023-11-03 15:52:05 24 4
gpt4 key购买 nike

在这里,我使用 IIdentityManagementService 按名称检索指定的用户。现在我只想检索他们所属的那些团队项目,并且可以在 TFS 中为其创建任务/工作项。我的程序允许用户在 TFS 中创建任务,我只希望他们能够看到他们有权访问以创建任务/工作项的项目列表。

var tfsTpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://dotnettfs:8080/tfs/"));
identityService = tfsTpc.GetService<IIdentityManagementService>();
userId = identityService.ReadIdentity(
IdentitySearchFactor.DisplayName,
strOutlookUser,
MembershipQuery.Direct,
ReadIdentityOptions.None
);

userTpc = new TfsTeamProjectCollection(tfsTpc.Uri, userId.Descriptor);
cssService = (ICommonStructureService4)userTpc.GetService(typeof(ICommonStructureService4));

wis = userTpc.GetService<WorkItemStore>();
lstAllProjects.AddRange(cssService.ListAllProjects().ToList());
List<string> lstViewProjectNames = lstAllProjects.Select(a => a.Name).ToList();

现在,当我希望它只显示检索到的用户有权访问的那些项目时,列表会显示该软件集合中的所有项目。

然后他们可以创建任务并指定其中一个项目的迭代和区域。

var store = wis.Projects[0]; //should be a specified project, not the first element.
WorkItem pbi = new WorkItem(store.WorkItemTypes["Product Backlog Item"]);

pbi.IterationPath = lstIterations.Where(a => a.Name == selectedIteration.ToString())
.Select(a => a.Path).First().ToString();


pbi.AreaPath = lstAreas.Where(a => a.Name == selectedArea.ToString())
.Select(a => a.Path).First().ToString();

最佳答案

I only want them to be able to see a list of the projects which they have access to for creating tasks/work items.

工作项与区域相关联,而区域与团队项目相关联。

基本步骤是:

1) 以相关用户身份连接到 TFS

2) 检索有问题的团队项目

3) 获取相关团队项目的区域

4) 检查每个节点的创建工作项的能力(你可能可以只对根区域节点进行递归检查)

您将需要的用法(可能不需要全部):

using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using Microsoft.TeamFoundation.Server;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.WorkItemTracking.Client;

IIdentityManagementService identityManagementService = tpc.GetService<IIdentityManagementService>();
TfsTeamProjectCollection tpc = GetTfsCollection();
TeamFoundationIdentity identity = identityManagementService.ReadIdentity(IdentitySearchFactor.AccountName, @"Domain\username", MembershipQuery.None, ReadIdentityOptions.None);
TfsTeamProjectCollection impersonatedTPC = new TfsTeamProjectCollection(new Uri(this._tfsUri, this._tfsCollectionName), identity.Descriptor);
WorkItemStore impersonatedWIS = impersonatedTPC.GetService<WorkItemStore>();
ProjectCollection impersonatedProjects = impersonatedWIS.Projects;
foreach (Project p in impersonatedProjects)
{
if (p.Name == "My Team Project")
{
NodeCollection areas = p.AreaRootNodes;
foreach (Node area in areas)
{
if (area.HasWorkItemWriteRightsRecursive)
{
//They do have rights
}
}
}
}

请注意,我调用了我自己的用户定义函数 GetTfsCollection()(这只是我构建的类,传入根 tfs uri 和集合名称作为字符串)。我也没有进行任何异常处理,只是展示了基础知识:

private TfsTeamProjectCollection GetTfsCollection()
{
return TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri(this._tfsUri, this._tfsCollectionName));
}

关于c# - 获取用户参与的特定项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25388519/

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