Project

General

Profile

Patch #43534 » Patch__target_version_filter_including_subprojects.patch

target version filter including subprojects v1 - Jan Catrysse, 2025-11-26 15:06

View differences:

app/controllers/queries_controller.rb (revision 8fccd687b604501ec83d29f9b062e667b94a2849) → app/controllers/queries_controller.rb (revision 9e53bc939f3feedb5464134f7d869192a1661446)
96 96
      q.project = Project.find(params[:project_id])
97 97
    end
98 98

  
99
    q.build_from_params(params)
100

  
99 101
    unless User.current.allowed_to?(q.class.view_permission, q.project, :global => true)
100 102
      raise Unauthorized
101 103
    end
app/models/issue_query.rb (revision 8fccd687b604501ec83d29f9b062e667b94a2849) → app/models/issue_query.rb (revision 9e53bc939f3feedb5464134f7d869192a1661446)
473 473
    raise StatementInvalid.new(e.message)
474 474
  end
475 475

  
476
  def fixed_version_values
477
    versions_scope =
478
      if project
479
        Version.visible.where(project_statement).includes(:project).references(:project)
480
      else
481
        Version.visible
482
      end
483

  
484
    Version.sort_by_status(versions_scope.distinct.to_a).
485
      collect{|s| ["#{s.project.name} - #{s.name}", s.id.to_s, l("version_status_#{s.status}")]}
486
  end
487

  
476 488
  def sql_for_notes_field(field, operator, value)
477 489
    subquery = "SELECT 1 FROM #{Journal.table_name}" +
478 490
      " WHERE #{Journal.table_name}.journalized_type='Issue' AND #{Journal.table_name}.journalized_id=#{Issue.table_name}.id" +
public/javascripts/application.js (revision 8fccd687b604501ec83d29f9b062e667b94a2849) → public/javascripts/application.js (revision 9e53bc939f3feedb5464134f7d869192a1661446)
132 132
  if (!filterOptions) return;
133 133

  
134 134
  if (filterOptions['remote'] && filterOptions['values'] == null) {
135
    $.getJSON(filtersUrl, {'name': field}).done(function(data) {
135
    var form = $('#query_form, #gantt_form, #calendar_form, #timelog_form, #time_entries_form').filter('form').first();
136
    var data = form.length ? form.serializeArray() : [];
137
    data.push({name: 'name', value: field});
138

  
139
    $.getJSON(filtersUrl, data).done(function(data) {
136 140
      filterOptions['values'] = data;
137 141
      addFilter(field, operator, values) ;
138 142
    });
test/functional/queries_controller_test.rb (revision 8fccd687b604501ec83d29f9b062e667b94a2849) → test/functional/queries_controller_test.rb (revision 9e53bc939f3feedb5464134f7d869192a1661446)
795 795
    assert_include ["eCookbook - 2.0", "3", "open"], json
796 796
  end
797 797

  
798
  def test_filter_should_build_query_from_params
799
    version = Version.create!(:project => Project.find(3), :name => 'Local subproject', :status => 'open')
800

  
801
    @request.session[:user_id] = 2
802
    get(
803
      :filter,
804
      :params => {
805
        :project_id => 1,
806
        :name => 'fixed_version_id',
807
        :set_filter => '1',
808
        :f => ['subproject_id'],
809
        :op => {'subproject_id' => '='},
810
        :v => {'subproject_id' => [version.project_id.to_s]}
811
      }
812
    )
813

  
814
    assert_response :success
815
    assert_equal 'application/json', response.media_type
816
    json = ActiveSupport::JSON.decode(response.body)
817
    assert_include ["#{version.project.name} - #{version.name}", version.id.to_s, "open"], json
818
  end
819

  
798 820
  def test_version_filter_without_project_id_should_return_all_visible_fixed_versions
799 821
    # Remove "jsmith" user from "Private child of eCookbook" project
800 822
    Project.find(5).memberships.find_by(:user_id => 2).destroy
test/unit/query_test.rb (revision 8fccd687b604501ec83d29f9b062e667b94a2849) → test/unit/query_test.rb (revision 9e53bc939f3feedb5464134f7d869192a1661446)
161 161
    assert_include subproject_version.id.to_s, filter[:values].map(&:second)
162 162
  end
163 163

  
164
  def test_fixed_version_filter_should_include_subproject_versions_when_displaying_subproject_issues
165
    with_settings :display_subprojects_issues => '1' do
166
      subproject = Project.find(3)
167
      version = Version.create!(:project => subproject, :name => 'Unshared subproject version')
168

  
169
      query = IssueQuery.new(:project => Project.find(1), :name => '_')
170
      filter = query.available_filters["fixed_version_id"]
171

  
172
      assert_not_nil filter
173
      assert_include version.id.to_s, filter[:values].map(&:second)
174
    end
175
  end
176

  
177
  def test_fixed_version_filter_should_respect_selected_subprojects
178
    subproject_1 = Project.find(3)
179
    subproject_2 = Project.find(4)
180
    version_1 = Version.create!(:project => subproject_1, :name => 'Subproject 1 version')
181
    version_2 = Version.create!(:project => subproject_2, :name => 'Subproject 2 version')
182

  
183
    query = IssueQuery.new(:project => Project.find(1), :name => '_')
184
    query.add_filter('subproject_id', '=', [subproject_1.id.to_s])
185
    filter = query.available_filters["fixed_version_id"]
186

  
187
    assert_not_nil filter
188
    values = filter[:values].map(&:second)
189
    assert_include version_1.id.to_s, values
190
    assert_not_include version_2.id.to_s, values
191
  end
192

  
193
  def test_fixed_version_filter_should_include_all_subproject_versions_when_filtering_any_subproject
194
    with_settings :display_subprojects_issues => '0' do
195
      subproject = Project.find(3)
196
      version = Version.create!(:project => subproject, :name => 'Any subproject version')
197

  
198
      query = IssueQuery.new(:project => Project.find(1), :name => '_')
199
      query.add_filter('subproject_id', '*', [''])
200
      filter = query.available_filters["fixed_version_id"]
201

  
202
      assert_not_nil filter
203
      assert_include version.id.to_s, filter[:values].map(&:second)
204
    end
205
  end
206

  
164 207
  def test_query_with_multiple_custom_fields
165 208
    query = IssueQuery.find(1)
166 209
    assert query.valid?
    (1-1/1)