diff --git a/app/helpers/settings_helper.rb b/app/helpers/settings_helper.rb index 525b8d975..a01e29a3a 100644 --- a/app/helpers/settings_helper.rb +++ b/app/helpers/settings_helper.rb @@ -53,7 +53,7 @@ module SettingsHelper check_box_tag( "settings[#{setting}][]", value, - Setting.send(setting).include?(value), + setting_values.include?(value), :id => nil ) + text.to_s, :class => (options[:inline] ? 'inline' : 'block') diff --git a/app/models/project.rb b/app/models/project.rb index 478261b86..8b305f3d8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -126,7 +126,12 @@ class Project < ActiveRecord::Base self.enabled_module_names = Setting.default_projects_modules end if !initialized.key?('trackers') && !initialized.key?('tracker_ids') - self.trackers = Tracker.sorted.all + default = Setting.default_projects_tracker_ids + if default.is_a?(Array) + self.trackers = Tracker.where(:id => default.map(&:to_i)).sorted.all + else + self.trackers = Tracker.sorted.all + end end end diff --git a/app/views/settings/_projects.html.erb b/app/views/settings/_projects.html.erb index 90db6b1ce..28fd9b578 100644 --- a/app/views/settings/_projects.html.erb +++ b/app/views/settings/_projects.html.erb @@ -6,6 +6,9 @@
<%= setting_multiselect(:default_projects_modules, Redmine::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, :prefix => "project_module_"), m.to_s]}) %>
+<%= setting_multiselect(:default_projects_tracker_ids, + Tracker.sorted.all.collect {|t| [t.name, t.id.to_s]}) %>
+<%= setting_check_box :sequential_project_identifiers %>
<%= setting_select :new_project_user_role_id, diff --git a/config/settings.yml b/config/settings.yml index c538334fb..0c9f270a1 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -179,6 +179,9 @@ default_projects_modules: - boards - calendar - gantt +default_projects_tracker_ids: + serialized: true + default: # Role given to a non-admin user who creates a project new_project_user_role_id: format: int diff --git a/test/test_helper.rb b/test/test_helper.rb index 410fe1f8a..368a4d41b 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -87,7 +87,15 @@ class ActiveSupport::TestCase end def with_settings(options, &block) - saved_settings = options.keys.inject({}) {|h, k| h[k] = Setting[k].is_a?(Symbol) ? Setting[k] : Setting[k].dup; h} + saved_settings = options.keys.inject({}) do |h, k| + h[k] = case Setting[k] + when Symbol, false, true, nil + Setting[k] + else + Setting[k].dup + end + h + end options.each {|k, v| Setting[k] = v} yield ensure diff --git a/test/unit/project_test.rb b/test/unit/project_test.rb index b9aabebed..c6ba4cd72 100644 --- a/test/unit/project_test.rb +++ b/test/unit/project_test.rb @@ -74,9 +74,30 @@ class ProjectTest < ActiveSupport::TestCase with_settings :default_projects_modules => ['issue_tracking', 'repository'] do assert_equal ['issue_tracking', 'repository'], Project.new.enabled_module_names end + end - assert_equal Tracker.all.sort, Project.new.trackers.sort - assert_equal Tracker.find(1, 3).sort, Project.new(:tracker_ids => [1, 3]).trackers.sort + def test_default_trackers_should_match_default_tracker_ids_setting + with_settings :default_projects_tracker_ids => ['1', '3'] do + assert_equal Tracker.find(1, 3).sort, Project.new.trackers.sort + end + end + + def test_default_trackers_should_be_all_trackers_with_blank_setting + with_settings :default_projects_tracker_ids => nil do + assert_equal Tracker.all.sort, Project.new.trackers.sort + end + end + + def test_default_trackers_should_be_empty_with_empty_setting + with_settings :default_projects_tracker_ids => [] do + assert_equal [], Project.new.trackers + end + end + + def test_default_trackers_should_not_replace_initialized_trackers + with_settings :default_projects_tracker_ids => ['1', '3'] do + assert_equal Tracker.find(1, 2).sort, Project.new(:tracker_ids => [1, 2]).trackers.sort + end end def test_update