Commit 44af7e5b authored by jplang's avatar jplang

Default target version for new issues (#1828).

git-svn-id: https://svn.redmine.org/redmine/trunk@14786 e93f8b46-1217-0410-a6f0-8f06a7374b81
parent 7f0faa61
......@@ -87,6 +87,14 @@ module ProjectsHelper
end
end
def project_default_version_options(project)
versions = project.shared_versions.open.to_a
if project.default_version && !versions.include?(project.default_version)
versions << project.default_version
end
version_options_for_select(versions, project.default_version)
end
def format_version_sharing(sharing)
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}")
......
......@@ -327,10 +327,13 @@ class Issue < ActiveRecord::Base
# Unless keep_tracker argument is set to true, this will change the tracker
# to the first tracker of the new project if the previous tracker is not part
# of the new project trackers.
# This will clear the fixed_version is it's no longer valid for the new project.
# This will clear the parent issue if it's no longer valid for the new project.
# This will set the category to the category with the same name in the new
# project if it exists, or clear it if it doesn't.
# This will:
# * clear the fixed_version is it's no longer valid for the new project.
# * clear the parent issue if it's no longer valid for the new project.
# * set the category to the category with the same name in the new
# project if it exists, or clear it if it doesn't.
# * for new issue, set the fixed_version to the project default version
# if it's a valid fixed_version.
def project=(project, keep_tracker=false)
project_was = self.project
association(:project).writer(project)
......@@ -355,6 +358,12 @@ class Issue < ActiveRecord::Base
@custom_field_values = nil
@workflow_rule_by_attribute = nil
end
# Set fixed_version to the project default version if it's valid
if new_record? && fixed_version.nil? && project && project.default_version_id?
if project.shared_versions.open.exists?(project.default_version_id)
self.fixed_version_id = project.default_version_id
end
end
self.project
end
......
......@@ -38,6 +38,7 @@ class Project < ActiveRecord::Base
has_many :issues, :dependent => :destroy
has_many :issue_changes, :through => :issues, :source => :journals
has_many :versions, lambda {order("#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC")}, :dependent => :destroy
belongs_to :default_version, :class_name => 'Version'
has_many :time_entries, :dependent => :destroy
has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all
has_many :documents, :dependent => :destroy
......@@ -687,7 +688,8 @@ class Project < ActiveRecord::Base
'custom_fields',
'tracker_ids',
'issue_custom_field_ids',
'parent_id'
'parent_id',
'default_version_id'
safe_attributes 'enabled_module_names',
:if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }
......
......@@ -17,7 +17,10 @@
class Version < ActiveRecord::Base
include Redmine::SafeAttributes
after_update :update_issues_from_sharing_change
before_destroy :nullify_projects_default_version
belongs_to :project
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
acts_as_customizable
......@@ -297,4 +300,8 @@ class Version < ActiveRecord::Base
CustomValue.joins(:custom_field).
where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any?
end
def nullify_projects_default_version
Project.where(:default_version_id => id).update_all(:default_version_id => nil)
end
end
......@@ -20,6 +20,10 @@
<p><%= f.check_box :inherit_members %></p>
<% end %>
<% if @project.safe_attribute?('default_version_id') && (default_version_options = project_default_version_options(@project)).present? %>
<p><%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %></p>
<% end %>
<%= wikitoolbar_for 'project_description' %>
<% @project.custom_field_values.each do |value| %>
......
......@@ -348,6 +348,7 @@ en:
field_users_visibility: Users visibility
field_time_entries_visibility: Time logs visibility
field_total_estimated_hours: Total estimated time
field_default_version: Default version
setting_app_title: Application title
setting_app_subtitle: Application subtitle
......
......@@ -368,6 +368,7 @@ fr:
field_users_visibility: Visibilité des utilisateurs
field_time_entries_visibility: Visibilité du temps passé
field_total_estimated_hours: Temps estimé total
field_default_version: Version par défaut
setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application
......
class AddProjectsDefaultVersionId < ActiveRecord::Migration
def self.up
# Don't try to add the column if redmine_default_version plugin was used
unless column_exists?(:projects, :default_version_id, :integer)
add_column :projects, :default_version_id, :integer, :default => nil
end
end
def self.down
remove_column :projects, :default_version_id
end
end
......@@ -1715,6 +1715,19 @@ class IssuesControllerTest < ActionController::TestCase
end
end
def test_new_should_preselect_default_version
version = Version.generate!(:project_id => 1)
Project.find(1).update_attribute :default_version_id, version.id
@request.session[:user_id] = 2
get :new, :project_id => 1
assert_response :success
assert_equal version, assigns(:issue).fixed_version
assert_select 'select[name=?]', 'issue[fixed_version_id]' do
assert_select 'option[value=?][selected=selected]', version.id.to_s
end
end
def test_get_new_with_list_custom_field
@request.session[:user_id] = 2
get :new, :project_id => 1, :tracker_id => 1
......
......@@ -496,6 +496,14 @@ class IssueTest < ActiveSupport::TestCase
assert_equal custom_value.id, issue.custom_value_for(field).id
end
def test_setting_project_should_set_version_to_default_version
version = Version.generate!(:project_id => 1)
Project.find(1).update_attribute(:default_version_id, version.id)
issue = Issue.new(:project_id => 1)
assert_equal version, issue.fixed_version
end
def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields
issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1,
:status_id => 1, :subject => 'Test',
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment