Commit 1beefdbe authored by Markus Koller's avatar Markus Koller

Merge branch 'fix_issue_template_url' into 'master'

Allow to apply issue inherited templates using URL

See merge request gitlab-org/gitlab!67686
parents 5a59980a 02f50c65
...@@ -32,13 +32,14 @@ module IssuablesDescriptionTemplatesHelper ...@@ -32,13 +32,14 @@ module IssuablesDescriptionTemplatesHelper
@template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names(project, issuable_type.pluralize) @template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names(project, issuable_type.pluralize)
end end
def issuable_templates_names(issuable) # Overriden on EE::IssuablesDescriptionTemplatesHelper to include inherited templates names
def issuable_templates_names(issuable, include_inherited_templates = false)
all_templates = issuable_templates(ref_project, issuable.to_ability_name) all_templates = issuable_templates(ref_project, issuable.to_ability_name)
all_templates.values.flatten.map { |tpl| tpl[:name] if tpl[:project_id] == ref_project.id }.compact.uniq all_templates.values.flatten.map { |tpl| tpl[:name] if tpl[:project_id] == ref_project.id }.compact.uniq
end end
def selected_template(issuable) def selected_template(issuable)
params[:issuable_template] if issuable_templates_names(issuable).any? { |tmpl_name| tmpl_name == params[:issuable_template] } params[:issuable_template] if issuable_templates_names(issuable, true).any? { |tmpl_name| tmpl_name == params[:issuable_template] }
end end
def template_names_path(parent, issuable) def template_names_path(parent, issuable)
...@@ -47,3 +48,5 @@ module IssuablesDescriptionTemplatesHelper ...@@ -47,3 +48,5 @@ module IssuablesDescriptionTemplatesHelper
project_template_names_path(parent, template_type: issuable.to_ability_name) project_template_names_path(parent, template_type: issuable.to_ability_name)
end end
end end
IssuablesDescriptionTemplatesHelper.prepend_mod
# frozen_string_literal: true
module EE
module IssuablesDescriptionTemplatesHelper
extend ::Gitlab::Utils::Override
override :issuable_templates_names
def issuable_templates_names(issuable, include_inherited_templates = false)
return super unless include_inherited_templates
all_templates = issuable_templates(ref_project, issuable.to_ability_name)
all_templates.values.flatten.map { |tpl| tpl[:name] }.compact.uniq
end
end
end
...@@ -74,4 +74,30 @@ RSpec.describe "User creates issue", :js do ...@@ -74,4 +74,30 @@ RSpec.describe "User creates issue", :js do
expect(page).to have_content(issue_title) expect(page).to have_content(issue_title)
end end
end end
context 'when new issue url has parameter' do
context 'for inherited issue template' do
let_it_be(:template_project) { create(:project, :public, :repository) }
before do
template_project.repository.create_file(
user,
'.gitlab/issue_templates/bug.md',
'this is a test "bug" template',
message: 'added issue template',
branch_name: 'master')
group.add_owner(user)
stub_licensed_features(custom_file_templates_for_namespace: true)
create(:project_group_link, project: template_project, group: group)
group.update!(file_template_project_id: template_project.id)
visit new_project_issue_path(project, issuable_template: 'bug')
end
it 'fills in with inherited template' do
expect(find('.js-issuable-selector .dropdown-toggle-text')).to have_content('bug')
end
end
end
end end
...@@ -5,8 +5,6 @@ require 'spec_helper' ...@@ -5,8 +5,6 @@ require 'spec_helper'
RSpec.describe IssuablesDescriptionTemplatesHelper do RSpec.describe IssuablesDescriptionTemplatesHelper do
include_context 'project issuable templates context' include_context 'project issuable templates context'
describe '#issuable_templates' do
context 'when project parent group has a file template project' do
let_it_be(:user) { create(:user) } let_it_be(:user) { create(:user) }
let_it_be_with_reload(:parent_group) { create(:group) } let_it_be_with_reload(:parent_group) { create(:group) }
let_it_be_with_reload(:group) { create(:group, parent: parent_group) } let_it_be_with_reload(:group) { create(:group, parent: parent_group) }
...@@ -15,6 +13,22 @@ RSpec.describe IssuablesDescriptionTemplatesHelper do ...@@ -15,6 +13,22 @@ RSpec.describe IssuablesDescriptionTemplatesHelper do
let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) } let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) }
let_it_be(:inherited_from) { file_template_project } let_it_be(:inherited_from) { file_template_project }
shared_examples 'issuable templates' do
context 'when include_inherited_templates is true' do
it 'returns project templates and inherited templates' do
expect(helper.issuable_templates_names(Issue.new, true)).to eq(%w[project_template inherited_template])
end
end
context 'when include_inherited_templates is false' do
it 'returns only project templates' do
expect(helper.issuable_templates_names(Issue.new)).to eq(%w[project_template])
end
end
end
describe '#issuable_templates' do
context 'when project parent group has a file template project' do
before do before do
stub_licensed_features(custom_file_templates_for_namespace: true) stub_licensed_features(custom_file_templates_for_namespace: true)
...@@ -24,4 +38,20 @@ RSpec.describe IssuablesDescriptionTemplatesHelper do ...@@ -24,4 +38,20 @@ RSpec.describe IssuablesDescriptionTemplatesHelper do
it_behaves_like 'project issuable templates' it_behaves_like 'project issuable templates'
end end
end end
describe '#issuable_template_names' do
let(:templates) do
{
'' => [{ name: 'project_template', id: 'project_issue_template', project_id: project.id }],
'Instance' => [{ name: 'inherited_template', id: 'instance_issue_template', project_id: file_template_project.id }]
}
end
before do
allow(helper).to receive(:ref_project).and_return(project)
allow(helper).to receive(:issuable_templates).and_return(templates)
end
it_behaves_like 'issuable templates'
end
end end
...@@ -41,19 +41,6 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do ...@@ -41,19 +41,6 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
context 'when project parent group does not have a file template project' do context 'when project parent group does not have a file template project' do
it_behaves_like 'project issuable templates' it_behaves_like 'project issuable templates'
end end
context 'when project parent group has a file template project' do
let_it_be(:file_template_project) { create(:project, :custom_repo, group: parent_group, files: issuable_template_files) }
let_it_be(:group, reload: true) { create(:group, parent: parent_group) }
let_it_be(:project, reload: true) { create(:project, :custom_repo, group: group, files: issuable_template_files) }
before do
project.update!(group: group)
parent_group.update_columns(file_template_project_id: file_template_project.id)
end
it_behaves_like 'project issuable templates'
end
end end
end end
...@@ -65,16 +52,12 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do ...@@ -65,16 +52,12 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
allow(helper).to receive(:issuable_templates).and_return(templates) allow(helper).to receive(:issuable_templates).and_return(templates)
end end
context 'with matching project templates' do context 'with project templates' do
let(:templates) do let(:templates) do
{ {
"" => [ "" => [
{ name: "another_issue_template", id: "another_issue_template", project_id: project.id }, { name: "another_issue_template", id: "another_issue_template" },
{ name: "custom_issue_template", id: "custom_issue_template", project_id: project.id } { name: "custom_issue_template", id: "custom_issue_template" }
],
"Instance" => [
{ name: "first_issue_issue_template", id: "first_issue_issue_template", project_id: non_existing_record_id },
{ name: "second_instance_issue_template", id: "second_instance_issue_template", project_id: non_existing_record_id }
] ]
} }
end end
...@@ -90,10 +73,6 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do ...@@ -90,10 +73,6 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
"Project Templates" => [ "Project Templates" => [
{ name: "another_issue_template", id: "another_issue_template", project_id: non_existing_record_id }, { name: "another_issue_template", id: "another_issue_template", project_id: non_existing_record_id },
{ name: "custom_issue_template", id: "custom_issue_template", project_id: non_existing_record_id } { name: "custom_issue_template", id: "custom_issue_template", project_id: non_existing_record_id }
],
"Instance" => [
{ name: "first_issue_issue_template", id: "first_issue_issue_template", project_id: non_existing_record_id },
{ name: "second_instance_issue_template", id: "second_instance_issue_template", project_id: non_existing_record_id }
] ]
} }
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