summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorDouwe Maan <douwe@gitlab.com>2015-04-14 14:50:56 +0200
committerDouwe Maan <douwe@gitlab.com>2015-04-14 14:50:56 +0200
commitdba63d667d536c939400979a22967ed9b25980b2 (patch)
tree224155b5cdd0bc9db91df26436a2387f4a3116af /app
parentf6cb42f3d197b7920207088f5fa5f5161be90905 (diff)
downloadgitlab-ce-dba63d667d536c939400979a22967ed9b25980b2.tar.gz
Allow user map to be specified.
Diffstat (limited to 'app')
-rw-r--r--app/controllers/import/google_code_controller.rb52
-rw-r--r--app/views/import/google_code/new.html.haml13
-rw-r--r--app/views/import/google_code/new_user_map.html.haml20
-rw-r--r--app/views/import/google_code/status.html.haml1
4 files changed, 82 insertions, 4 deletions
diff --git a/app/controllers/import/google_code_controller.rb b/app/controllers/import/google_code_controller.rb
index 9bf29386bc9..fb4ef987367 100644
--- a/app/controllers/import/google_code_controller.rb
+++ b/app/controllers/import/google_code_controller.rb
@@ -1,4 +1,5 @@
class Import::GoogleCodeController < Import::BaseController
+ before_filter :user_map, only: [:new_user_map, :create_user_map]
def new
@@ -17,11 +18,46 @@ class Import::GoogleCodeController < Import::BaseController
return redirect_to :back, alert: "The uploaded file is not a valid Google Takeout archive."
end
- unless Gitlab::GoogleCodeImport::Client.new(dump).valid?
+ client = Gitlab::GoogleCodeImport::Client.new(dump)
+ unless client.valid?
return redirect_to :back, alert: "The uploaded file is not a valid Google Takeout archive."
end
session[:google_code_dump] = dump
+
+ if params[:create_user_map] == "1"
+ redirect_to new_user_map_import_google_code_path
+ else
+ redirect_to status_import_google_code_path
+ end
+ end
+
+ def new_user_map
+
+ end
+
+ def create_user_map
+ user_map_json = params[:user_map]
+ user_map_json = "{}" if user_map_json.blank?
+
+ begin
+ user_map = JSON.parse(user_map_json)
+ rescue
+ flash.now[:alert] = "The entered user map is not a valid JSON user map."
+
+ render "new_user_map" and return
+ end
+
+ unless user_map.is_a?(Hash) && user_map.all? { |k, v| k.is_a?(String) && v.is_a?(String) }
+ flash.now[:alert] = "The entered user map is not a valid JSON user map."
+
+ render "new_user_map" and return
+ end
+
+ session[:google_code_user_map] = user_map
+
+ flash[:notice] = "The user map has been saved. Continue by selecting the projects you want to import."
+
redirect_to status_import_google_code_path
end
@@ -51,7 +87,9 @@ class Import::GoogleCodeController < Import::BaseController
namespace = @target_namespace
- @project = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, current_user).execute
+ user_map = session[:google_code_user_map]
+
+ @project = Gitlab::GoogleCodeImport::ProjectCreator.new(repo, namespace, current_user, user_map).execute
end
private
@@ -60,4 +98,14 @@ class Import::GoogleCodeController < Import::BaseController
@client ||= Gitlab::GoogleCodeImport::Client.new(session[:google_code_dump])
end
+ def user_map
+ @user_map ||= begin
+ user_map = client.user_map
+
+ stored_user_map = session[:google_code_user_map]
+ user_map.update(stored_user_map) if stored_user_map
+
+ Hash[user_map.sort]
+ end
+ end
end
diff --git a/app/views/import/google_code/new.html.haml b/app/views/import/google_code/new.html.haml
index 0b4edc68428..ce78fec205f 100644
--- a/app/views/import/google_code/new.html.haml
+++ b/app/views/import/google_code/new.html.haml
@@ -46,6 +46,15 @@
%input{type: "file", name: "dump_file", id: "dump_file"}
%li
%p
- Continue to the next step:
+ Do you want to customize how Google Code email addresses and usernames are imported into GitLab?
%p
- = submit_tag 'Select projects to import', class: "btn btn-create"
+ = label_tag :create_user_map_0 do
+ = radio_button_tag :create_user_map, 0, true
+ No, directly import the existing email addresses and usernames.
+ %p
+ = label_tag :create_user_map_1 do
+ = radio_button_tag :create_user_map, 1, false
+ Yes, let me map Google Code users to full names or GitLab users.
+ %li
+ %p
+ = submit_tag 'Continue to the next step', class: "btn btn-create"
diff --git a/app/views/import/google_code/new_user_map.html.haml b/app/views/import/google_code/new_user_map.html.haml
new file mode 100644
index 00000000000..2996d3b659b
--- /dev/null
+++ b/app/views/import/google_code/new_user_map.html.haml
@@ -0,0 +1,20 @@
+%h3.page-title
+ %i.fa.fa-google
+ Import projects from Google Code
+%hr
+
+= form_tag create_user_map_import_google_code_path, class: 'form-horizontal' do
+ %p
+ Customize how Google Code email addresses and usernames are imported into GitLab.
+ In the next step, you'll be able to select the projects you want to import.
+ %p
+ The user map is a JSON document mapping Google Code users (as keys) to the way they will be imported into GitLab (as values). By default the username is masked to ensure users' privacy.
+ %p
+ To map a Google Code user to a full name or GitLab user, simply replace the value, e.g. <code>"johnsmith@gmail.com": "John Smith"</code> or <code>"johnsmith@gmail.com": "@johnsmith"</code>. Be sure to preserve the surrounding double quotes and other interpunction.
+
+ .form-group
+ .col-sm-12
+ = text_area_tag :user_map, JSON.pretty_generate(@user_map), class: 'form-control', rows: 15
+
+ .form-actions
+ = submit_tag 'Continue to the next step', class: "btn btn-create"
diff --git a/app/views/import/google_code/status.html.haml b/app/views/import/google_code/status.html.haml
index eba9c5296bc..8f24a1ce85d 100644
--- a/app/views/import/google_code/status.html.haml
+++ b/app/views/import/google_code/status.html.haml
@@ -7,6 +7,7 @@
%hr
%p
= button_tag 'Import all projects', class: "btn btn-success js-import-all"
+ = link_to "Specify user map", new_user_map_import_google_code_path, class: "btn prepend-left-10"
%table.table.import-jobs
%thead