I want to add or remove users from TFS using REST API. Any help appreciated.
可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
回答1:
Afraid this can't be achieved through Rest API for now. If you really want to do it programmatically. You can use client API.
You can try to use IIdentityManagementService.ReadIdentity()
along with IIdentityManagementService.AddMemberToApplicationGroup()
to add Windows users to TFS groups, even if those Windows users are not known to TFS yet.
This is accomplished by specifying the ReadIdentityOptions.IncludeReadFromSource
option.
Below is an example of adding a Windows user VSALM\Barry
to the Fabrikam Fiber Web Team
(TFS Group), in the FabrikamFiber
Team Project, in the http://vsalm:8080/tfs/FabrikamFiberCollection
(Also applies to server level)
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.Framework.Client;
using Microsoft.TeamFoundation.Framework.Common;
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
var tpc = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://vsalm:8080/tfs/FabrikamFiberCollection"));
var ims = tpc.GetService<IIdentityManagementService>();
var tfsGroupIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"[FabrikamFiber]\\Fabrikam Fiber Web Team",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
var userIdentity = ims.ReadIdentity(IdentitySearchFactor.AccountName,
"VSALM\\Barry",
MembershipQuery.None,
ReadIdentityOptions.IncludeReadFromSource);
ims.AddMemberToApplicationGroup(tfsGroupIdentity.Descriptor, userIdentity.Descriptor);
}
}
}