diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-13 03:06:31 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2019-11-13 03:06:31 +0000 |
commit | d41c040fa25a8b4092843b84bf7d839591b6ee09 (patch) | |
tree | 5f7e94d2b6ac79483788eb867b3827af10f5bd82 | |
parent | 4689bac80c8ab86e2b37abf217cc9b3404c5255f (diff) | |
download | gitlab-ce-d41c040fa25a8b4092843b84bf7d839591b6ee09.tar.gz |
Add latest changes from gitlab-org/gitlab@master
29 files changed, 213 insertions, 11 deletions
diff --git a/app/graphql/types/issue_sort_enum.rb b/app/graphql/types/issue_sort_enum.rb index ad919b55481..f71dd114d1f 100644 --- a/app/graphql/types/issue_sort_enum.rb +++ b/app/graphql/types/issue_sort_enum.rb @@ -5,6 +5,9 @@ module Types class IssueSortEnum < IssuableSortEnum graphql_name 'IssueSort' description 'Values for sorting issues' + + value 'DUE_DATE_ASC', 'Due date by ascending order', value: 'due_date_asc' + value 'DUE_DATE_DESC', 'Due date by descending order', value: 'due_date_desc' end # rubocop: enable Graphql/AuthorizeTypes end diff --git a/app/models/issue.rb b/app/models/issue.rb index 372621b144d..5966db21813 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -138,8 +138,8 @@ class Issue < ApplicationRecord def self.sort_by_attribute(method, excluded_labels: []) case method.to_s when 'closest_future_date', 'closest_future_date_asc' then order_closest_future_date - when 'due_date', 'due_date_asc' then order_due_date_asc - when 'due_date_desc' then order_due_date_desc + when 'due_date', 'due_date_asc' then order_due_date_asc.with_order_id_desc + when 'due_date_desc' then order_due_date_desc.with_order_id_desc when 'relative_position', 'relative_position_asc' then order_relative_position_asc.with_order_id_desc else super diff --git a/changelogs/unreleased/63778-graphql-add-issue-due-date-sortring.yml b/changelogs/unreleased/63778-graphql-add-issue-due-date-sortring.yml new file mode 100644 index 00000000000..805c0f3c6b2 --- /dev/null +++ b/changelogs/unreleased/63778-graphql-add-issue-due-date-sortring.yml @@ -0,0 +1,5 @@ +--- +title: 'Issues queried in GraphQL now sortable by due date' +merge_request: 18094 +author: +type: added diff --git a/doc/api/graphql/reference/gitlab_schema.graphql b/doc/api/graphql/reference/gitlab_schema.graphql index 723294da35e..084cae38332 100644 --- a/doc/api/graphql/reference/gitlab_schema.graphql +++ b/doc/api/graphql/reference/gitlab_schema.graphql @@ -2677,6 +2677,16 @@ Values for sorting issues """ enum IssueSort { """ + Due date by ascending order + """ + DUE_DATE_ASC + + """ + Due date by descending order + """ + DUE_DATE_DESC + + """ Created at ascending order """ created_asc diff --git a/doc/api/graphql/reference/gitlab_schema.json b/doc/api/graphql/reference/gitlab_schema.json index f921f1ef45c..32aafa51cc6 100644 --- a/doc/api/graphql/reference/gitlab_schema.json +++ b/doc/api/graphql/reference/gitlab_schema.json @@ -13406,6 +13406,18 @@ "description": "Created at ascending order", "isDeprecated": false, "deprecationReason": null + }, + { + "name": "DUE_DATE_ASC", + "description": "Due date by ascending order", + "isDeprecated": false, + "deprecationReason": null + }, + { + "name": "DUE_DATE_DESC", + "description": "Due date by descending order", + "isDeprecated": false, + "deprecationReason": null } ], "possibleTypes": null diff --git a/doc/development/testing_guide/end_to_end/best_practices.md b/doc/development/testing_guide/end_to_end/best_practices.md index e73c6a61fb1..e2a0d267ba1 100644 --- a/doc/development/testing_guide/end_to_end/best_practices.md +++ b/doc/development/testing_guide/end_to_end/best_practices.md @@ -85,3 +85,11 @@ after(:all) do Page::Main::Menu.perform(&:sign_out) end ``` + +## Tag tests that require Administrator access + +We don't run tests that require Administrator access against our Production environments. + +When you add a new test that requires Administrator access, apply the RSpec metadata `:requires_admin` so that the test will not be included in the test suites executed against Production and other environments on which we don't want to run those tests. + +Note: When running tests locally or configuring a pipeline, the environment variable `QA_CAN_TEST_ADMIN_FEATURES` can be set to `false` to skip tests that have the `:requires_admin` tag. diff --git a/lib/sentry/client.rb b/lib/sentry/client.rb index 15158bbc3b5..6191d69c870 100644 --- a/lib/sentry/client.rb +++ b/lib/sentry/client.rb @@ -51,10 +51,6 @@ module Sentry raise Client::ResponseInvalidSizeError, "Sentry API response is too big. Limit is #{Gitlab::Utils::DeepSize.human_default_max_size}." end - def valid_size?(issues) - Gitlab::Utils::DeepSize.new(issues).valid? - end - def handle_mapping_exceptions(&block) yield rescue KeyError => e diff --git a/qa/qa/specs/features/browser_ui/2_plan/issue/check_mentions_for_xss_spec.rb b/qa/qa/specs/features/browser_ui/2_plan/issue/check_mentions_for_xss_spec.rb index 55e15b19200..6068b9fb04a 100644 --- a/qa/qa/specs/features/browser_ui/2_plan/issue/check_mentions_for_xss_spec.rb +++ b/qa/qa/specs/features/browser_ui/2_plan/issue/check_mentions_for_xss_spec.rb @@ -2,7 +2,7 @@ module QA context 'Plan' do - describe 'check xss occurence in @mentions in issues' do + describe 'check xss occurence in @mentions in issues', :requires_admin do it 'user mentions a user in comment' do QA::Runtime::Env.personal_access_token = QA::Runtime::Env.admin_personal_access_token diff --git a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb index 4fca2db3d0f..187c4a2a248 100644 --- a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb +++ b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb @@ -2,7 +2,7 @@ module QA context 'Performance bar' do - context 'when logged in as an admin user' do + context 'when logged in as an admin user', :requires_admin do before do Runtime::Browser.visit(:gitlab, Page::Main::Login) Page::Main::Login.perform(&:sign_in_using_admin_credentials) diff --git a/spec/graphql/resolvers/issues_resolver_spec.rb b/spec/graphql/resolvers/issues_resolver_spec.rb index 2232c9b7d7b..3ac698e0e72 100644 --- a/spec/graphql/resolvers/issues_resolver_spec.rb +++ b/spec/graphql/resolvers/issues_resolver_spec.rb @@ -72,8 +72,33 @@ describe Resolvers::IssuesResolver do expect(resolve_issues(search: 'foo')).to contain_exactly(issue2) end - it 'sort issues' do - expect(resolve_issues(sort: 'created_desc')).to eq [issue2, issue1] + describe 'sorting' do + context 'when sorting by created' do + it 'sorts issues ascending' do + expect(resolve_issues(sort: 'created_asc')).to eq [issue1, issue2] + end + + it 'sorts issues descending' do + expect(resolve_issues(sort: 'created_desc')).to eq [issue2, issue1] + end + end + + context 'when sorting by due date' do + let(:project) { create(:project) } + + let!(:due_issue1) { create(:issue, project: project, due_date: 3.days.from_now) } + let!(:due_issue2) { create(:issue, project: project, due_date: nil) } + let!(:due_issue3) { create(:issue, project: project, due_date: 2.days.ago) } + let!(:due_issue4) { create(:issue, project: project, due_date: nil) } + + it 'sorts issues ascending' do + expect(resolve_issues(sort: :due_date_asc)).to eq [due_issue3, due_issue1, due_issue4, due_issue2] + end + + it 'sorts issues descending' do + expect(resolve_issues(sort: :due_date_desc)).to eq [due_issue1, due_issue3, due_issue4, due_issue2] + end + end end it 'returns issues user can see' do diff --git a/spec/graphql/types/issue_sort_enum_spec.rb b/spec/graphql/types/issue_sort_enum_spec.rb new file mode 100644 index 00000000000..da7126f3d84 --- /dev/null +++ b/spec/graphql/types/issue_sort_enum_spec.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe GitlabSchema.types['IssueSort'] do + it { expect(described_class.graphql_name).to eq('IssueSort') } + + it_behaves_like 'common sort values' + + it 'exposes all the existing issue sort values' do + expect(described_class.values.keys).to include(*%w[DUE_DATE_ASC DUE_DATE_DESC]) + end +end diff --git a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb index a2770ef2fe4..887a6baf659 100644 --- a/spec/lib/gitlab/gitaly_client/blob_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/blob_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::BlobService do diff --git a/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb index 742b2872c40..e88b86c71f2 100644 --- a/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/blobs_stitcher_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::BlobsStitcher do diff --git a/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb b/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb index c42332dc27b..c6c7fa1c38a 100644 --- a/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/cleanup_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::CleanupService do diff --git a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb index 71489adb373..1abdabe17bb 100644 --- a/spec/lib/gitlab/gitaly_client/commit_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/commit_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::CommitService do diff --git a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb index a3602463756..db734b1c129 100644 --- a/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/conflict_files_stitcher_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::ConflictFilesStitcher do diff --git a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb index 52630ba0223..f19bcae2470 100644 --- a/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/conflicts_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::ConflictsService do diff --git a/spec/lib/gitlab/gitaly_client/diff_spec.rb b/spec/lib/gitlab/gitaly_client/diff_spec.rb index ec7ab2fdedb..d86497da7f5 100644 --- a/spec/lib/gitlab/gitaly_client/diff_spec.rb +++ b/spec/lib/gitlab/gitaly_client/diff_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::Diff do diff --git a/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb b/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb index cd3242b9326..c9d42ad32cf 100644 --- a/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb +++ b/spec/lib/gitlab/gitaly_client/diff_stitcher_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::DiffStitcher do diff --git a/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb b/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb index 2c7e5eb5787..615bc80fff2 100644 --- a/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/health_check_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::HealthCheckService do diff --git a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb index f38b8d31237..f741a91b660 100644 --- a/spec/lib/gitlab/gitaly_client/operation_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/operation_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::OperationService do diff --git a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb index 0bb6e582159..2b4fe2ea5c0 100644 --- a/spec/lib/gitlab/gitaly_client/ref_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/ref_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::RefService do diff --git a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb index d5508dbff5d..929ff5dee5d 100644 --- a/spec/lib/gitlab/gitaly_client/remote_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/remote_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::RemoteService do diff --git a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb index f4b73931f21..503ac57ade6 100644 --- a/spec/lib/gitlab/gitaly_client/repository_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/repository_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::RepositoryService do diff --git a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb index 2f83e5a5221..a6b29489df3 100644 --- a/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb +++ b/spec/lib/gitlab/gitaly_client/storage_settings_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::StorageSettings do diff --git a/spec/lib/gitlab/gitaly_client/util_spec.rb b/spec/lib/gitlab/gitaly_client/util_spec.rb index 78a5e195ad1..f31b7c349ff 100644 --- a/spec/lib/gitlab/gitaly_client/util_spec.rb +++ b/spec/lib/gitlab/gitaly_client/util_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::Util do diff --git a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb index 4fa8e97aca0..cb04f9a1637 100644 --- a/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb +++ b/spec/lib/gitlab/gitaly_client/wiki_service_spec.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'spec_helper' describe Gitlab::GitalyClient::WikiService do diff --git a/spec/requests/api/graphql/project/issues_spec.rb b/spec/requests/api/graphql/project/issues_spec.rb index 3bac39b1aae..c98f39ffee8 100644 --- a/spec/requests/api/graphql/project/issues_spec.rb +++ b/spec/requests/api/graphql/project/issues_spec.rb @@ -64,7 +64,7 @@ describe 'getting an issue list for a project' do end end - it "is expected to check permissions on the first issue only" do + it 'is expected to check permissions on the first issue only' do allow(Ability).to receive(:allowed?).and_call_original # Newest first, we only want to see the newest checked expect(Ability).not_to receive(:allowed?).with(current_user, :read_issue, issues.first) @@ -116,4 +116,95 @@ describe 'getting an issue list for a project' do end end end + + describe 'sorting and pagination' do + let(:start_cursor) { graphql_data['project']['issues']['pageInfo']['startCursor'] } + let(:end_cursor) { graphql_data['project']['issues']['pageInfo']['endCursor'] } + + context 'when sorting by due date' do + let(:sort_project) { create(:project, :public) } + + let!(:due_issue1) { create(:issue, project: sort_project, due_date: 3.days.from_now) } + let!(:due_issue2) { create(:issue, project: sort_project, due_date: nil) } + let!(:due_issue3) { create(:issue, project: sort_project, due_date: 2.days.ago) } + let!(:due_issue4) { create(:issue, project: sort_project, due_date: nil) } + let!(:due_issue5) { create(:issue, project: sort_project, due_date: 1.day.ago) } + + let(:params) { 'sort: DUE_DATE_ASC' } + + def query(issue_params = params) + graphql_query_for( + 'project', + { 'fullPath' => sort_project.full_path }, + <<~ISSUES + issues(#{issue_params}) { + pageInfo { + endCursor + } + edges { + node { + iid + dueDate + } + } + } + ISSUES + ) + end + + before do + post_graphql(query, current_user: current_user) + end + + it_behaves_like 'a working graphql query' + + context 'when ascending' do + it 'sorts issues' do + expect(grab_iids).to eq [due_issue3.iid, due_issue5.iid, due_issue1.iid, due_issue4.iid, due_issue2.iid] + end + + context 'when paginating' do + let(:params) { 'sort: DUE_DATE_ASC, first: 2' } + + it 'sorts issues' do + expect(grab_iids).to eq [due_issue3.iid, due_issue5.iid] + + cursored_query = query("sort: DUE_DATE_ASC, after: \"#{end_cursor}\"") + post_graphql(cursored_query, current_user: current_user) + response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + + expect(grab_iids(response_data)).to eq [due_issue1.iid, due_issue4.iid, due_issue2.iid] + end + end + end + + context 'when descending' do + let(:params) { 'sort: DUE_DATE_DESC' } + + it 'sorts issues' do + expect(grab_iids).to eq [due_issue1.iid, due_issue5.iid, due_issue3.iid, due_issue4.iid, due_issue2.iid] + end + + context 'when paginating' do + let(:params) { 'sort: DUE_DATE_DESC, first: 2' } + + it 'sorts issues' do + expect(grab_iids).to eq [due_issue1.iid, due_issue5.iid] + + cursored_query = query("sort: DUE_DATE_DESC, after: \"#{end_cursor}\"") + post_graphql(cursored_query, current_user: current_user) + response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + + expect(grab_iids(response_data)).to eq [due_issue3.iid, due_issue4.iid, due_issue2.iid] + end + end + end + end + end + + def grab_iids(data = issues_data) + data.map do |issue| + issue.dig('node', 'iid').to_i + end + end end diff --git a/spec/support/shared_examples/graphql/sort_enum_shared_examples.rb b/spec/support/shared_examples/graphql/sort_enum_shared_examples.rb new file mode 100644 index 00000000000..becea9bcae1 --- /dev/null +++ b/spec/support/shared_examples/graphql/sort_enum_shared_examples.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +RSpec.shared_examples 'common sort values' do + it 'exposes all the existing common sort values' do + expect(described_class.values.keys).to include(*%w[updated_desc updated_asc created_desc created_asc]) + end +end |