![](/img/trans.png)
[英]How do I get a list of connected TFS projects in Visual Studio?
[英]TFS API - how do I return only projects that an authenticated user has permissions to, instead of the whole list?
我目前正在使用api從TFS返回一個項目列表。
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("some URI"));
var store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
var projects = store.Projects
這很好用。 但是,它將為每個用戶返回我們的TFS團隊項目的完整列表。 有沒有一種方法可以返回或過濾列表,以便僅返回特定用戶有權訪問的項目?
這是使用TFS 2010。
在TFS 2010中,我相信您可以通過在撥打電話時模擬您感興趣的用戶來實現。
TFS 2010 API允許(正確授權)應用程序“模擬”您想要的任何有效用戶並以該用戶身份執行操作。 這是“授權”模擬-您未在以其他用戶身份進行身份驗證,因此沒有密碼輸入,但是您正在“代表”另一位用戶采取措施。 您必須具有特定的權限才能執行此操作,因此您的應用程序需要實際以具有“代表其他用戶的請求”權限的用戶身份運行。
完成后,代碼非常簡單。 您從TPC提取所需的身份,然后在不同的上下文中創建第二個“模擬”的身份,並將該第二個上下文用於您的實際工作:
var tfs = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("some URI"));
var identityService = tfs.GetService<IIdentityManagementService>();
var identity = identity = identityService.ReadIdentity(
IdentitySearchFactor.AccountName,
"someuser",
MembershipQuery.None,
ReadIdentityOptions.None);
var userTfs = new TfsTeamProjectCollection(tfs.Uri, identity.Descriptor);
您對userTfs
采取的任何操作都會像指定的用戶名一樣執行; 這使您可以代表其他用戶查詢項目,隊列構建等。
如果using System.net
添加,則可以使用憑據緩存,並在獲取集合時將當前用戶的默認憑據傳遞給TFS。
using (var tfs = new TfsTeamProjectCollection(tfsUri, CredentialCache.DefaultCredentials))
{
var store = (WorkItemStore)tfs.GetService(typeof(WorkItemStore));
var projects = store.Projects
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.