summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJames Lopez <james@jameslopez.es>2016-08-08 15:05:58 +0200
committerJames Lopez <james@jameslopez.es>2016-09-20 10:14:39 +0200
commit0c65112da79e177da3574458c3bb5befc349fd30 (patch)
treef3715fa7342143d1fd7bd53278c3ecf279e87c49 /app
parent95b9421ad3b2678da6e0af0131eafd52cdd0b2a5 (diff)
downloadgitlab-ce-0c65112da79e177da3574458c3bb5befc349fd30.tar.gz
modify github import JS and controller so we can now specify a namespace and/or name for a project.
- Fixed and added specs. - Added different namespace options depending on user privilages - Updated docs.
Diffstat (limited to 'app')
-rw-r--r--app/assets/javascripts/importer_status.js14
-rw-r--r--app/assets/stylesheets/pages/projects.scss6
-rw-r--r--app/controllers/import/github_controller.rb7
-rw-r--r--app/helpers/namespaces_helper.rb14
-rw-r--r--app/views/import/github/status.html.haml13
5 files changed, 42 insertions, 12 deletions
diff --git a/app/assets/javascripts/importer_status.js b/app/assets/javascripts/importer_status.js
index 9efad1ce943..9fe00a0a4db 100644
--- a/app/assets/javascripts/importer_status.js
+++ b/app/assets/javascripts/importer_status.js
@@ -14,20 +14,20 @@
$btn = $(e.currentTarget);
$tr = $btn.closest('tr');
$target_field = $tr.find('.import-target');
- $namespace_input = $target_field.find('input');
+ $namespace_input = $target_field.find('.js-select-namespace option:selected');
id = $tr.attr('id').replace('repo_', '');
target_namespace = null;
-
+ new_name = null;
if ($namespace_input.length > 0) {
- target_namespace = $namespace_input.prop('value');
- $target_field.empty().append(target_namespace + "/" + ($target_field.data('project_name')));
+ target_namespace = $namespace_input[0].innerHTML;
+ new_name = $target_field.find('#path').prop('value');
+ $target_field.empty().append(target_namespace + "/" + new_name);
}
-
$btn.disable().addClass('is-loading');
-
return $.post(_this.import_url, {
repo_id: id,
- target_namespace: target_namespace
+ target_namespace: target_namespace,
+ new_name: new_name
}, {
dataType: 'script'
});
diff --git a/app/assets/stylesheets/pages/projects.scss b/app/assets/stylesheets/pages/projects.scss
index db46d8072ce..986a22f4e6e 100644
--- a/app/assets/stylesheets/pages/projects.scss
+++ b/app/assets/stylesheets/pages/projects.scss
@@ -770,3 +770,9 @@ pre.light-well {
}
}
}
+
+.input-group {
+ .project-path {
+ padding: 0;
+ }
+} \ No newline at end of file
diff --git a/app/controllers/import/github_controller.rb b/app/controllers/import/github_controller.rb
index 8c6bdd16383..ee7d498c59c 100644
--- a/app/controllers/import/github_controller.rb
+++ b/app/controllers/import/github_controller.rb
@@ -40,11 +40,12 @@ class Import::GithubController < Import::BaseController
def create
@repo_id = params[:repo_id].to_i
repo = client.repo(@repo_id)
- @project_name = repo.name
- @target_namespace = find_or_create_namespace(repo.owner.login, client.user.login)
+ @project_name = params[:new_name].presence || repo.name
+ namespace_path = params[:target_namespace].presence || current_user.namespace_path
+ @target_namespace = find_or_create_namespace(namespace_path, current_user.namespace_path)
if current_user.can?(:create_projects, @target_namespace)
- @project = Gitlab::GithubImport::ProjectCreator.new(repo, @target_namespace, current_user, access_params).execute
+ @project = Gitlab::GithubImport::ProjectCreator.new(repo, @project_name, @target_namespace, current_user, access_params).execute
else
render 'unauthorized'
end
diff --git a/app/helpers/namespaces_helper.rb b/app/helpers/namespaces_helper.rb
index 94c6b548ecd..af06833ef91 100644
--- a/app/helpers/namespaces_helper.rb
+++ b/app/helpers/namespaces_helper.rb
@@ -1,6 +1,9 @@
module NamespacesHelper
- def namespaces_options(selected = :current_user, display_path: false)
+ def namespaces_options(selected = :current_user, extra_groups = [], display_path: false)
groups = current_user.owned_groups + current_user.masters_groups
+
+ groups += process_extra_groups(extra_groups) if extra_groups.any?
+
users = [current_user.namespace]
data_attr_group = { 'data-options-parent' => 'groups' }
@@ -25,6 +28,15 @@ module NamespacesHelper
grouped_options_for_select(options, selected)
end
+ def process_extra_groups(extra_groups)
+ # Remove duplicate groups - we either keep the ones that exist for the user
+ # (already in groups) or ignore those that do not belong to the user.
+ duplicated_groups = extra_groups.map { |name| Namespace.where(name: name).map(&:name) }
+ extra_groups = extra_groups - duplicated_groups.flatten
+
+ extra_groups.map { |name| Group.new(name: name) }
+ end
+
def namespace_icon(namespace, size = 40)
if namespace.kind_of?(Group)
group_icon(namespace)
diff --git a/app/views/import/github/status.html.haml b/app/views/import/github/status.html.haml
index bd3be20c4f8..8e552fbd005 100644
--- a/app/views/import/github/status.html.haml
+++ b/app/views/import/github/status.html.haml
@@ -45,7 +45,18 @@
%td
= github_project_link(repo.full_name)
%td.import-target
- = import_project_target(repo.owner.login, repo.name)
+ %fieldset.row
+ .input-group
+ .col-xs-11.col-sm-5.project-path
+ - if current_user.can_select_namespace? && !current_user.can_create_group?
+ = select_tag :namespace_id, namespaces_options(params[:namespace_id] || :current_user, display_path: true), {class: 'project-path select2 js-select-namespace', tabindex: 1}
+ - elsif current_user.can_create_group?
+ = select_tag :namespace_id, namespaces_options(params[:namespace_id] || :current_user, [repo.owner.login]), {class: 'project-path select2 js-select-namespace', tabindex: 1}
+ - else
+ = text_field_tag :path, current_user.namespace_path, class: "form-control", tabindex: 2, autofocus: true, disabled: true
+
+ .col-xs-12.col-sm-6.project-path
+ = text_field_tag :path, repo.name, class: "form-control", tabindex: 2, autofocus: true, required: true
%td.import-actions.job-status
= button_tag class: "btn btn-import js-add-to-import" do
Import