Skip to content
This repository has been archived by the owner on Jun 24, 2024. It is now read-only.

Use assignment creator's token when random token fails #2286

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

EricPickup
Copy link
Contributor

@EricPickup EricPickup commented Aug 22, 2019

What

Back-end solution to #2222

When creating a repo for a student, grab a random classroom admin's token (as we currently do).

If the token can access the repo, use that token to create the student repo. Otherwise use the assignment creator's token.

@EricPickup
Copy link
Contributor Author

Update since today is my last day 😢

I held off on this PR since I found some weird behavior testing it locally.

To reproduce:

  1. Create a classroom with two administrators
  2. Create an assignment within that classroom using a private starter code repo that only Admin 1 can access
  3. Try to accept that assignment. It will recognize that not all admins have access and will use the assignment creator (admin 1's) octokit client, but I'm still getting a 403 forbidden even with the proper client.

This might be some weird issues on my environment.

Once this is fixed I suggest adding this under a feature flag to be safe.

@spinecone
Copy link
Contributor

spinecone commented Aug 27, 2019

I've been getting my local environment to test the weird behavior Eric mentioned. So far I haven't reproduced it (the assignment was successfully accepted) but will keep trying tomorrow.

@spinecone
Copy link
Contributor

I dug around in the console and it looks like the Resource could not be found on github.com error is coming from when we try to look at the organization plan, since the GithubOrganization we create around the assignment creator's token isn't a real organization.

@spinecone
Copy link
Contributor

spinecone commented Aug 30, 2019

Rather than creating a fake GithubOrganization around the assignment creator's token and needing to worry about other places where we expect it to behave like an organization (such as checking if it has a free/paid plan, which the fake org returns nil for), I'm working on thinking of a different approach for this problem.

Instead of changing which GithubOrganization object calls create_repository, it might make more sense for us to continue just using the real organization that owns the assignment, and having it try the assignment creator's token itself if it doesn't have access with its own random token.

def create_repository(repo_name, alternate_client, users_repo_options = {})
  repo_options = github_repo_default_options.merge(users_repo_options)

  repo = GitHub::Errors.with_error_handling do
    begin
      @client.create_repository(repo_name, repo_options)
    rescue GitHub::Error
      use_alternate_client = true
      # Try the assignment creator's token before giving up
      alternate_client.create_repository(repo_name, repo_options)
    end
  end

  GitHubRepository.new(use_alternate_client ? alternate_client : @client, repo.id)
end

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

Successfully merging this pull request may close these issues.

4 participants