diff --git a/app/controllers/concerns/issue_templates_common.rb b/app/controllers/concerns/issue_templates_common.rb index 2b50b1d6..62f33160 100644 --- a/app/controllers/concerns/issue_templates_common.rb +++ b/app/controllers/concerns/issue_templates_common.rb @@ -108,8 +108,12 @@ def core_fields_map_by_tracker_id(tracker_id: nil, project_id: nil) end if field == 'watcher_user_ids' && project_id.present? - issue = Issue.new(tracker_id: tracker_id, project_id: project_id) - watchers = helpers.users_for_new_issue_watchers(issue) + project_principals = if Watcher.reflections['user'].class_name == 'Principal' + Project.find(project_id).principals.where(type: %w[User Group]) + else # Redmine 4.1.x or earlier + Project.find(project_id).users + end + watchers = project_principals.active.visible.sort value[:field_format] = 'list' value[:possible_values] = watchers.map { |user| "#{user.name} :#{user.id}" } diff --git a/assets/javascripts/issue_templates.js b/assets/javascripts/issue_templates.js index 983cce9d..b48b1ed8 100644 --- a/assets/javascripts/issue_templates.js +++ b/assets/javascripts/issue_templates.js @@ -423,13 +423,17 @@ ISSUE_TEMPLATE.prototype = { document.getElementById('issue_template').dispatchEvent(changeEvent) }, checkSelectedWatchers: function (values) { - let targets = document.querySelectorAll('input[name="issue[watcher_user_ids][]"]') - for (let i = 0; i < targets.length; i++) { - let target = targets[i] - if (values.includes(target.value)) { - target.checked = true - } - } + // HACK: want to get this url and params in a stable way. + const rootPath = $('a.home').attr('href'); + const projectPath = $('a.overview')?.attr('href') ?? `/projects/${$('#issue_project_id').val()}`; + const { projectId } = /projects\/(?.+)/.exec(projectPath).groups; + $.post({ + url: `${rootPath}watchers/append.js`, + data: { + project_id: projectId, + watcher: { user_ids: values } + }, + }); }, filterTemplate: function (event) { let cols = document.getElementsByClassName('template_data')