From 59bb635e0e94a0e6c61a0c53cdb70a4eb7bd3910 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 13:27:48 +0200 Subject: Set project path & name in one field without transforamtion Signed-off-by: Dmitriy Zaporozhets --- app/services/projects/create_service.rb | 10 ++++------ app/views/projects/new.html.haml | 23 +++++------------------ 2 files changed, 9 insertions(+), 24 deletions(-) diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 3672b623806..7b06ce9a337 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -12,12 +12,10 @@ module Projects @project.visibility_level = default_features.visibility_level end - # Parametrize path for project - # - # Ex. - # 'GitLab HQ'.parameterize => "gitlab-hq" - # - @project.path = @project.name.dup.parameterize unless @project.path.present? + # Set project name from path + unless @project.name.present? + @project.name = @project.path.dup + end # get namespace id namespace_id = params[:namespace_id] diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index e77ef84f51c..f0f9d74c808 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -5,10 +5,13 @@ = form_for @project, html: { class: 'new_project form-horizontal' } do |f| .form-group.project-name-holder - = f.label :name, class: 'control-label' do + = f.label :path, class: 'control-label' do %strong Project name .col-sm-10 - = f.text_field :name, placeholder: "Example Project", class: "form-control", tabindex: 1, autofocus: true + .input-group + = f.text_field :path, placeholder: "my-awesome-project", class: "form-control", tabindex: 1, autofocus: true + .input-group-addon + \.git - if current_user.can_select_namespace? .form-group @@ -18,22 +21,6 @@ = f.select :namespace_id, namespaces_options(params[:namespace_id] || :current_user), {}, {class: 'select2', tabindex: 2} %hr - .js-toggle-container - .form-group - .col-sm-2 - .col-sm-10 - = link_to "#", class: 'js-toggle-button' do - %i.fa.fa-pencil-square-o - %span Customize repository name? - .js-toggle-content.hide - .form-group - = f.label :path, class: 'control-label' do - %span Repository name - .col-sm-10 - .input-group - = f.text_field :path, class: 'form-control' - %span.input-group-addon .git - .js-toggle-container .form-group .col-sm-2 -- cgit v1.2.1 From ed2bcf952be8e6431ad5d3fb7b39927880b512b0 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 13:50:58 +0200 Subject: Set group path during creation Signed-off-by: Dmitriy Zaporozhets --- app/controllers/groups_controller.rb | 2 +- app/views/projects/edit.html.haml | 2 ++ app/views/projects/new.html.haml | 2 +- app/views/shared/_group_form.html.haml | 18 ++++++++++++++---- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/app/controllers/groups_controller.rb b/app/controllers/groups_controller.rb index 36222758eb2..1ea2a2a8c18 100644 --- a/app/controllers/groups_controller.rb +++ b/app/controllers/groups_controller.rb @@ -23,7 +23,7 @@ class GroupsController < ApplicationController def create @group = Group.new(group_params) - @group.path = @group.name.dup.parameterize if @group.name + @group.name = @group.path.dup unless @group.name if @group.save @group.add_owner(current_user) diff --git a/app/views/projects/edit.html.haml b/app/views/projects/edit.html.haml index b85cf7d8d37..f2bb56b5664 100644 --- a/app/views/projects/edit.html.haml +++ b/app/views/projects/edit.html.haml @@ -136,6 +136,8 @@ .col-sm-9 .form-group .input-group + .input-group-addon + #{URI.join(root_url, @project.namespace.path)}/ = f.text_field :path, class: 'form-control' %span.input-group-addon .git %ul diff --git a/app/views/projects/new.html.haml b/app/views/projects/new.html.haml index f0f9d74c808..f320a2b505e 100644 --- a/app/views/projects/new.html.haml +++ b/app/views/projects/new.html.haml @@ -6,7 +6,7 @@ = form_for @project, html: { class: 'new_project form-horizontal' } do |f| .form-group.project-name-holder = f.label :path, class: 'control-label' do - %strong Project name + %strong Project path .col-sm-10 .input-group = f.text_field :path, placeholder: "my-awesome-project", class: "form-control", tabindex: 1, autofocus: true diff --git a/app/views/shared/_group_form.html.haml b/app/views/shared/_group_form.html.haml index 93294e42505..e0bf77db10f 100644 --- a/app/views/shared/_group_form.html.haml +++ b/app/views/shared/_group_form.html.haml @@ -1,9 +1,19 @@ +- if @group.persisted? + .form-group + = f.label :name, class: 'control-label' do + Group name + .col-sm-10 + = f.text_field :name, placeholder: 'open-source', class: 'form-control' + .form-group - = f.label :name, class: 'control-label' do - Group name + = f.label :path, class: 'control-label' do + Group path .col-sm-10 - = f.text_field :name, placeholder: 'Example Group', class: 'form-control', - autofocus: local_assigns[:autofocus] || false + .input-group + .input-group-addon + = root_url + = f.text_field :path, placeholder: 'open-source', class: 'form-control', + autofocus: local_assigns[:autofocus] || false .form-group.group-description-holder = f.label :description, 'Details', class: 'control-label' -- cgit v1.2.1 From 52a8e5c01a2a5377dbd51587f8197c49b17430b3 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 13:55:32 +0200 Subject: Set group name from path in admin controller Signed-off-by: Dmitriy Zaporozhets --- app/controllers/admin/groups_controller.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/controllers/admin/groups_controller.rb b/app/controllers/admin/groups_controller.rb index e6d0c9323c1..8c7d90a5d9f 100644 --- a/app/controllers/admin/groups_controller.rb +++ b/app/controllers/admin/groups_controller.rb @@ -21,7 +21,7 @@ class Admin::GroupsController < Admin::ApplicationController def create @group = Group.new(group_params) - @group.path = @group.name.dup.parameterize if @group.name + @group.name = @group.path.dup unless @group.name if @group.save @group.add_owner(current_user) -- cgit v1.2.1 From 1f2628fe2118642b467e93a362cebb11ca780a40 Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 15:02:47 +0200 Subject: Allow Group path to be changed at the same time as name Signed-off-by: Dmitriy Zaporozhets --- app/views/admin/groups/_form.html.haml | 11 ----------- app/views/shared/_group_form.html.haml | 7 +++++++ features/steps/groups.rb | 3 ++- features/steps/project/create.rb | 2 +- 4 files changed, 10 insertions(+), 13 deletions(-) diff --git a/app/views/admin/groups/_form.html.haml b/app/views/admin/groups/_form.html.haml index f4d7e25fd74..86a73200609 100644 --- a/app/views/admin/groups/_form.html.haml +++ b/app/views/admin/groups/_form.html.haml @@ -21,17 +21,6 @@ = link_to 'Cancel', admin_groups_path, class: "btn btn-cancel" - else - .form-group.group_name_holder - = f.label :path, class: 'control-label' do - %span Group path - .col-sm-10 - = f.text_field :path, placeholder: "example-group", class: "form-control danger" - .bs-callout.bs-callout-danger - %ul - %li Changing group path can have unintended side effects. - %li Renaming group path will rename directory for all related projects - %li It will change web url for access group and group projects. - %li It will change the git path to repositories under this group. .form-actions = f.submit 'Save changes', class: "btn btn-primary" = link_to 'Cancel', admin_group_path(@group), class: "btn btn-cancel" diff --git a/app/views/shared/_group_form.html.haml b/app/views/shared/_group_form.html.haml index e0bf77db10f..5875f71bac2 100644 --- a/app/views/shared/_group_form.html.haml +++ b/app/views/shared/_group_form.html.haml @@ -14,6 +14,13 @@ = root_url = f.text_field :path, placeholder: 'open-source', class: 'form-control', autofocus: local_assigns[:autofocus] || false + - if @group.persisted? + .bs-callout.bs-callout-danger + %ul + %li Changing group path can have unintended side effects. + %li Renaming group path will rename directory for all related projects + %li It will change web url for access group and group projects. + %li It will change the git path to repositories under this group. .form-group.group-description-holder = f.label :description, 'Details', class: 'control-label' diff --git a/features/steps/groups.rb b/features/steps/groups.rb index 616a297db99..e5b73e53967 100644 --- a/features/steps/groups.rb +++ b/features/steps/groups.rb @@ -77,7 +77,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps end step 'submit form with new group "Samurai" info' do - fill_in 'group_name', with: 'Samurai' + fill_in 'group_path', with: 'Samurai' fill_in 'group_description', with: 'Tokugawa Shogunate' click_button "Create group" end @@ -94,6 +94,7 @@ class Spinach::Features::Groups < Spinach::FeatureSteps step 'I change group "Owned" name to "new-name"' do fill_in 'group_name', with: 'new-name' + fill_in 'group_path', with: 'new-name' click_button "Save group" end diff --git a/features/steps/project/create.rb b/features/steps/project/create.rb index e1062a6ce39..6b07b62f16f 100644 --- a/features/steps/project/create.rb +++ b/features/steps/project/create.rb @@ -3,7 +3,7 @@ class Spinach::Features::ProjectCreate < Spinach::FeatureSteps include SharedPaths step 'fill project form with valid data' do - fill_in 'project_name', with: 'Empty' + fill_in 'project_path', with: 'Empty' click_button "Create project" end -- cgit v1.2.1 From d0b1bc222e7486bcb4877a7b8526b1646c2be0fc Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 16:48:40 +0200 Subject: Fix spinach test Signed-off-by: Dmitriy Zaporozhets --- features/steps/admin/groups.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/steps/admin/groups.rb b/features/steps/admin/groups.rb index d69a87cd07e..4171398e568 100644 --- a/features/steps/admin/groups.rb +++ b/features/steps/admin/groups.rb @@ -22,7 +22,7 @@ class Spinach::Features::AdminGroups < Spinach::FeatureSteps end step 'submit form with new group info' do - fill_in 'group_name', with: 'gitlab' + fill_in 'group_path', with: 'gitlab' fill_in 'group_description', with: 'Group description' click_button "Create group" end -- cgit v1.2.1 From fb7be3238d86501353863313af72563528ace76f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 17:09:48 +0200 Subject: For API compatibility still generate path from name if only name provided Signed-off-by: Dmitriy Zaporozhets --- app/services/projects/create_service.rb | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/services/projects/create_service.rb b/app/services/projects/create_service.rb index 7b06ce9a337..31226b7504b 100644 --- a/app/services/projects/create_service.rb +++ b/app/services/projects/create_service.rb @@ -13,8 +13,15 @@ module Projects end # Set project name from path - unless @project.name.present? + if @project.name.present? && @project.path.present? + # if both name and path set - everything is ok + elsif @project.path.present? + # Set project name from path @project.name = @project.path.dup + elsif @project.name.present? + # For compatibility - set path from name + # TODO: remove this in 8.0 + @project.path = @project.name.dup.parameterize end # get namespace id -- cgit v1.2.1 From f775809910a2c8ebec1887ec39ba33325d00171a Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Mon, 22 Dec 2014 19:11:15 +0200 Subject: Fix test Signed-off-by: Dmitriy Zaporozhets --- spec/requests/api/projects_spec.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 2c4b68c10b6..f8c5d40b9bf 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -198,8 +198,6 @@ describe API::API, api: true do it 'should respond with 400 on failure' do post api("/projects/user/#{user.id}", admin) response.status.should == 400 - json_response['message']['creator'].should == ['can\'t be blank'] - json_response['message']['namespace'].should == ['can\'t be blank'] json_response['message']['name'].should == [ 'can\'t be blank', 'is too short (minimum is 0 characters)', -- cgit v1.2.1