Skip to content

#569 part 2 : Add Organization Blocking Users API #620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 27 commits into from
Apr 25, 2017

Conversation

varadarajana
Copy link
Contributor

This is continuation of #569. I have made a first cut for review here.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter. We need to confirm that they're okay with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.

@dmitshur
Copy link
Member

dmitshur commented Apr 20, 2017

@varadarajana The commits in this PR are currently identical to the commits in PR #600, which we already merged (as d23570d).

@varadarajana
Copy link
Contributor Author

@shurcooL sorry, I missed pushing my code. Now it is done. you can check commit 7377254.

Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This mostly looks really good. No major issues.

I left 2 inline comments. One you should address (about admin:org scope TODO comments). The other one, I'm waiting to hear back from GitHub support. If they take too long to respond, we can proceed merging this without waiting.

// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#unblock-a-user
func (s *OrganizationsService) UnblockUser(ctx context.Context, org string, user string) (*Response, error) {
// TODO: add a check for scope to be admin:org
u := fmt.Sprintf("user/%v/blocks/%v", org, user)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. It's really surprising to see user/%v/blocks/%v here, instead of orgs/%v/blocks/%v.

However, I can see it matches with what the GitHub API says at https://developer.github.com/v3/orgs/blocking/#unblock-a-user.

But I suspect it's a mistake on their part. Look at how it's inconsistent compared to the user-specific blocks (on the right hand side):

image

This is worthy of sending them an email to clarify. I've done that just now, and I'll report back here when I hear back from them.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shurcooL Thank you, I never realized the URL seems incorrect.

//
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#list-blocked-users
func (s *OrganizationsService) ListBlockedUsers(ctx context.Context, org string, opt *ListOptions) ([]*User, *Response, error) {
// TODO: add a check for scope to be admin:org
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have this // TODO: add a check for scope to be admin:org in 8 places. You also asked:

I have a question. While i was reading the Blocking Users (Organizations) API, I find the following lines:

The token used to authenticate the call must have the admin:org scope in order to make any
blocking calls for an organization. Otherwise, the response returns HTTP 404.

In authorizations.go we have all the scopes defines. I do not see any references to scope anywhere? Is there a central place where this scope validation is done?

Let me answer that here. That note is meant for users of GitHub API. When authenticating, they need to make sure the token they're using has that scope.

There's nothing we need to do for these endpoints inside go-github, that information is for users of go-github. Authentication is orthogonal matter, see https://github.com/google/go-github#authentication.

So, nothing needs to be done here, and you can safely remove these TODOs.

However, if you want, you can add that note to the documentation for these 4 endpoints. E.g.:

// ListBlockedUsers lists all the users blocked by an organization.
//
// The token used to authenticate the call must have the admin:org scope
// in order to make any blocking calls for an organization. Otherwise,
// the response returns HTTP 404.
//
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#list-blocked-users

We generally don't try to document this for all endpoints, people are expected to read GitHub API documentation to figure out what scopes are required. So I'm not sure if it's worth doing or not just here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @shurcooL . I do not think there is a need to document this at end point since one needs to follow the API documentation. I have removed the TODO.

Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. One optional inline comment.

We don't necessarily need to block on a response from GitHub about the strange path. When they reply, if anything needs to be done, we can update it then.

Thanks @varadarajana.

You don't need to do it for this PR, but in the future, please try to have a cleaner PR containing only the relevant commits. You should rebase or cherry-pick your work onto latest master of go-github before sending a PR. That makes reviewing it easier. See https://github.com/servo/servo/wiki/Github-workflow and https://github.com/servo/servo/wiki/Beginner's-guide-to-rebasing-and-squashing for helpful resources on the topic.

w.WriteHeader(http.StatusNoContent)
})

_, err := client.Organizations.BlockUser(context.Background(), "o1", "u1")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason this test uses "o1" and "u1", while the rest use "o" and "u"? It seems a little inconsistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shurcooL I was in a debugging effort and trying out combinations of URL. that's where I out o1 and u1. For consistency as you have mentioned, I have replaced o1 and u1 with o and u.

@dmitshur dmitshur requested a review from gmlewis April 22, 2017 15:51
Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

About #620 (comment), I got a reply from GitHub support:

Thanks for reporting this, Dmitri -- that looks like a bug in the docs. It should be /orgs/:org/blocks/:user. I'll ask our documentation team to fix that up.

//
// GitHub API docs: https://developer.github.com/v3/orgs/blocking/#unblock-a-user
func (s *OrganizationsService) UnblockUser(ctx context.Context, org string, user string) (*Response, error) {
u := fmt.Sprintf("user/%v/blocks/%v", org, user)
Copy link
Member

@dmitshur dmitshur Apr 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Therefore, this should be changed to "orgs/%v/blocks/%v".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@shurcooL I have made these changes in the latest checkin.

Copy link
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM after @shurcooL's comments are addressed.
Thank you, @varadarajana and @shurcooL!

setup()
defer teardown()

mux.HandleFunc("/user/o/blocks/u", func(w http.ResponseWriter, r *http.Request) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Obviously, this line will be changed too once @shurcooL's comments are addressed, to make the tests pass.

Copy link
Member

@dmitshur dmitshur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks @varadarajana!

@dmitshur dmitshur merged commit e8d4666 into google:master Apr 25, 2017
bubg-dev pushed a commit to bubg-dev/go-github that referenced this pull request Jun 16, 2017
This change adds support for user blocking preview API to OrganizationsService.
This preview API was announced at https://developer.github.com/changes/2017-02-28-user-blocking-apis-and-webhook/.
The endpoints are documented at https://developer.github.com/v3/orgs/blocking/.

Follows d23570d.

Helps google#569.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants