Commit 02f50c65 authored by Felipe Artur's avatar Felipe Artur

Allow to apply issue inherited templates using URL

Fix not applying inherited issue templates using URL

Changelog: fixed
EE: true
parent c62c0a5f
......@@ -32,13 +32,14 @@ module IssuablesDescriptionTemplatesHelper
@template_types[project.id][issuable_type] ||= TemplateFinder.all_template_names(project, issuable_type.pluralize)
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.values.flatten.map { |tpl| tpl[:name] if tpl[:project_id] == ref_project.id }.compact.uniq
end
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
def template_names_path(parent, issuable)
......@@ -47,3 +48,5 @@ module IssuablesDescriptionTemplatesHelper
project_template_names_path(parent, template_type: issuable.to_ability_name)
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
expect(page).to have_content(issue_title)
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
......@@ -5,16 +5,30 @@ require 'spec_helper'
RSpec.describe IssuablesDescriptionTemplatesHelper do
include_context 'project issuable templates context'
let_it_be(:user) { create(:user) }
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(:project) { create(:project, :custom_repo, group: group, files: issuable_template_files) }
let_it_be(:file_template_project) { create(:project, :custom_repo, group: parent_group, files: issuable_template_files) }
let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) }
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
let_it_be(:user) { create(:user) }
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(:project) { create(:project, :custom_repo, group: group, files: issuable_template_files) }
let_it_be(:file_template_project) { create(:project, :custom_repo, group: parent_group, files: issuable_template_files) }
let_it_be(:group_member) { create(:group_member, :developer, group: parent_group, user: user) }
let_it_be(:inherited_from) { file_template_project }
before do
stub_licensed_features(custom_file_templates_for_namespace: true)
......@@ -24,4 +38,20 @@ RSpec.describe IssuablesDescriptionTemplatesHelper do
it_behaves_like 'project issuable templates'
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
......@@ -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
it_behaves_like 'project issuable templates'
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
......@@ -65,16 +52,12 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
allow(helper).to receive(:issuable_templates).and_return(templates)
end
context 'with matching project templates' do
context 'with project templates' do
let(:templates) do
{
"" => [
{ name: "another_issue_template", id: "another_issue_template", project_id: project.id },
{ name: "custom_issue_template", id: "custom_issue_template", project_id: project.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 }
{ name: "another_issue_template", id: "another_issue_template" },
{ name: "custom_issue_template", id: "custom_issue_template" }
]
}
end
......@@ -90,10 +73,6 @@ RSpec.describe IssuablesDescriptionTemplatesHelper, :clean_gitlab_redis_cache do
"Project Templates" => [
{ 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 }
],
"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
......
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