GitHub API v3:确定用户是否是组织的所有者 [英] GitHub API v3: Determine if user is an Owner of an Organization

查看:36
本文介绍了GitHub API v3:确定用户是否是组织的所有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果您知道id :

It's easy to determine if a User is a member of a Team if you know the id:

GET /teams/:id/members/:user

但是,如何轻松确定每个组织拥有的特殊所有者"团队的ID?

But how can one easily determine the ID of the special "Owners" team that every Organization has?

据我所知,唯一的方法是检索所有团队的完整列​​表(我认为可能是多个页面?)并逐步浏览它们,直到找到名称为所有者"的一个.

As far as I can tell, the only way is to retrieve a full list of all Teams (which I assume may be multiple pages?) and walk through them until you find one with the name "Owners".

这当然是可行的,但是对于GitHub的原本很棒的API来说,这通常并不方便. ;)

This is doable of course, but it's uncharacteristically inconvenient for GitHub's otherwise fantastic API. ;)

对于它的价值,我尝试了以下操作(没有运气):

For what it's worth, I've tried the following (with no luck):

GET /orgs/:organization/teams?name=Owners # Lists all teams
GET /orgs/:organization/owners            # 404

请清楚一点,我确保使用与拥有相关组织的用户相关的令牌,因此不应有任何授权问题.

Just to be clear, I've made sure to use a token associated with the user that owns the organization in question, so there shouldn't be any authorization issues.

推荐答案

当前没有简单的方法来检查用户是否在所有者团队中.不过,感谢您的酷炫功能建议! ;)

There is currently no easy way to check if a user is in the owners team. Thanks for the cool feature suggestion, though! ;)

一种变通的解决方法将涉及执行仅允许所有者执行的非破坏性操作.如果操作成功-身份验证的用户是所有者.

A hacky workaround would involve performing a non-destructive operation which only owners are allowed to do. If the operation succeeds - the authenticated user is an owner.

例如,您可以尝试通过发送一个空的JSON哈希来编辑组织的设置:

For example, you could try editing the organization's settings by sending an empty JSON hash:

$ curl -v -X PATCH -d '{}' https://api.github.com/orgs/:org?access_token=TOKEN

如果此命令返回200状态代码,则该用户是所有者. 404状态码则以其他方式发出信号.

If this returns a 200 status code, the user is an owner. A 404 status code signals otherwise.

希望我们将来能够提供更优雅的解决方案.

Hopefully we can provide a more elegant solution in the future.

这篇关于GitHub API v3:确定用户是否是组织的所有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆