1
0
mirror of https://github.com/meineerde/redmine.git synced 2025-12-19 15:01:14 +00:00

Default target version for new issues (#1828).

git-svn-id: http://svn.redmine.org/redmine/trunk@14786 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Jean-Philippe Lang 2015-11-01 08:11:36 +00:00
parent 786e3cff10
commit 9178d4748f
10 changed files with 70 additions and 5 deletions

View File

@ -87,6 +87,14 @@ module ProjectsHelper
end end
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) def format_version_sharing(sharing)
sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing)
l("label_version_sharing_#{sharing}") l("label_version_sharing_#{sharing}")

View File

@ -327,10 +327,13 @@ class Issue < ActiveRecord::Base
# Unless keep_tracker argument is set to true, this will change the tracker # 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 # to the first tracker of the new project if the previous tracker is not part
# of the new project trackers. # of the new project trackers.
# This will clear the fixed_version is it's no longer valid for the new project. # This will:
# This will clear the parent issue if it's no longer valid for the new project. # * clear the fixed_version is it's no longer valid for the new project.
# This will set the category to the category with the same name in the new # * clear the parent issue if it's no longer valid for the new project.
# project if it exists, or clear it if it doesn't. # * 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) def project=(project, keep_tracker=false)
project_was = self.project project_was = self.project
association(:project).writer(project) association(:project).writer(project)
@ -355,6 +358,12 @@ class Issue < ActiveRecord::Base
@custom_field_values = nil @custom_field_values = nil
@workflow_rule_by_attribute = nil @workflow_rule_by_attribute = nil
end 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 self.project
end end

View File

@ -38,6 +38,7 @@ class Project < ActiveRecord::Base
has_many :issues, :dependent => :destroy has_many :issues, :dependent => :destroy
has_many :issue_changes, :through => :issues, :source => :journals 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 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 :time_entries, :dependent => :destroy
has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all
has_many :documents, :dependent => :destroy has_many :documents, :dependent => :destroy
@ -687,7 +688,8 @@ class Project < ActiveRecord::Base
'custom_fields', 'custom_fields',
'tracker_ids', 'tracker_ids',
'issue_custom_field_ids', 'issue_custom_field_ids',
'parent_id' 'parent_id',
'default_version_id'
safe_attributes 'enabled_module_names', safe_attributes 'enabled_module_names',
:if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) }

View File

@ -17,7 +17,10 @@
class Version < ActiveRecord::Base class Version < ActiveRecord::Base
include Redmine::SafeAttributes include Redmine::SafeAttributes
after_update :update_issues_from_sharing_change after_update :update_issues_from_sharing_change
before_destroy :nullify_projects_default_version
belongs_to :project belongs_to :project
has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify
acts_as_customizable acts_as_customizable
@ -297,4 +300,8 @@ class Version < ActiveRecord::Base
CustomValue.joins(:custom_field). CustomValue.joins(:custom_field).
where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any? where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any?
end end
def nullify_projects_default_version
Project.where(:default_version_id => id).update_all(:default_version_id => nil)
end
end end

View File

@ -20,6 +20,10 @@
<p><%= f.check_box :inherit_members %></p> <p><%= f.check_box :inherit_members %></p>
<% end %> <% 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' %> <%= wikitoolbar_for 'project_description' %>
<% @project.custom_field_values.each do |value| %> <% @project.custom_field_values.each do |value| %>

View File

@ -348,6 +348,7 @@ en:
field_users_visibility: Users visibility field_users_visibility: Users visibility
field_time_entries_visibility: Time logs visibility field_time_entries_visibility: Time logs visibility
field_total_estimated_hours: Total estimated time field_total_estimated_hours: Total estimated time
field_default_version: Default version
setting_app_title: Application title setting_app_title: Application title
setting_app_subtitle: Application subtitle setting_app_subtitle: Application subtitle

View File

@ -368,6 +368,7 @@ fr:
field_users_visibility: Visibilité des utilisateurs field_users_visibility: Visibilité des utilisateurs
field_time_entries_visibility: Visibilité du temps passé field_time_entries_visibility: Visibilité du temps passé
field_total_estimated_hours: Temps estimé total field_total_estimated_hours: Temps estimé total
field_default_version: Version par défaut
setting_app_title: Titre de l'application setting_app_title: Titre de l'application
setting_app_subtitle: Sous-titre de l'application setting_app_subtitle: Sous-titre de l'application

View File

@ -0,0 +1,12 @@
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

View File

@ -1715,6 +1715,19 @@ class IssuesControllerTest < ActionController::TestCase
end end
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 def test_get_new_with_list_custom_field
@request.session[:user_id] = 2 @request.session[:user_id] = 2
get :new, :project_id => 1, :tracker_id => 1 get :new, :project_id => 1, :tracker_id => 1

View File

@ -496,6 +496,14 @@ class IssueTest < ActiveSupport::TestCase
assert_equal custom_value.id, issue.custom_value_for(field).id assert_equal custom_value.id, issue.custom_value_for(field).id
end 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 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, issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1,
:status_id => 1, :subject => 'Test', :status_id => 1, :subject => 'Test',