diff options
author | Jan Provaznik <jprovaznik@gitlab.com> | 2019-07-22 11:44:20 +0000 |
---|---|---|
committer | James Lopez <james@gitlab.com> | 2019-07-22 11:44:20 +0000 |
commit | 972b5f4555f70fdb47c5b3dc78127377b7220cad (patch) | |
tree | ae8b41fe06336a8cbf31307d5fdbd3a03fd62c01 | |
parent | 5ca1899a5f436cd1a8d0f6938fa1c22c1fd3d1a3 (diff) | |
download | gitlab-ce-972b5f4555f70fdb47c5b3dc78127377b7220cad.tar.gz |
Removed project autocomplete pagination
This pagination is not used anywhere so there is no reason
to keep it. It seems the usage of offset_id was probably
removed in 90c60138db4e1f86026aac5760febe4ba066ca30
-rw-r--r-- | app/finders/autocomplete/move_to_project_finder.rb | 9 | ||||
-rw-r--r-- | app/models/project.rb | 17 | ||||
-rw-r--r-- | changelogs/unreleased/jprovazn-project-search.yml | 5 | ||||
-rw-r--r-- | spec/controllers/autocomplete_controller_spec.rb | 22 | ||||
-rw-r--r-- | spec/finders/autocomplete/move_to_project_finder_spec.rb | 40 | ||||
-rw-r--r-- | spec/models/project_spec.rb | 20 |
6 files changed, 23 insertions, 90 deletions
diff --git a/app/finders/autocomplete/move_to_project_finder.rb b/app/finders/autocomplete/move_to_project_finder.rb index edaf74c5f92..491cce2232e 100644 --- a/app/finders/autocomplete/move_to_project_finder.rb +++ b/app/finders/autocomplete/move_to_project_finder.rb @@ -3,7 +3,9 @@ module Autocomplete # Finder that retrieves a list of projects that an issue can be moved to. class MoveToProjectFinder - attr_reader :current_user, :search, :project_id, :offset_id + attr_reader :current_user, :search, :project_id + + LIMIT = 20 # current_user - The User object of the user that wants to view the list of # projects. @@ -14,13 +16,10 @@ module Autocomplete # # * search: An optional search query to apply to the list of projects. # * project_id: The ID of a project to exclude from the returned relation. - # * offset_id: The ID of a project to use for pagination. When given, only - # projects with a lower ID are included in the list. def initialize(current_user, params = {}) @current_user = current_user @search = params[:search] @project_id = params[:project_id] - @offset_id = params[:offset_id] end def execute @@ -28,8 +27,8 @@ module Autocomplete .projects_where_can_admin_issues .optionally_search(search) .excluding_project(project_id) - .paginate_in_descending_order_using_id(before: offset_id) .eager_load_namespace_and_owner + .sorted_by_name_asc_limited(LIMIT) end end end diff --git a/app/models/project.rb b/app/models/project.rb index 8dfe2212282..ece7507e55c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -357,6 +357,7 @@ class Project < ApplicationRecord scope :sorted_by_activity, -> { reorder(Arel.sql("GREATEST(COALESCE(last_activity_at, '1970-01-01'), COALESCE(last_repository_updated_at, '1970-01-01')) DESC")) } scope :sorted_by_stars_desc, -> { reorder(star_count: :desc) } scope :sorted_by_stars_asc, -> { reorder(star_count: :asc) } + scope :sorted_by_name_asc_limited, ->(limit) { reorder(name: :asc).limit(limit) } scope :in_namespace, ->(namespace_ids) { where(namespace_id: namespace_ids) } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } @@ -441,22 +442,6 @@ class Project < ApplicationRecord without_deleted.find_by_id(id) end - # Paginates a collection using a `WHERE id < ?` condition. - # - # before - A project ID to use for filtering out projects with an equal or - # greater ID. If no ID is given, all projects are included. - # - # limit - The maximum number of rows to include. - def self.paginate_in_descending_order_using_id( - before: nil, - limit: Kaminari.config.default_per_page - ) - relation = order_id_desc.limit(limit) - relation = relation.where('projects.id < ?', before) if before - - relation - end - def self.eager_load_namespace_and_owner includes(namespace: :owner) end diff --git a/changelogs/unreleased/jprovazn-project-search.yml b/changelogs/unreleased/jprovazn-project-search.yml new file mode 100644 index 00000000000..f76d4858924 --- /dev/null +++ b/changelogs/unreleased/jprovazn-project-search.yml @@ -0,0 +1,5 @@ +--- +title: Order projects in 'Move issue' dropdown by name. +merge_request: 30778 +author: +type: fixed diff --git a/spec/controllers/autocomplete_controller_spec.rb b/spec/controllers/autocomplete_controller_spec.rb index 3f1c0ae8ac4..eaa5d6cd073 100644 --- a/spec/controllers/autocomplete_controller_spec.rb +++ b/spec/controllers/autocomplete_controller_spec.rb @@ -295,28 +295,6 @@ describe AutocompleteController do end end - context 'authorized projects with offset' do - before do - authorized_project2 = create(:project) - authorized_project3 = create(:project) - - authorized_project.add_maintainer(user) - authorized_project2.add_maintainer(user) - authorized_project3.add_maintainer(user) - end - - describe 'GET #projects with project ID and offset_id' do - before do - get(:projects, params: { project_id: project.id, offset_id: authorized_project.id }) - end - - it 'returns projects' do - expect(json_response).to be_kind_of(Array) - expect(json_response.size).to eq 2 # Of a total of 3 - end - end - end - context 'authorized projects without admin_issue ability' do before do authorized_project.add_guest(user) diff --git a/spec/finders/autocomplete/move_to_project_finder_spec.rb b/spec/finders/autocomplete/move_to_project_finder_spec.rb index c3bc410a7f6..4a87b47bd08 100644 --- a/spec/finders/autocomplete/move_to_project_finder_spec.rb +++ b/spec/finders/autocomplete/move_to_project_finder_spec.rb @@ -6,9 +6,9 @@ describe Autocomplete::MoveToProjectFinder do let(:no_access_project) { create(:project) } let(:guest_project) { create(:project) } - let(:reporter_project) { create(:project) } - let(:developer_project) { create(:project) } - let(:maintainer_project) { create(:project) } + let(:reporter_project) { create(:project, name: 'name') } + let(:developer_project) { create(:project, name: 'name2') } + let(:maintainer_project) { create(:project, name: 'name3') } describe '#execute' do context 'filter' do @@ -20,14 +20,14 @@ describe Autocomplete::MoveToProjectFinder do expect(finder.execute).to be_empty end - it 'returns projects equal or above Gitlab::Access::REPORTER ordered by id in descending order' do + it 'returns projects equal or above Gitlab::Access::REPORTER ordered by name' do reporter_project.add_reporter(user) developer_project.add_developer(user) maintainer_project.add_maintainer(user) finder = described_class.new(user, project_id: project.id) - expect(finder.execute.to_a).to eq([maintainer_project, developer_project, reporter_project]) + expect(finder.execute.to_a).to eq([reporter_project, developer_project, maintainer_project]) end it 'does not include the source project' do @@ -60,46 +60,32 @@ describe Autocomplete::MoveToProjectFinder do expect(finder.execute.to_a).to eq([other_reporter_project]) end - it 'returns a page of projects ordered by id in descending order' do - allow(Kaminari.config).to receive(:default_per_page).and_return(2) + it 'returns a page of projects ordered by name' do + stub_const('Autocomplete::MoveToProjectFinder::LIMIT', 2) - projects = create_list(:project, 2) do |project| + projects = create_list(:project, 3) do |project| project.add_developer(user) end finder = described_class.new(user, project_id: project.id) page = finder.execute.to_a - expect(page.length).to eq(Kaminari.config.default_per_page) - expect(page[0]).to eq(projects.last) - end - - it 'returns projects after the given offset id' do - reporter_project.add_reporter(user) - developer_project.add_developer(user) - maintainer_project.add_maintainer(user) - - expect(described_class.new(user, project_id: project.id, offset_id: maintainer_project.id).execute.to_a) - .to eq([developer_project, reporter_project]) - - expect(described_class.new(user, project_id: project.id, offset_id: developer_project.id).execute.to_a) - .to eq([reporter_project]) - - expect(described_class.new(user, project_id: project.id, offset_id: reporter_project.id).execute.to_a) - .to be_empty + expected_projects = projects.sort_by(&:name).first(2) + expect(page.length).to eq(2) + expect(page).to eq(expected_projects) end end context 'search' do it 'returns projects matching a search query' do - foo_project = create(:project) + foo_project = create(:project, name: 'foo') foo_project.add_maintainer(user) wadus_project = create(:project, name: 'wadus') wadus_project.add_maintainer(user) expect(described_class.new(user, project_id: project.id).execute.to_a) - .to eq([wadus_project, foo_project]) + .to eq([foo_project, wadus_project]) expect(described_class.new(user, project_id: project.id, search: 'wadus').execute.to_a) .to eq([wadus_project]) diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 927c072be10..bcb2da7eed2 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -1675,26 +1675,6 @@ describe Project do end end - describe '.paginate_in_descending_order_using_id' do - let!(:project1) { create(:project) } - let!(:project2) { create(:project) } - - it 'orders the relation in descending order' do - expect(described_class.paginate_in_descending_order_using_id) - .to eq([project2, project1]) - end - - it 'applies a limit to the relation' do - expect(described_class.paginate_in_descending_order_using_id(limit: 1)) - .to eq([project2]) - end - - it 'limits projects by and ID when given' do - expect(described_class.paginate_in_descending_order_using_id(before: project2.id)) - .to eq([project1]) - end - end - describe '.including_namespace_and_owner' do it 'eager loads the namespace and namespace owner' do create(:project) |