From: Jean-Philippe Lang Date: Sun, 1 Nov 2015 08:11:36 +0000 (+0000) Subject: Default target version for new issues (#1828). X-Git-Tag: 3.2.0~88 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=9178d4748f19adee08e5b9d58ea1176836249eb6;p=redmine.git Default target version for new issues (#1828). git-svn-id: http://svn.redmine.org/redmine/trunk@14786 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 9eec9f75e..3e839e683 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -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}") diff --git a/app/models/issue.rb b/app/models/issue.rb index 9301dc9f7..5da5f4d50 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index 5e1d0c44c..323a70632 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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) } diff --git a/app/models/version.rb b/app/models/version.rb index 9910700f2..7d3387a63 100644 --- a/app/models/version.rb +++ b/app/models/version.rb @@ -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 diff --git a/app/views/projects/_form.html.erb b/app/views/projects/_form.html.erb index 1d08acc48..b75ce82d6 100644 --- a/app/views/projects/_form.html.erb +++ b/app/views/projects/_form.html.erb @@ -20,6 +20,10 @@

<%= f.check_box :inherit_members %>

<% end %> +<% if @project.safe_attribute?('default_version_id') && (default_version_options = project_default_version_options(@project)).present? %> +

<%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %>

+<% end %> + <%= wikitoolbar_for 'project_description' %> <% @project.custom_field_values.each do |value| %> diff --git a/config/locales/en.yml b/config/locales/en.yml index b2dda77b4..5158d4c0a 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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 diff --git a/config/locales/fr.yml b/config/locales/fr.yml index a2ad44246..e5fbd17c0 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -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 diff --git a/db/migrate/20151031095005_add_projects_default_version_id.rb b/db/migrate/20151031095005_add_projects_default_version_id.rb new file mode 100644 index 000000000..7d38f36cd --- /dev/null +++ b/db/migrate/20151031095005_add_projects_default_version_id.rb @@ -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 diff --git a/test/functional/issues_controller_test.rb b/test/functional/issues_controller_test.rb index 48ba81485..b1c2b26e5 100644 --- a/test/functional/issues_controller_test.rb +++ b/test/functional/issues_controller_test.rb @@ -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 diff --git a/test/unit/issue_test.rb b/test/unit/issue_test.rb index 1da9f71e2..1dea102a5 100644 --- a/test/unit/issue_test.rb +++ b/test/unit/issue_test.rb @@ -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',