获取用户可以访问的项目列表

发布于 2025-01-27 21:59:14 字数 376 浏览 4 评论 0原文

我有一个自动化网站,并希望向用户显示他们可以在下拉列表中访问的项目列表。 如果我在组织中有管理帐户的AA PAT,如何获取给定用户电子邮件的项目列表?

大概是REST API是这样做的最佳方法?

https:https:// https:// .microsoft.com/en-us/rest/api/azure/devops/?view = azure-devops-rest-7.1

I have a site for automation, and want to display to users a list of projects they have access to in a dropdown.
If I have a a PAT for an admin account in the org, how can I get the list of projects given a user's email?

Presumably the REST api is the best way to do this?

https://learn.microsoft.com/en-us/rest/api/azure/devops/?view=azure-devops-rest-7.1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉目亦如画i 2025-02-03 21:59:15

我找到了两种方法。

:列出所有项目,基于用户列表的过滤

projects = GET https://dev.azure.com/{orgname}/_apis/projects?api-version=6.0
results = []
foreach project in projects:
    descriptor = GET https://vssps.dev.azure.com/{orgname}/_apis/graph/descriptors/{project.id}
    members = GET https://vssps.dev.azure.com/{orgname}/_apis/graph/users?api-version=6.0-preview.1&scopeDescriptor={descriptor}
    if userId in members:
        results.push(project)

第一个方法
这更好,因为这将显示人们拥有读者(或更高)的所有项目,其中第一个方法没有显示用户没有明确会员资格的项目,

users = GET https://vsaex.dev.azure.com/{orgname}/_apis/UserEntitlements?$filter=name eq '{userId}'&$orderBy=name Ascending&select=Projects
user = [x for x in users where x.userId == userId][0]
results = user.projectEntitlements

请注意 select 第二个示例中包含的查询参数,这对于projectEntiTlements中的结果是必不可少的。

I've found two ways to do this.

First method: list all projects, filter based on user list

projects = GET https://dev.azure.com/{orgname}/_apis/projects?api-version=6.0
results = []
foreach project in projects:
    descriptor = GET https://vssps.dev.azure.com/{orgname}/_apis/graph/descriptors/{project.id}
    members = GET https://vssps.dev.azure.com/{orgname}/_apis/graph/users?api-version=6.0-preview.1&scopeDescriptor={descriptor}
    if userId in members:
        results.push(project)

Second method: get user entitlements
This is better because this will show all projects that people have Reader (or higher) on, where the first method doesn't show projects where the user doesn't have explicit membership

users = GET https://vsaex.dev.azure.com/{orgname}/_apis/UserEntitlements?$filter=name eq '{userId}'&$orderBy=name Ascending&select=Projects
user = [x for x in users where x.userId == userId][0]
results = user.projectEntitlements

Note the select query parameter included in the second example, this is necessary for projectEntitlements to be included in the result.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文