@@ -0,0 +1,12 | |||
|
1 | class AddProjectsDefaultVersionId < ActiveRecord::Migration | |
|
2 | def self.up | |
|
3 | # Don't try to add the column if redmine_default_version plugin was used | |
|
4 | unless column_exists?(:projects, :default_version_id, :integer) | |
|
5 | add_column :projects, :default_version_id, :integer, :default => nil | |
|
6 | end | |
|
7 | end | |
|
8 | ||
|
9 | def self.down | |
|
10 | remove_column :projects, :default_version_id | |
|
11 | end | |
|
12 | end |
@@ -87,6 +87,14 module ProjectsHelper | |||
|
87 | 87 | end |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | def project_default_version_options(project) | |
|
91 | versions = project.shared_versions.open.to_a | |
|
92 | if project.default_version && !versions.include?(project.default_version) | |
|
93 | versions << project.default_version | |
|
94 | end | |
|
95 | version_options_for_select(versions, project.default_version) | |
|
96 | end | |
|
97 | ||
|
90 | 98 | def format_version_sharing(sharing) |
|
91 | 99 | sharing = 'none' unless Version::VERSION_SHARINGS.include?(sharing) |
|
92 | 100 | l("label_version_sharing_#{sharing}") |
@@ -327,10 +327,13 class Issue < ActiveRecord::Base | |||
|
327 | 327 | # Unless keep_tracker argument is set to true, this will change the tracker |
|
328 | 328 | # to the first tracker of the new project if the previous tracker is not part |
|
329 | 329 | # of the new project trackers. |
|
330 | # This will clear the fixed_version is it's no longer valid for the new project. | |
|
331 |
# |
|
|
332 | # This will set the category to the category with the same name in the new | |
|
330 | # This will: | |
|
331 | # * clear the fixed_version is it's no longer valid for the new project. | |
|
332 | # * clear the parent issue if it's no longer valid for the new project. | |
|
333 | # * set the category to the category with the same name in the new | |
|
333 | 334 | # project if it exists, or clear it if it doesn't. |
|
335 | # * for new issue, set the fixed_version to the project default version | |
|
336 | # if it's a valid fixed_version. | |
|
334 | 337 | def project=(project, keep_tracker=false) |
|
335 | 338 | project_was = self.project |
|
336 | 339 | association(:project).writer(project) |
@@ -355,6 +358,12 class Issue < ActiveRecord::Base | |||
|
355 | 358 | @custom_field_values = nil |
|
356 | 359 | @workflow_rule_by_attribute = nil |
|
357 | 360 | end |
|
361 | # Set fixed_version to the project default version if it's valid | |
|
362 | if new_record? && fixed_version.nil? && project && project.default_version_id? | |
|
363 | if project.shared_versions.open.exists?(project.default_version_id) | |
|
364 | self.fixed_version_id = project.default_version_id | |
|
365 | end | |
|
366 | end | |
|
358 | 367 | self.project |
|
359 | 368 | end |
|
360 | 369 |
@@ -38,6 +38,7 class Project < ActiveRecord::Base | |||
|
38 | 38 | has_many :issues, :dependent => :destroy |
|
39 | 39 | has_many :issue_changes, :through => :issues, :source => :journals |
|
40 | 40 | has_many :versions, lambda {order("#{Version.table_name}.effective_date DESC, #{Version.table_name}.name DESC")}, :dependent => :destroy |
|
41 | belongs_to :default_version, :class_name => 'Version' | |
|
41 | 42 | has_many :time_entries, :dependent => :destroy |
|
42 | 43 | has_many :queries, :class_name => 'IssueQuery', :dependent => :delete_all |
|
43 | 44 | has_many :documents, :dependent => :destroy |
@@ -687,7 +688,8 class Project < ActiveRecord::Base | |||
|
687 | 688 | 'custom_fields', |
|
688 | 689 | 'tracker_ids', |
|
689 | 690 | 'issue_custom_field_ids', |
|
690 | 'parent_id' | |
|
691 | 'parent_id', | |
|
692 | 'default_version_id' | |
|
691 | 693 | |
|
692 | 694 | safe_attributes 'enabled_module_names', |
|
693 | 695 | :if => lambda {|project, user| project.new_record? || user.allowed_to?(:select_project_modules, project) } |
@@ -17,7 +17,10 | |||
|
17 | 17 | |
|
18 | 18 | class Version < ActiveRecord::Base |
|
19 | 19 | include Redmine::SafeAttributes |
|
20 | ||
|
20 | 21 | after_update :update_issues_from_sharing_change |
|
22 | before_destroy :nullify_projects_default_version | |
|
23 | ||
|
21 | 24 | belongs_to :project |
|
22 | 25 | has_many :fixed_issues, :class_name => 'Issue', :foreign_key => 'fixed_version_id', :dependent => :nullify |
|
23 | 26 | acts_as_customizable |
@@ -297,4 +300,8 class Version < ActiveRecord::Base | |||
|
297 | 300 | CustomValue.joins(:custom_field). |
|
298 | 301 | where(:value => id.to_s, :custom_fields => {:field_format => 'version'}).any? |
|
299 | 302 | end |
|
303 | ||
|
304 | def nullify_projects_default_version | |
|
305 | Project.where(:default_version_id => id).update_all(:default_version_id => nil) | |
|
306 | end | |
|
300 | 307 | end |
@@ -20,6 +20,10 | |||
|
20 | 20 | <p><%= f.check_box :inherit_members %></p> |
|
21 | 21 | <% end %> |
|
22 | 22 | |
|
23 | <% if @project.safe_attribute?('default_version_id') && (default_version_options = project_default_version_options(@project)).present? %> | |
|
24 | <p><%= f.select :default_version_id, project_default_version_options(@project), :include_blank => true %></p> | |
|
25 | <% end %> | |
|
26 | ||
|
23 | 27 | <%= wikitoolbar_for 'project_description' %> |
|
24 | 28 | |
|
25 | 29 | <% @project.custom_field_values.each do |value| %> |
@@ -348,6 +348,7 en: | |||
|
348 | 348 | field_users_visibility: Users visibility |
|
349 | 349 | field_time_entries_visibility: Time logs visibility |
|
350 | 350 | field_total_estimated_hours: Total estimated time |
|
351 | field_default_version: Default version | |
|
351 | 352 | |
|
352 | 353 | setting_app_title: Application title |
|
353 | 354 | setting_app_subtitle: Application subtitle |
@@ -368,6 +368,7 fr: | |||
|
368 | 368 | field_users_visibility: Visibilité des utilisateurs |
|
369 | 369 | field_time_entries_visibility: Visibilité du temps passé |
|
370 | 370 | field_total_estimated_hours: Temps estimé total |
|
371 | field_default_version: Version par défaut | |
|
371 | 372 | |
|
372 | 373 | setting_app_title: Titre de l'application |
|
373 | 374 | setting_app_subtitle: Sous-titre de l'application |
@@ -1715,6 +1715,19 class IssuesControllerTest < ActionController::TestCase | |||
|
1715 | 1715 | end |
|
1716 | 1716 | end |
|
1717 | 1717 | |
|
1718 | def test_new_should_preselect_default_version | |
|
1719 | version = Version.generate!(:project_id => 1) | |
|
1720 | Project.find(1).update_attribute :default_version_id, version.id | |
|
1721 | @request.session[:user_id] = 2 | |
|
1722 | ||
|
1723 | get :new, :project_id => 1 | |
|
1724 | assert_response :success | |
|
1725 | assert_equal version, assigns(:issue).fixed_version | |
|
1726 | assert_select 'select[name=?]', 'issue[fixed_version_id]' do | |
|
1727 | assert_select 'option[value=?][selected=selected]', version.id.to_s | |
|
1728 | end | |
|
1729 | end | |
|
1730 | ||
|
1718 | 1731 | def test_get_new_with_list_custom_field |
|
1719 | 1732 | @request.session[:user_id] = 2 |
|
1720 | 1733 | get :new, :project_id => 1, :tracker_id => 1 |
@@ -496,6 +496,14 class IssueTest < ActiveSupport::TestCase | |||
|
496 | 496 | assert_equal custom_value.id, issue.custom_value_for(field).id |
|
497 | 497 | end |
|
498 | 498 | |
|
499 | def test_setting_project_should_set_version_to_default_version | |
|
500 | version = Version.generate!(:project_id => 1) | |
|
501 | Project.find(1).update_attribute(:default_version_id, version.id) | |
|
502 | ||
|
503 | issue = Issue.new(:project_id => 1) | |
|
504 | assert_equal version, issue.fixed_version | |
|
505 | end | |
|
506 | ||
|
499 | 507 | def test_should_not_update_custom_fields_on_changing_tracker_with_different_custom_fields |
|
500 | 508 | issue = Issue.create!(:project_id => 1, :tracker_id => 1, :author_id => 1, |
|
501 | 509 | :status_id => 1, :subject => 'Test', |
General Comments 0
You need to be logged in to leave comments.
Login now