diff options
author | Eric K Idema <eki@vying.org> | 2016-05-02 11:22:38 -0400 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2016-06-30 18:48:17 +0200 |
commit | 12aa1f898dbfea3aaeb2de351ac1cccef304717f (patch) | |
tree | 86a15a55b4bd1666e7994d702a684589afa8efa4 /app/controllers/import | |
parent | c5d164d1df46eb34668a032b234484f142e1a881 (diff) | |
download | gitlab-ce-12aa1f898dbfea3aaeb2de351ac1cccef304717f.tar.gz |
Import from Github using Personal Access Tokens.
This stands as an alternative to using OAuth to access a user's Github
repositories. This is setup in such a way that it can be used without OAuth
configuration.
From a UI perspective, the how to import modal has been replaced by a full
page, which includes a form for posting a personal access token back to the
Import::GithubController.
If the user has logged in via GitHub, skip the Personal Access Token and go
directly to Github for an access token via OAuth.
Diffstat (limited to 'app/controllers/import')
-rw-r--r-- | app/controllers/import/github_controller.rb | 25 |
1 files changed, 22 insertions, 3 deletions
diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb index 67bf4190e7e..95852c6941c 100644 --- a/app/controllers/import/github_controller.rb +++ b/app/controllers/import/github_controller.rb @@ -1,14 +1,29 @@ class Import::GithubController < Import::BaseController before_action :verify_github_import_enabled - before_action :github_auth, except: :callback + before_action :github_auth, except: [:callback, :new, :personal_access_token] rescue_from Octokit::Unauthorized, with: :github_unauthorized + helper_method :logged_in_with_github? + + def new + if logged_in_with_github? + go_to_github_for_permissions + elsif session[:github_access_token] + redirect_to status_import_github_url + end + end + def callback session[:github_access_token] = client.get_token(params[:code]) redirect_to status_import_github_url end + def personal_access_token + session[:github_access_token] = params[:personal_access_token] + redirect_to status_import_github_url + end + def status @repos = client.repos @already_added_projects = current_user.created_projects.where(import_type: "github") @@ -57,10 +72,14 @@ class Import::GithubController < Import::BaseController end def github_unauthorized - go_to_github_for_permissions + session[:github_access_token] = nil + redirect_to new_import_github_url, + alert: 'Access denied to your GitHub account.' end - private + def logged_in_with_github? + current_user.identities.exists?(provider: 'github') + end def access_params { github_access_token: session[:github_access_token] } |