我想使用对象模型库获取VSTS中的用户访问权限。我想知道用户是否具有“基本”或“堆叠持有人”权利。
由于
答案 0 :(得分:0)
VSTS的其余API中有一个GET方法:User Entitlements。
它返回用户的权利(疯狂权利),其中包含accountLicenseType
中的accessLevel
GET https://{accountName}.vsaex.visualstudio.com/_apis/userentitlements/{userId}?api-version=4.1-preview.1
"accessLevel": {
"licensingSource": "account",
**"accountLicenseType": "stakeholder",**
"msdnLicenseType": "none",
"licenseDisplayName": "Stakeholder",
"status": "active",
"statusMessage": "",
"assignmentSource": "unknown"
},
"lastAccessedDate": "0001-01-01T00:00:00Z",
"projectEntitlements": [],
"extensions": [],
"groupAssignments": []
}
答案 1 :(得分:0)
您可以RestClinet调用API并获取响应json信息,还需要安装 RestSharp NuGet 软件包。简单的REST和HTTP API客户端
获取VSTS用户列表以供参考的示例代码:
static void Main(string[] args)
{
// Asking for a maximum of 1000 users to be returned
var client = new RestClient("https://YOUR-ACCOUNT-HERE.vsaex.visualstudio.com/_apis/userentitlements?api-version=4.1-preview&top=1000");
var request = new RestRequest(Method.GET);
request.AddHeader("Authorization", "Basic YOUR-PAT-HERE!");
IRestResponse response = client.Execute(request);
var users = JsonConvert.DeserializeObject<Rootobject>(response.Content);
foreach (var user in users.value.OrderBy(x => x.user.mailAddress))// Sorting results by e-mail address
{
Console.WriteLine($"{user.user.mailAddress},{user.lastAccessedDate.ToLocalTime():yyyy-MM-dd HH:mm:ss},{user.accessLevel.licenseDisplayName}");
}
Console.ReadKey(); // Pause the command window (for testing)
}
更多详细信息,请参阅本教程博客:GET A LIST OF VSTS USERS WITH APIS
您应该使用Rest API:
GET https://{accountName}.vsaex.visualstudio.com/_apis/userentitlements/{userId}?api-version=4.1-preview.1
对于单个用户,只需指定用户ID并获取 accountLicenseType 以返回json。