Merge pull request #22731 from opf/bug/73430-templates-from-other-projects-are-not-discoverable

[#73430] Templates from other projects are not discoverable
This commit is contained in:
Mir Bhatia
2026-04-13 13:24:43 +02:00
committed by GitHub
2 changed files with 49 additions and 2 deletions
@@ -39,7 +39,7 @@ class Meeting::TemplateAutocompleter < ApplicationForm
templates.each do |template|
select.option(
value: template.id,
label: template.title,
label: label(template),
selected: template.id == @selected_id
)
end
@@ -74,6 +74,16 @@ class Meeting::TemplateAutocompleter < ApplicationForm
def templates
return [] if @disabled
Meeting.templates_visible_in_project(@project).order(:title)
Meeting.templates_visible_in_project(@project)
.includes(:project)
.order("projects.name ASC, meetings.title ASC")
end
def label(template)
if template.project_id == @project.id
template.title
else
"#{template.project.name}: #{template.title}"
end
end
end
@@ -380,4 +380,41 @@ RSpec.describe "Create meeting from template", :js do
end
end
end
describe "autocompleter labels and ordering", with_ee: [:meeting_templates] do
let(:project_a) { create(:project, name: "Project A", enabled_module_names: %i[meetings]) }
let(:project_b) { create(:project, name: "Project B", enabled_module_names: %i[meetings]) }
let!(:template_a1) { create(:onetime_template, project: project_a, title: "Template A1") }
let!(:template_a2) { create(:onetime_template, project: project_a, title: "Template A2") }
let!(:template_b1) { create(:onetime_template, project: project_b, title: "Template A1", sharing: :system) }
let(:project_a_meetings_page) { Pages::Meetings::Index.new(project: project_a) }
before { project_a_meetings_page.visit! }
it "prefixes templates from other projects with their project name" do
project_a_meetings_page.click_on "add-meeting-button"
project_a_meetings_page.click_on "One-time"
within_dialog "New one-time meeting" do
find('[data-test-selector="template_id"]').click
expect(page).to have_text("Template A1")
expect(page).to have_text("Template A2")
expect(page).to have_text("Project B: Template A1")
end
end
it "orders options such that all templates from a project are grouped together" do
project_a_meetings_page.click_on "add-meeting-button"
project_a_meetings_page.click_on "One-time"
within_dialog "New one-time meeting" do
find('[data-test-selector="template_id"]').click
expect(all(".ng-option").map(&:text)).to eq(["Template A1", "Template A2", "Project B: Template A1"])
end
end
end
end