Project

General

Profile

Patch #23083 » 0001-Allow-global-versions-to-be-shown-outside-of-a-proje.patch

Holger Just, 2016-06-16 14:16

View differences:

lib/redmine/field_format.rb
802 802
          projects.map {|project| possible_values_options(custom_field, project)}.reduce(:&) || []
803 803
        elsif object.respond_to?(:project) && object.project
804 804
          scope = object.project.shared_versions
805
          if !all_statuses && custom_field.version_status.is_a?(Array)
806
            statuses = custom_field.version_status.map(&:to_s).reject(&:blank?)
807
            if statuses.any?
808
              scope = scope.where(:status => statuses.map(&:to_s))
809
            end
810
          end
811
          scope.sort.collect {|u| [u.to_s, u.id.to_s]}
805
          filtered_versions_options(custom_field, scope, all_statuses)
806
        elsif object.nil?
807
          scope = Version.visible.where(:sharing => 'system')
808
          filtered_versions_options(custom_field, scope, all_statuses)
812 809
        else
813 810
          []
814 811
        end
815 812
      end
813

  
814
      def filtered_versions_options(custom_field, scope, all_statuses=false)
815
        if !all_statuses && custom_field.version_status.is_a?(Array)
816
          statuses = custom_field.version_status.map(&:to_s).reject(&:blank?)
817
          if statuses.any?
818
            scope = scope.where(:status => statuses.map(&:to_s))
819
          end
820
        end
821
        scope.sort.collect{|u| [u.to_s, u.id.to_s] }
822
      end
816 823
    end
817 824
  end
818 825
end
test/unit/lib/redmine/field_format/version_field_format_test.rb
52 52
    assert_equal expected, field.possible_values_options(project).map(&:first)
53 53
  end
54 54

  
55
  def test_possible_values_options_should_return_system_shared_versions_without_project
56
    field = IssueCustomField.new(:field_format => 'version')
57
    version = Version.generate!(:project => Project.find(1), :status => 'open', :sharing => 'system')
58

  
59
    expected = Version.visible.where(:sharing => 'system').sort.map(&:name)
60
    assert_include version.name, expected
61
    assert_equal expected, field.possible_values_options.map(&:first)
62
  end
63

  
55 64
  def test_possible_values_options_should_return_project_versions_with_selected_status
56 65
    field = IssueCustomField.new(:field_format => 'version', :version_status => ["open"])
57 66
    project = Project.find(1)
(1-1/2)