Possibility to define the default enable trackers when creating a project (#13175).

git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@11394 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2013-02-15 08:28:34 +00:00
parent 348a1d59ef
commit 4e9fbeb851
6 changed files with 45 additions and 5 deletions

View 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')

View 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

View 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,

View 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

View 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

View 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
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