##// END OF EJS Templates
Add option to set a new version as default directly from New Version page (#24011)....
Jean-Philippe Lang -
r15540:eb023bdcce2b
parent child
Show More
@@ -19,6 +19,7 class Version < ActiveRecord::Base
19 include Redmine::SafeAttributes
19 include Redmine::SafeAttributes
20
20
21 after_update :update_issues_from_sharing_change
21 after_update :update_issues_from_sharing_change
22 after_save :update_default_project_version
22 before_destroy :nullify_projects_default_version
23 before_destroy :nullify_projects_default_version
23
24
24 belongs_to :project
25 belongs_to :project
@@ -65,6 +66,7 class Version < ActiveRecord::Base
65 'wiki_page_title',
66 'wiki_page_title',
66 'status',
67 'status',
67 'sharing',
68 'sharing',
69 'default_project_version',
68 'custom_field_values',
70 'custom_field_values',
69 'custom_fields'
71 'custom_fields'
70
72
@@ -82,6 +84,12 class Version < ActiveRecord::Base
82 project.present? && project.attachments_deletable?(usr)
84 project.present? && project.attachments_deletable?(usr)
83 end
85 end
84
86
87 alias :base_reload :reload
88 def reload(*args)
89 @default_project_version = nil
90 base_reload(*args)
91 end
92
85 def start_date
93 def start_date
86 @start_date ||= fixed_issues.minimum('start_date')
94 @start_date ||= fixed_issues.minimum('start_date')
87 end
95 end
@@ -263,6 +271,18 class Version < ActiveRecord::Base
263 fixed_issues.empty? && !referenced_by_a_custom_field?
271 fixed_issues.empty? && !referenced_by_a_custom_field?
264 end
272 end
265
273
274 def default_project_version
275 if @default_project_version.nil?
276 project.present? && project.default_version == self
277 else
278 @default_project_version
279 end
280 end
281
282 def default_project_version=(arg)
283 @default_project_version = (arg == '1' || arg == true)
284 end
285
266 private
286 private
267
287
268 def load_issue_counts
288 def load_issue_counts
@@ -291,6 +311,12 class Version < ActiveRecord::Base
291 end
311 end
292 end
312 end
293
313
314 def update_default_project_version
315 if @default_project_version && project.present?
316 project.update_columns :default_version_id => id
317 end
318 end
319
294 # Returns the average estimated time of assigned issues
320 # Returns the average estimated time of assigned issues
295 # or 1 if no issue has an estimated time
321 # or 1 if no issue has an estimated time
296 # Used to weight unestimated issues in progress calculation
322 # Used to weight unestimated issues in progress calculation
@@ -10,6 +10,9
10 <p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
10 <p><%= f.text_field :wiki_page_title, :label => :label_wiki_page, :size => 60, :disabled => @project.wiki.nil? %></p>
11 <p><%= f.date_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
11 <p><%= f.date_field :effective_date, :size => 10 %><%= calendar_for('version_effective_date') %></p>
12 <p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p>
12 <p><%= f.select :sharing, @version.allowed_sharings.collect {|v| [format_version_sharing(v), v]} %></p>
13 <% if @version.new_record? %>
14 <p><%= f.check_box :default_project_version, :label => :field_default_version %></p>
15 <% end %>
13
16
14 <% @version.custom_field_values.each do |value| %>
17 <% @version.custom_field_values.each do |value| %>
15 <p><%= custom_field_tag_with_label :version, value %></p>
18 <p><%= custom_field_tag_with_label :version, value %></p>
@@ -29,6 +29,22 class VersionTest < ActiveSupport::TestCase
29 assert_equal 'none', v.sharing
29 assert_equal 'none', v.sharing
30 end
30 end
31
31
32 def test_create_as_default_project_version
33 project = Project.find(1)
34 v = Version.new(:project => project, :name => '1.1',
35 :default_project_version => '1')
36 assert v.save
37 assert_equal v, project.reload.default_version
38 end
39
40 def test_create_not_as_default_project_version
41 project = Project.find(1)
42 v = Version.new(:project => project, :name => '1.1',
43 :default_project_version => '0')
44 assert v.save
45 assert_nil project.reload.default_version
46 end
47
32 def test_invalid_effective_date_validation
48 def test_invalid_effective_date_validation
33 v = Version.new(:project => Project.find(1), :name => '1.1',
49 v = Version.new(:project => Project.find(1), :name => '1.1',
34 :effective_date => '99999-01-01')
50 :effective_date => '99999-01-01')
General Comments 0
You need to be logged in to leave comments. Login now