1
我想通過使用TFS API REST或在c#中實現方法來添加團隊的管理員...您能幫助我嗎? 有沒有辦法通過代碼來做到這一點,而不是像你可以在圖像中看到的那樣從tfs網站上做到這一點? 謝謝!通過TFS API REST或TFS SERVER API添加TFS 2017中的團隊管理員C#
我想通過使用TFS API REST或在c#中實現方法來添加團隊的管理員...您能幫助我嗎? 有沒有辦法通過代碼來做到這一點,而不是像你可以在圖像中看到的那樣從tfs網站上做到這一點? 謝謝!通過TFS API REST或TFS SERVER API添加TFS 2017中的團隊管理員C#
這是無法通過REST API現在實現了,甚至將用戶添加到團隊。一直有相關的UserVoice的:
添加REST API添加成員團隊
你可以使用TFS API服務器在服務器端實現這一目標,樣本代碼如下:
static void Main(string[] args)
{
// Connect to the TFS server and get the team project URI.
var collection = GetServer("server_uri");
var projectUri = GetProjectUri(collection, "project_name");
// Retrieve the default team.
TfsTeamService teamService = collection.GetService<TfsTeamService>();
TeamFoundationTeam defaultTeam = teamService.GetDefaultTeam(projectUri, null);
// Get security namespace for the project collection.
ISecurityService securityService = collection.GetService<ISecurityService>();
SecurityNamespace securityNamespace = securityService.GetSecurityNamespace(FrameworkSecurity.IdentitiesNamespaceId);
// Use reflection to retrieve a security token for the team.
MethodInfo mi = typeof(IdentityHelper).GetMethod("CreateSecurityToken", BindingFlags.Static | BindingFlags.NonPublic);
string token = mi.Invoke(null, new object[] { defaultTeam.Identity }) as string;
// Retrieve an ACL object for all the team members.
var allMembers = defaultTeam.GetMembers(collection, MembershipQuery.Expanded).Where(m => !m.IsContainer);
AccessControlList acl = securityNamespace.QueryAccessControlList(token, allMembers.Select(m => m.Descriptor), true);
// Retrieve the team administrator SIDs by querying the ACL entries.
var entries = acl.AccessControlEntries;
var admins = entries.Where(e => (e.Allow & 15) == 15).Select(e => e.Descriptor.Identifier);
// Finally, retrieve the actual TeamFoundationIdentity objects from the SIDs.
var adminIdentities = allMembers.Where(m => admins.Contains(m.Descriptor.Identifier));
}
儘管它展示瞭如何查詢團隊管理員,也不難添加管理員。
TeamFoundationIdentity admin
string token = IdentityHelper.CreateSecurityToken(team.Identity);
securityNamespace.SetPermissions(token, admin.Descriptor, 15, 0, true);
確保您使用的帳戶具有足夠的權限添加團隊管理員以運行代碼。更多詳情請參考此問題中的答案:TFS API - How to get a Team's Adminstrator?
謝謝!我需要簡單地這樣做以添加一個管理員: 之後,我得到團隊: string token = IdentityHelper.CreateSecurityToken(_team.Identity); securityNamespace.SetPermissions(token,admin.Descriptor,15,0,true); – Nello360