From 1f79610fdc05fe306ee56c60b2cb1b249ff9010d Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Sat, 18 Jun 2016 10:18:40 +0000 Subject: [PATCH] Merged r15536 and r15541 (#23083). git-svn-id: http://svn.redmine.org/redmine/branches/3.3-stable@15560 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- lib/redmine/field_format.rb | 21 ++++++++++++------- test/unit/custom_field_version_format_test.rb | 1 + .../field_format/version_field_format_test.rb | 9 ++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/redmine/field_format.rb b/lib/redmine/field_format.rb index 7734b3984..0347ca8da 100644 --- a/lib/redmine/field_format.rb +++ b/lib/redmine/field_format.rb @@ -804,17 +804,24 @@ module Redmine projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || [] elsif object.respond_to?(:project) && object.project scope = object.project.shared_versions - if !all_statuses && custom_field.version_status.is_a?(Array) - statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) - if statuses.any? - scope = scope.where(:status => statuses.map(&:to_s)) - end - end - scope.sort.collect {|u| [u.to_s, u.id.to_s]} + filtered_versions_options(custom_field, scope, all_statuses) + elsif object.nil? + scope = Version.visible.where(:sharing => 'system') + filtered_versions_options(custom_field, scope, all_statuses) else [] end end + + def filtered_versions_options(custom_field, scope, all_statuses=false) + if !all_statuses && custom_field.version_status.is_a?(Array) + statuses = custom_field.version_status.map(&:to_s).reject(&:blank?) + if statuses.any? + scope = scope.where(:status => statuses.map(&:to_s)) + end + end + scope.sort.collect{|u| [u.to_s, u.id.to_s] } + end end end end diff --git a/test/unit/custom_field_version_format_test.rb b/test/unit/custom_field_version_format_test.rb index f8a95174e..a394dabc8 100644 --- a/test/unit/custom_field_version_format_test.rb +++ b/test/unit/custom_field_version_format_test.rb @@ -25,6 +25,7 @@ class CustomFieldVersionFormatTest < ActiveSupport::TestCase end def test_possible_values_options_with_no_arguments + Version.delete_all assert_equal [], @field.possible_values_options assert_equal [], @field.possible_values_options(nil) end diff --git a/test/unit/lib/redmine/field_format/version_field_format_test.rb b/test/unit/lib/redmine/field_format/version_field_format_test.rb index 191895145..0b3006c65 100644 --- a/test/unit/lib/redmine/field_format/version_field_format_test.rb +++ b/test/unit/lib/redmine/field_format/version_field_format_test.rb @@ -51,6 +51,15 @@ class Redmine::VersionFieldFormatTest < ActionView::TestCase assert_equal expected, field.possible_values_options(project).map(&:first) end + + def test_possible_values_options_should_return_system_shared_versions_without_project + field = IssueCustomField.new(:field_format => 'version') + version = Version.generate!(:project => Project.find(1), :status => 'open', :sharing => 'system') + + expected = Version.visible.where(:sharing => 'system').sort.map(&:name) + assert_include version.name, expected + assert_equal expected, field.possible_values_options.map(&:first) + end def test_possible_values_options_should_return_project_versions_with_selected_status field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"]) -- 2.39.5