]> source.dussan.org Git - redmine.git/commitdiff
Possibility to define the default enable trackers when creating a project (#13175).
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Feb 2013 08:28:34 +0000 (08:28 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Fri, 15 Feb 2013 08:28:34 +0000 (08:28 +0000)
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11394 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/helpers/settings_helper.rb
app/models/project.rb
app/views/settings/_projects.html.erb
config/settings.yml
test/test_helper.rb
test/unit/project_test.rb

index 525b8d97566e18517a33baba1dabf53fa102f038..a01e29a3a52820ff855ab450eebc1dd633a79cdd 100644 (file)
@@ -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')
index 478261b862ee147a24da1622143a726529d292b1..8b305f3d8f29caf22d160487b5057a14c15b00e0 100644 (file)
@@ -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
 
index 90db6b1ceaf4375e6c84c63765cfd225dfd6cb7b..28fd9b5789f32dc801f04e7fe3a21210df3460e5 100644 (file)
@@ -6,6 +6,9 @@
 <p><%= setting_multiselect(:default_projects_modules,
         Redmine::AccessControl.available_project_modules.collect {|m| [l_or_humanize(m, :prefix => "project_module_"), m.to_s]}) %></p>
 
+<p><%= setting_multiselect(:default_projects_tracker_ids,
+        Tracker.sorted.all.collect {|t| [t.name, t.id.to_s]}) %></p>
+
 <p><%= setting_check_box :sequential_project_identifiers %></p>
 
 <p><%= setting_select :new_project_user_role_id,
index c538334fbcc537ad1bb00f3bddc233fdcbb17e8a..0c9f270a137c9fa9fd3ff2908ce10165df459002 100644 (file)
@@ -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
index 410fe1f8a2cb7312ea2a224e413c83b4c1e1ab32..368a4d41bb438b8e93a390e23453dbb9b81fe14e 100644 (file)
@@ -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
index b9aabebed7e3ea2873cf36a9dbbde0a32bbbe7de..c6ba4cd72869c3fc8dcb0d03a930488802de86d0 100644 (file)
@@ -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
+
+  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
 
-    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_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