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}")
# 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)
@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
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
'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) }
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
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
<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| %>
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
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
--- /dev/null
+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
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
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',