From 2f46a68f1a1a36a0c43fe2003cd6e095a7ea081f Mon Sep 17 00:00:00 2001 From: Akiko Takano Date: Tue, 30 Jun 2020 19:38:14 +0900 Subject: [PATCH] Prevent defailt template loaded when new.js is called. --- app/controllers/issue_templates_controller.rb | 16 ++++++++++++---- .../issue_templates/_issue_select_form.html.erb | 3 ++- assets/javascripts/issue_templates.js | 2 +- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/app/controllers/issue_templates_controller.rb b/app/controllers/issue_templates_controller.rb index f1e58328..8684ed39 100644 --- a/app/controllers/issue_templates_controller.rb +++ b/app/controllers/issue_templates_controller.rb @@ -100,12 +100,12 @@ def set_pulldown add_templates_to_group(@inherit_templates, class: 'inherited') add_templates_to_group(@global_templates, class: 'global') - is_triggered_by = request.parameters[:is_triggered_by] - is_update_issue = request.parameters[:is_update_issue] - @group[@default_template].selected = 'selected' if @default_template.present? && (is_update_issue.blank? || is_update_issue != 'true') + if loadable_trigger? + @group[@default_template].selected = 'selected' + end render action: '_template_pulldown', layout: false, - locals: { is_triggered_by: is_triggered_by, grouped_options: @group, + locals: { is_triggered_by: request.parameters[:is_triggered_by], grouped_options: @group, should_replaced: setting.should_replaced, default_template: @default_template } end @@ -233,4 +233,12 @@ def render_form_params locals: { issue_template: template, project: @project, child_project_used_count: child_project_used_count, checklist_enabled: checklist_enabled?, custom_fields: custom_fields.to_s, builtin_fields_enable: builtin_fields_enabled? } } end + + def loadable_trigger? + is_triggered_by = request.parameters[:is_triggered_by] + is_update_issue = request.parameters[:is_update_issue] + + return false if is_triggered_by.present? && is_triggered_by != 'is_update_issue' + return @default_template.present? && (is_update_issue.blank? || is_update_issue != 'true') + end end diff --git a/app/views/issue_templates/_issue_select_form.html.erb b/app/views/issue_templates/_issue_select_form.html.erb index 9f389a9b..bef7a037 100644 --- a/app/views/issue_templates/_issue_select_form.html.erb +++ b/app/views/issue_templates/_issue_select_form.html.erb @@ -83,7 +83,8 @@ confirmMessage: '<%=h l(:label_template_applied, default: "Issue template is applied. You can revert with click 'Revert' link.") %>' } - var templateNS = templateNS || new ISSUE_TEMPLATE(templateConfig); + var templateNS = templateNS || new ISSUE_TEMPLATE(templateConfig) + templateNS.isTriggeredBy = '<%= is_triggered_by %>' templateNS.setPulldown('<%= @issue.tracker.id %>') document.getElementById('issue_template').addEventListener('change', (event) => { diff --git a/assets/javascripts/issue_templates.js b/assets/javascripts/issue_templates.js index 093f1a11..1400247a 100644 --- a/assets/javascripts/issue_templates.js +++ b/assets/javascripts/issue_templates.js @@ -258,7 +258,7 @@ ISSUE_TEMPLATE.prototype = { }, setPulldown: function (tracker) { let ns = this - let params = { issue_tracker_id: tracker } + let params = { issue_tracker_id: tracker, is_triggered_by: ns.isTriggeredBy } let pullDownProject = document.getElementById('issue_project_id') if (pullDownProject) { params.issue_project_id = pullDownProject.value