Setup team or users permissions with VSTS REST API

2020-08-01 05:11发布

问题:

Is it possible to setup the teams or users permissions via the VSTS Rest API ?

I've only found posts that are quite old and without any update on the subject. On the API page it seems like it would be possible to remove them for users or groups but not list the permissions for a specific user or add some.

https://docs.microsoft.com/en-us/rest/api/vsts/security/permissions/remove%20permission?view=vsts-rest-4.1

回答1:

The REST API is not documented, however you can track it by tools such as Fiddler or press F12 in Chrome browser then select Network.

e.g. I can use below REST API To set the Delete team project permission to Allow for my team Team0416 in below sample:

POST https://{account}.visualstudio.com/{Project}/_api/_security/ManagePermissions?__v=5

Request body:

{"updatePackage":"{\"IsRemovingIdentity\":false,\"TeamFoundationId\":\"18de9da7-7edc-4c1d-88e0-e2420020e6dd\",\"DescriptorIdentityType\":\"Microsoft.TeamFoundation.Identity\",\"DescriptorIdentifier\":\"S-1-9-1551374245-717605811-4129483085-2927145651-87449592-1-853620709-4198499904-2869176592-1434840851\",\"PermissionSetId\":\"52d39943-cb85-4d7f-8fa8-c6baac873819\",\"PermissionSetToken\":\"vstfs:///Classification/TeamProject/b3cbc52a-22f6-4de9-ae78-b2b305365ff8\",\"RefreshIdentities\":false,\"Updates\":[{\"PermissionId\":1,\"PermissionBit\":4,\"NamespaceId\":\"52d39943-cb85-4d7f-8fa8-c6baac873819\",\"Token\":\"$PROJECT:vstfs:///Classification/TeamProject/b3cbc52a-22f6-4de9-ae78-b2b305365ff8:\"}],\"TokenDisplayName\":null}"}

The key points:

"Updates\":[{\"PermissionId\":1, in the request body:

--> 0 means Not set,1 means Allow, 2 means Deny

Besides, you can use Permission Command to modify the user access control list (ACL) and displays authorization settings for an item under version control.

And you can use the TFSSecurity command-line tool to create, modify, and delete groups and users in TFS, in addition to modifying permissions for groups and users.