Project

General

Profile

Feature #42073 » 0001-Remove-navigation-parameters-from-issue-detail-URLs-after-updates.patch

Katsuya HIDAKA, 2025-01-05 16:12

View differences:

app/controllers/application_controller.rb
482 482
  end
483 483
  helper_method :back_url
484 484

  
485
  def redirect_back_or_default(default, options={})
485
  def redirect_back_or_default(default, options = {})
486
    referer = options.delete(:referer)
487

  
486 488
    if back_url = validate_back_url(params[:back_url].to_s)
487 489
      redirect_to(back_url)
488 490
      return
489
    elsif options[:referer]
491
    elsif referer
490 492
      redirect_to_referer_or default
491 493
      return
492 494
    end
493
    redirect_to default
495
    redirect_to default, options
494 496
    false
495 497
  end
496 498

  
app/controllers/issues_controller.rb
224 224
      end
225 225
      respond_to do |format|
226 226
        format.html do
227
          redirect_back_or_default(
228
            issue_path(@issue, previous_and_next_issue_ids_params)
229
          )
227
          redirect_back_or_default issue_path(@issue),
228
            flash: { previous_and_next_issue_ids: previous_and_next_issue_ids_params }
230 229
        end
231 230
        format.api  {render_api_ok}
232 231
      end
......
512 511
  end
513 512

  
514 513
  def retrieve_previous_and_next_issue_ids
515
    if params[:prev_issue_id].present? || params[:next_issue_id].present?
516
      @prev_issue_id = params[:prev_issue_id].presence.try(:to_i)
517
      @next_issue_id = params[:next_issue_id].presence.try(:to_i)
518
      @issue_position = params[:issue_position].presence.try(:to_i)
519
      @issue_count = params[:issue_count].presence.try(:to_i)
514
    if flash.key?(:previous_and_next_issue_ids)
515
      flash[:previous_and_next_issue_ids].then do |info|
516
        @prev_issue_id = info[:prev_issue_id].presence.try(:to_i)
517
        @next_issue_id = info[:next_issue_id].presence.try(:to_i)
518
        @issue_position = info[:issue_position].presence.try(:to_i)
519
        @issue_count = info[:issue_count].presence.try(:to_i)
520
      end
521
      flash.delete(:previous_and_next_issue_ids)
520 522
    else
521 523
      retrieve_query_from_session
522 524
      if @query
test/functional/issues_controller_test.rb
2642 2642
  end
2643 2643

  
2644 2644
  def test_show_should_not_display_prev_next_links_for_issue_not_in_query_results
2645
    @request.session[:issue_query] =
2646
      {
2647
        :filters => {
2648
          'status_id' => {:values => [''], :operator => 'c'}
2649
        },
2650
        :project_id => 1,
2651
        :sort => [['id', 'asc']]
2645
    @request.session[:issue_query] = {
2646
      filters: {
2647
        'status_id' => {operator: 'o', values: ['']}
2648
      },
2649
      project_id: 1,
2650
      sort: [['id', 'asc']]
2651
    }
2652
    get(:show, params: {id: 8})
2653

  
2654
    assert_response :success
2655
    assert_select 'a', text: /Previous/, count: 0
2656
    assert_select 'a', text: /Next/, count: 0
2657
  end
2658

  
2659
  def test_show_should_display_prev_next_links_for_issue_not_in_query_when_flash_contains_previous_and_next_issue_ids
2660
    @request.session[:issue_query] = {
2661
      filters: {
2662
        'status_id' => {operator: 'o', values: ['']}
2663
      },
2664
      project_id: 1,
2665
      sort: [['id', 'asc']]
2666
    }
2667
    get(
2668
      :show,
2669
      params: { id: 8 }, # The issue#8 is closed
2670
      flash: {
2671
        previous_and_next_issue_ids: {
2672
          prev_issue_id: 7,
2673
          next_issue_id: 9,
2674
          issue_position: 7,
2675
          issue_count: 10
2676
        }
2652 2677
      }
2653
    get(:show, :params => {:id => 1})
2678
    )
2679

  
2654 2680
    assert_response :success
2655
    assert_select 'a', :text => /Previous/, :count => 0
2656
    assert_select 'a', :text => /Next/, :count => 0
2681
    assert_select 'div.next-prev-links' do
2682
      assert_select 'a[href="/issues/7"]', text: /Previous/
2683
      assert_select 'a[href="/issues/9"]', text: /Next/
2684
      assert_select 'span.position', text: "7 of 10"
2685
    end
2657 2686
  end
2658 2687

  
2659 2688
  def test_show_show_should_display_prev_next_links_with_query_sort_by_user_custom_field
......
2684 2713
    end
2685 2714
  end
2686 2715

  
2687
  def test_show_should_display_prev_next_links_when_request_has_previous_and_next_issue_ids_params
2688
    get(
2689
      :show,
2690
      :params => {
2691
        :id => 1,
2692
        :prev_issue_id => 1,
2693
        :next_issue_id => 3,
2694
        :issue_position => 2,
2695
        :issue_count => 4
2696
      }
2697
    )
2698
    assert_response :success
2699
    assert_select 'div.next-prev-links' do
2700
      assert_select 'a[href="/issues/1"]', :text => /Previous/
2701
      assert_select 'a[href="/issues/3"]', :text => /Next/
2702
      assert_select 'span.position', :text => "2 of 4"
2703
    end
2704
  end
2705

  
2706 2716
  def test_show_should_display_category_field_if_categories_are_defined
2707 2717
    Issue.update_all :category_id => nil
2708 2718
    get(:show, :params => {:id => 1})
......
6903 6913
        :issue_count => 3
6904 6914
      }
6905 6915
    )
6906
    assert_redirected_to '/issues/11?issue_count=3&issue_position=2&next_issue_id=12&prev_issue_id=8'
6916
    assert_redirected_to '/issues/11'
6917
    assert_equal(
6918
      { issue_count: '3', issue_position: '2', next_issue_id: '12', prev_issue_id: '8' },
6919
      flash[:previous_and_next_issue_ids]
6920
    )
6907 6921
  end
6908 6922

  
6909 6923
  def test_update_with_permission_on_tracker_should_be_allowed
(1-1/2)