Commit 87ff15e7 authored by Lee Tickett's avatar Lee Tickett Committed by Illya Klymov

Fix default path when creating project from group template

parent 0806f699
---
title: Fix default path when creating project from group template
merge_request: 30597
author: Lee Tickett
type: fixed
...@@ -56,11 +56,12 @@ const bindEvents = () => { ...@@ -56,11 +56,12 @@ const bindEvents = () => {
function chooseTemplate() { function chooseTemplate() {
const subgroupId = $(this).data('subgroup-id'); const subgroupId = $(this).data('subgroup-id');
const groupId = $(this).data('parent-group-id');
const templateName = $(this).data('template-name'); const templateName = $(this).data('template-name');
if (subgroupId) { if (subgroupId) {
$subgroupWithTemplatesIdInput.val(subgroupId); $subgroupWithTemplatesIdInput.val(subgroupId);
$namespaceSelect.val(subgroupId).trigger('change'); $namespaceSelect.val(groupId).trigger('change');
hideNonRootParentPathOptions(); hideNonRootParentPathOptions();
...@@ -102,7 +103,7 @@ const bindEvents = () => { ...@@ -102,7 +103,7 @@ const bindEvents = () => {
$projectFieldsForm $projectFieldsForm
.find('.js-select-namespace') .find('.js-select-namespace')
.first() .first()
.val(subgroupId); .val(groupId);
} }
$useCustomTemplateBtn.on('change', chooseTemplate); $useCustomTemplateBtn.on('change', chooseTemplate);
......
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
%a.btn.btn-default.append-right-10{ href: project_path(project), rel: 'noopener noreferrer', target: '_blank' } %a.btn.btn-default.append-right-10{ href: project_path(project), rel: 'noopener noreferrer', target: '_blank' }
= _('Preview') = _('Preview')
%label.btn.btn-success.custom-template-button.choose-template.gl-mb-0{ for: project.name } %label.btn.btn-success.custom-template-button.choose-template.gl-mb-0{ for: project.name }
%input{ type: "radio", autocomplete: "off", name: "project[template_project_id]", id: project.name, value: project.id, data: { subgroup_id: project.namespace_id, template_name: project.name } } %input{ type: "radio", autocomplete: "off", name: "project[template_project_id]", id: project.name, value: project.id, data: { subgroup_id: project.namespace_id, template_name: project.name, parent_group_id: namespace_id || group.parent_id } }
%span.qa-use-template-button %span.qa-use-template-button
= _('Use template') = _('Use template')
......
:plain :plain
var target = $(".project-templates-buttons#custom-group-project-templates"); var target = $(".project-templates-buttons#custom-group-project-templates");
target.empty(); target.empty();
target.html("#{escape_javascript(render('custom_project_templates_from_groups', groups_with_project_templates: @groups_with_project_templates))}"); target.html("#{escape_javascript(render('custom_project_templates_from_groups', groups_with_project_templates: @groups_with_project_templates, namespace_id: params[:group_id]))}");
target.trigger("ajax:success"); target.trigger("ajax:success");
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe 'Project' do
describe 'when creating from group template' do
let(:user) { create(:user) }
let(:group) { create(:group, name: 'parent-group') }
let(:template_subgroup) { create(:group, parent: group, name: 'template-subgroup') }
let(:other_subgroup) { create(:group, parent: group, name: 'other-subgroup') }
let(:template) { create(:project, namespace: template_subgroup) }
before do
stub_licensed_features(custom_project_templates: true)
group.add_owner(user)
group.update!(custom_project_templates_group_id: template_subgroup.id)
sign_in user
end
it "defaults to correct namespace", :js do
visit new_project_path
find('#create-from-template-tab').click
find('.custom-group-project-templates-tab').click
find("label[for=#{template.name}]").click
expect(find('.js-select-namespace')).to have_content group.name
end
it "uses supplied namespace", :js do
visit new_project_path(namespace_id: other_subgroup.id)
find('#create-from-template-tab').click
find('.custom-group-project-templates-tab').click
find("label[for=#{template.name}]").click
expect(find('.js-select-namespace')).to have_content other_subgroup.name
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment