Skip to content
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

Fix denied login for users with many repos. #543

Merged
merged 2 commits into from
Aug 20, 2017
Merged

Conversation

tech4him1
Copy link
Contributor

@tech4him1 tech4him1 commented Aug 19, 2017

- Summary

isCollaborator was created in #491 to block login if a user did not have write (push) permissions to a repo, by going through the list of a users repos until it found the right one. It did not institute pagination, however, so if a user had enough repos that the one in question was on another page, the CMS would assume that they did not have permission and block the login. Since there are only about 30 repos per page, this is a fairly significant bug.

This commit fixes the problem by calling the API for the specific repo instead of getting the whole list.

- Test plan

Tested manually before and after:

  • repo w/permissions.

Tested errors after:

  • repo w/o permissions (no permission error).
  • non-existing repo ("Not Found" error).

- Description for the changelog

Fix denied login for users with many repos.

@tech4him1 tech4him1 changed the title WIP: Fix denied login for users with many repos. (WIP) Fix denied login for users with many repos. Aug 19, 2017
@tech4him1 tech4him1 self-assigned this Aug 19, 2017
Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

Thanks Caleb! Just a code style request, other than that this looks good.

return contributor;
}).catch((error) => {
console.error("Problem with response of /user/repos from GitHub");
return this.request(this.repoURL).then((repo) => (repo.permissions.push)).catch((error) => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nitpick - the extra parens can be dropped, and use multiple lines for clarity:

this.request(...)
  .then(repo => repo.permissions.push)
  .catch(error => {
     ...
  });

Copy link
Contributor Author

@tech4him1 tech4him1 Aug 20, 2017

Choose a reason for hiding this comment

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

@erquhart this should be done.

`isCollaborator` was created in #491 to block login if a user did not have write (push) permissions to a repo, by going through the list of a users repos until it found the right one. It did not institute pagination, however, so if a user had enough repos that the one in question was on another page, the CMS would assume that they did not have permission and block the login.

This commit fixes the problem by calling the API for the specific repo instead of getting the whole list.
@tech4him1 tech4him1 changed the title (WIP) Fix denied login for users with many repos. Fix denied login for users with many repos. Aug 20, 2017
@tech4him1 tech4him1 removed their assignment Aug 20, 2017
jasonlally added a commit to jasonlally/kaldi-hugo-cms-template that referenced this pull request Aug 20, 2017
Copy link
Contributor

@erquhart erquhart left a comment

Choose a reason for hiding this comment

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

LGTM

@erquhart erquhart merged commit 06e5c9d into master Aug 20, 2017
@erquhart erquhart deleted the isCollaborator-fix branch August 20, 2017 20:10
@@ -32,7 +32,7 @@ export default class GitHub {
this.token = state.token;
this.api = new API({ token: this.token, branch: this.branch, repo: this.repo, api_root: this.api_root });
return this.api.user().then(user =>
this.api.isCollaborator(user.login).then((isCollab) => {
this.api.hasWriteAccess().then((isCollab) => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should isCollab be changed as well?

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

Successfully merging this pull request may close these issues.

2 participants