簡體   English   中英

獲得用戶所屬的特定項目

[英]get specific projects that a user is a part of

在這里,我使用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();

我只希望他們能夠看到他們有權創建任務/工作項目的項目列表。

工作項目與區域相關,而區域與團隊項目相關。

基本步驟是:

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
            }
        }
    }
}

請注意,我調用了我自己的用戶定義函數(這是我構造的類,將根tfs uri和集合名稱作為字符串傳入)的GetTfsCollection()。 我也沒有進行任何異常處理,只是顯示了基礎知識:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM