From 98bec8db98213f35570a985b4388e5958bc21e5c Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Fri, 15 Apr 2022 06:08:54 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/helpers/application_settings_helper.rb | 40 ++++----- app/models/environment.rb | 2 +- .../_visibility_and_access.html.haml | 22 ++--- app/views/projects/issues/_form.html.haml | 2 +- .../projects/merge_requests/_form.html.haml | 2 +- .../creations/_new_submit.html.haml | 2 +- .../issuable/form/_contribution.html.haml | 13 ++- .../shared/issuable/form/_metadata.html.haml | 6 +- .../env_last_deployment_by_finished_at.yml | 2 +- ...untime_data_columns_to_vsa_aggregations.rb | 0 ...to_vsa_aggregation_runtime_data_columns.rb | 0 lib/gitlab/data_builder/deployment.rb | 9 +- locale/gitlab.pot | 8 +- qa/qa/page/dashboard/todos.rb | 6 +- .../merge_train_spec_with_user_prep.rb | 88 +++++++++++++++++++ spec/features/admin/admin_settings_spec.rb | 12 +-- .../gitlab/data_builder/deployment_spec.rb | 22 ++++- 17 files changed, 166 insertions(+), 70 deletions(-) rename db/{post_migrate => migrate}/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb (100%) rename db/{post_migrate => migrate}/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb (100%) create mode 100644 qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb diff --git a/app/helpers/application_settings_helper.rb b/app/helpers/application_settings_helper.rb index 77cf3cc92eb..57e08eeb4f4 100644 --- a/app/helpers/application_settings_helper.rb +++ b/app/helpers/application_settings_helper.rb @@ -69,39 +69,31 @@ module ApplicationSettingsHelper end end - # Return a group of checkboxes that use Bootstrap's button plugin for a - # toggle button effect. - def restricted_level_checkboxes(help_block_id, checkbox_name, options = {}) + def restricted_level_checkboxes(form) Gitlab::VisibilityLevel.values.map do |level| checked = restricted_visibility_levels(true).include?(level) - css_class = checked ? 'active' : '' - tag_name = "application_setting_visibility_level_#{level}" - label_tag(tag_name, class: css_class) do - check_box_tag(checkbox_name, level, checked, - autocomplete: 'off', - 'aria-describedby' => help_block_id, - 'class' => options[:class], - id: tag_name) + visibility_level_icon(level) + visibility_level_label(level) - end + form.gitlab_ui_checkbox_component( + :restricted_visibility_levels, + "#{visibility_level_icon(level)} #{visibility_level_label(level)}".html_safe, + checkbox_options: { checked: checked, multiple: true, autocomplete: 'off' }, + checked_value: level, + unchecked_value: nil + ) end end - # Return a group of checkboxes that use Bootstrap's button plugin for a - # toggle button effect. - def import_sources_checkboxes(help_block_id, options = {}) + def import_sources_checkboxes(form) Gitlab::ImportSources.options.map do |name, source| checked = @application_setting.import_sources.include?(source) - css_class = checked ? 'active' : '' - checkbox_name = 'application_setting[import_sources][]' - label_tag(name, class: css_class) do - check_box_tag(checkbox_name, source, checked, - autocomplete: 'off', - 'aria-describedby' => help_block_id, - 'class' => options[:class], - id: name.tr(' ', '_')) + name - end + form.gitlab_ui_checkbox_component( + :import_sources, + name, + checkbox_options: { checked: checked, multiple: true, autocomplete: 'off' }, + checked_value: source, + unchecked_value: nil + ) end end diff --git a/app/models/environment.rb b/app/models/environment.rb index a3fb35917ba..4c4ba22fae1 100644 --- a/app/models/environment.rb +++ b/app/models/environment.rb @@ -26,7 +26,7 @@ class Environment < ApplicationRecord has_many :self_managed_prometheus_alert_events, inverse_of: :environment has_many :alert_management_alerts, class_name: 'AlertManagement::Alert', inverse_of: :environment - has_one :last_deployment, -> { Feature.enabled?(:env_last_deployment_by_finished_at) ? success.ordered : success.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment + has_one :last_deployment, -> { Feature.enabled?(:env_last_deployment_by_finished_at, default_enabled: :yaml) ? success.ordered : success.distinct_on_environment }, class_name: 'Deployment', inverse_of: :environment has_one :last_visible_deployment, -> { visible.distinct_on_environment }, inverse_of: :environment, class_name: 'Deployment' has_one :last_visible_deployable, through: :last_visible_deployment, source: 'deployable', source_type: 'CommitStatus', disable_joins: true has_one :last_visible_pipeline, through: :last_visible_deployable, source: 'pipeline', disable_joins: true diff --git a/app/views/admin/application_settings/_visibility_and_access.html.haml b/app/views/admin/application_settings/_visibility_and_access.html.haml index 94bd5894d28..23649bc2d54 100644 --- a/app/views/admin/application_settings/_visibility_and_access.html.haml +++ b/app/views/admin/application_settings/_visibility_and_access.html.haml @@ -17,18 +17,16 @@ = render('shared/visibility_radios', model_method: :default_group_visibility, form: f, selected_level: @application_setting.default_group_visibility, form_model: Group.new) .form-group = f.label :restricted_visibility_levels, class: 'label-bold' - - checkbox_name = 'application_setting[restricted_visibility_levels][]' - = hidden_field_tag(checkbox_name) - - restricted_level_checkboxes('restricted-visibility-help', checkbox_name, class: 'form-check-input').each do |level| - .form-check - = level + = hidden_field_tag 'application_setting[restricted_visibility_levels][]' + - restricted_level_checkboxes(f).each do |level| + = level %span.form-text.text-muted#restricted-visibility-help = _('Selected levels cannot be used by non-admin users for groups, projects or snippets. If the public level is restricted, user profiles are only visible to logged in users.') .form-group = f.label :import_sources, class: 'label-bold' = hidden_field_tag 'application_setting[import_sources][]' - - import_sources_checkboxes('import-sources-help', class: 'form-check-input').each do |source| - .form-check= source + - import_sources_checkboxes(f).each do |source| + = source %span.form-text.text-muted#import-sources-help = _('Enabled sources for code import during project creation. OmniAuth must be configured for GitHub') = link_to sprite_icon('question-o'), help_page_path("integration/github") @@ -40,10 +38,7 @@ = render_if_exists 'admin/application_settings/ldap_access_setting', form: f .form-group - .form-check - = f.check_box :project_export_enabled, class: 'form-check-input' - = f.label :project_export_enabled, class: 'form-check-label' do - = _('Project export enabled') + = f.gitlab_ui_checkbox_component :project_export_enabled, s_('AdminSettings|Project export enabled') .form-group %label.label-bold= _('Enabled Git access protocols') @@ -65,9 +60,6 @@ .form-group %label.label-bold= s_('AdminSettings|Feed token') - .form-check - = f.check_box :disable_feed_token, class: 'form-check-input' - = f.label :disable_feed_token, class: 'form-check-label' do - = s_('AdminSettings|Disable feed token') + = f.gitlab_ui_checkbox_component :disable_feed_token, s_('AdminSettings|Disable feed token') = f.submit _('Save changes'), class: "gl-button btn btn-confirm" diff --git a/app/views/projects/issues/_form.html.haml b/app/views/projects/issues/_form.html.haml index 7bfdaac72c4..11741059ee5 100644 --- a/app/views/projects/issues/_form.html.haml +++ b/app/views/projects/issues/_form.html.haml @@ -1,3 +1,3 @@ -= form_for [@project, @issue], += gitlab_ui_form_for [@project, @issue], html: { class: 'issue-form common-note-form gl-mt-3 js-quick-submit gl-show-field-errors', data: issues_form_data(@project) } do |f| = render 'shared/issuable/form', f: f, issuable: @issue diff --git a/app/views/projects/merge_requests/_form.html.haml b/app/views/projects/merge_requests/_form.html.haml index a68a4318538..5f1c72156eb 100644 --- a/app/views/projects/merge_requests/_form.html.haml +++ b/app/views/projects/merge_requests/_form.html.haml @@ -1,3 +1,3 @@ -= form_for [@project, @merge_request], += gitlab_ui_form_for [@project, @merge_request], html: { class: 'merge-request-form common-note-form js-requires-input js-quick-submit' } do |f| = render 'shared/issuable/form', f: f, issuable: @merge_request, presenter: @mr_presenter diff --git a/app/views/projects/merge_requests/creations/_new_submit.html.haml b/app/views/projects/merge_requests/creations/_new_submit.html.haml index 253f50d5090..ef6e930bf23 100644 --- a/app/views/projects/merge_requests/creations/_new_submit.html.haml +++ b/app/views/projects/merge_requests/creations/_new_submit.html.haml @@ -1,6 +1,6 @@ %h3.page-title = _('New merge request') -= form_for [@project, @merge_request], html: { class: 'merge-request-form common-note-form js-requires-input js-quick-submit' } do |f| += gitlab_ui_form_for [@project, @merge_request], html: { class: 'merge-request-form common-note-form js-requires-input js-quick-submit' } do |f| = render 'shared/issuable/form', f: f, issuable: @merge_request, commits: @commits, presenter: @mr_presenter = f.hidden_field :source_project_id = f.hidden_field :source_branch diff --git a/app/views/shared/issuable/form/_contribution.html.haml b/app/views/shared/issuable/form/_contribution.html.haml index dc6abfd2c9e..47766008c9a 100644 --- a/app/views/shared/issuable/form/_contribution.html.haml +++ b/app/views/shared/issuable/form/_contribution.html.haml @@ -1,5 +1,7 @@ - issuable = local_assigns.fetch(:issuable) - form = local_assigns.fetch(:form) +- contribution_help_link = help_page_path('user/project/merge_requests/allow_collaboration') +- contribution_help_link_start = ''.html_safe % { url: contribution_help_link } - return unless issuable.is_a?(MergeRequest) - return unless issuable.for_fork? @@ -11,10 +13,7 @@ %label.col-form-label.col-sm-2 = _('Contribution') .col-sm-10 - .form-check.gl-mt-2 - = form.check_box :allow_collaboration, disabled: !issuable.can_allow_collaboration?(current_user), class: 'form-check-input' - = form.label :allow_collaboration, class: 'form-check-label' do - = _('Allow commits from members who can merge to the target branch.') - = link_to 'About this feature', help_page_path('user/project/merge_requests/allow_collaboration'), target: '_blank', rel: 'noopener noreferrer nofollow' - .form-text.text-muted - = allow_collaboration_unavailable_reason(issuable) + = form.gitlab_ui_checkbox_component :allow_collaboration, + _('Allow commits from members who can merge to the target branch. %{link_start}About this feature.%{link_end}').html_safe % { link_start: contribution_help_link_start, link_end: ''.html_safe }, + checkbox_options: { disabled: !issuable.can_allow_collaboration?(current_user) }, + help_text: allow_collaboration_unavailable_reason(issuable) diff --git a/app/views/shared/issuable/form/_metadata.html.haml b/app/views/shared/issuable/form/_metadata.html.haml index 34720576526..e941eaadbc9 100644 --- a/app/views/shared/issuable/form/_metadata.html.haml +++ b/app/views/shared/issuable/form/_metadata.html.haml @@ -17,10 +17,8 @@ - if issuable.respond_to?(:confidential) && can?(current_user, :set_confidentiality, issuable) .form-group.row .offset-sm-2.col-sm-10 - .form-check - = form.check_box :confidential, class: 'form-check-input' - = form.label :confidential, class: 'form-check-label' do - #{_('This issue is confidential and should only be visible to team members with at least Reporter access.')} + = form.gitlab_ui_checkbox_component :confidential, + _('This issue is confidential and should only be visible to team members with at least Reporter access.') - if can?(current_user, :"set_#{issuable.to_ability_name}_metadata", issuable) %hr diff --git a/config/feature_flags/development/env_last_deployment_by_finished_at.yml b/config/feature_flags/development/env_last_deployment_by_finished_at.yml index 0fac852cd97..36163b167d0 100644 --- a/config/feature_flags/development/env_last_deployment_by_finished_at.yml +++ b/config/feature_flags/development/env_last_deployment_by_finished_at.yml @@ -5,4 +5,4 @@ rollout_issue_url: https://gitlab.com/gitlab-org/gitlab/-/issues/357299 milestone: '14.10' type: development group: group::release -default_enabled: false +default_enabled: true diff --git a/db/post_migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb b/db/migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb similarity index 100% rename from db/post_migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb rename to db/migrate/20220401110511_add_runtime_data_columns_to_vsa_aggregations.rb diff --git a/db/post_migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb b/db/migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb similarity index 100% rename from db/post_migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb rename to db/migrate/20220401113123_add_check_constraint_to_vsa_aggregation_runtime_data_columns.rb diff --git a/lib/gitlab/data_builder/deployment.rb b/lib/gitlab/data_builder/deployment.rb index f77a6339eee..0e6841e10a7 100644 --- a/lib/gitlab/data_builder/deployment.rb +++ b/lib/gitlab/data_builder/deployment.rb @@ -17,6 +17,11 @@ module Gitlab Gitlab::UrlBuilder.build(commit) end + user_url = + if deployment.deployed_by + Gitlab::UrlBuilder.build(deployment.deployed_by) + end + { object_kind: 'deployment', status: deployment.status, @@ -27,8 +32,8 @@ module Gitlab environment: deployment.environment.name, project: deployment.project.hook_attrs, short_sha: deployment.short_sha, - user: deployment.deployed_by.hook_attrs, - user_url: Gitlab::UrlBuilder.build(deployment.deployed_by), + user: deployment.deployed_by&.hook_attrs, + user_url: user_url, commit_url: commit_url, commit_title: deployment.commit_title, ref: deployment.ref diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 4658384cd1a..f6473d46840 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -2700,6 +2700,9 @@ msgstr "" msgid "AdminSettings|Preview payload" msgstr "" +msgid "AdminSettings|Project export enabled" +msgstr "" + msgid "AdminSettings|Protect CI/CD variables by default" msgstr "" @@ -3672,7 +3675,7 @@ msgstr "" msgid "Allow access to the following IP addresses" msgstr "" -msgid "Allow commits from members who can merge to the target branch." +msgid "Allow commits from members who can merge to the target branch. %{link_start}About this feature.%{link_end}" msgstr "" msgid "Allow group owners to manage LDAP-related settings" @@ -29143,9 +29146,6 @@ msgstr "" msgid "Project export download requests" msgstr "" -msgid "Project export enabled" -msgstr "" - msgid "Project export has been deleted." msgstr "" diff --git a/qa/qa/page/dashboard/todos.rb b/qa/qa/page/dashboard/todos.rb index d8baadcf73d..d5660823118 100644 --- a/qa/qa/page/dashboard/todos.rb +++ b/qa/qa/page/dashboard/todos.rb @@ -17,7 +17,11 @@ module QA end def has_todo_list? - has_element? :todo_item_container + has_element?(:todo_item_container) + end + + def has_no_todo_list? + has_no_element?(:todo_item_container) end def has_latest_todo_item_with_content?(action, title) diff --git a/qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb b/qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb new file mode 100644 index 00000000000..9d1a37cb0b8 --- /dev/null +++ b/qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb @@ -0,0 +1,88 @@ +# frozen_string_literal: true + +module QA + RSpec.shared_context 'merge train spec with user prep' do + let(:executor) { "qa-runner-#{Faker::Alphanumeric.alphanumeric(number: 8)}" } + let(:file_name) { Faker::Lorem.word } + let(:mr_title) { Faker::Lorem.sentence } + let(:admin_api_client) { Runtime::API::Client.as_admin } + + let(:user) do + Resource::User.fabricate_via_api! do |user| + user.api_client = admin_api_client + end + end + + let(:project) do + Resource::Project.fabricate_via_api! do |project| + project.name = 'pipeline-for-merge-trains' + end + end + + let!(:runner) do + Resource::Runner.fabricate! do |runner| + runner.project = project + runner.name = executor + runner.tags = [executor] + end + end + + let!(:project_files) do + Resource::Repository::Commit.fabricate_via_api! do |commit| + commit.project = project + commit.commit_message = 'Add .gitlab-ci.yml' + commit.add_files( + [ + { + file_path: '.gitlab-ci.yml', + content: <<~YAML + test_merge_train: + tags: + - #{executor} + script: + - sleep 10 + - echo 'OK!' + only: + - merge_requests + YAML + }, + { + file_path: file_name, + content: Faker::Lorem.sentence + } + ] + ) + end + end + + before do + project.add_member(user, Resource::Members::AccessLevel::MAINTAINER) + + Flow::Login.sign_in + project.visit! + Flow::MergeRequest.enable_merge_trains + + Flow::Login.sign_in(as: user) + + Resource::MergeRequest.fabricate_via_api! do |merge_request| + merge_request.title = mr_title + merge_request.project = project + merge_request.description = Faker::Lorem.sentence + merge_request.target_new_branch = false + merge_request.update_existing_file = true + merge_request.file_name = file_name + merge_request.file_content = Faker::Lorem.sentence + end.visit! + + Page::MergeRequest::Show.perform do |show| + show.has_pipeline_status?('passed') + show.try_to_merge! + end + end + + after do + runner&.remove_via_api! + user&.remove_via_api! + end + end +end diff --git a/spec/features/admin/admin_settings_spec.rb b/spec/features/admin/admin_settings_spec.rb index 35fe58517d0..85e8bd747ff 100644 --- a/spec/features/admin/admin_settings_spec.rb +++ b/spec/features/admin/admin_settings_spec.rb @@ -34,16 +34,16 @@ RSpec.describe 'Admin updates settings' do it 'uncheck all restricted visibility levels' do page.within('.as-visibility-access') do - find('#application_setting_visibility_level_0').set(false) - find('#application_setting_visibility_level_10').set(false) - find('#application_setting_visibility_level_20').set(false) + find('#application_setting_restricted_visibility_levels_0').set(false) + find('#application_setting_restricted_visibility_levels_10').set(false) + find('#application_setting_restricted_visibility_levels_20').set(false) click_button 'Save changes' end expect(page).to have_content "Application settings saved successfully" - expect(find('#application_setting_visibility_level_0')).not_to be_checked - expect(find('#application_setting_visibility_level_10')).not_to be_checked - expect(find('#application_setting_visibility_level_20')).not_to be_checked + expect(find('#application_setting_restricted_visibility_levels_0')).not_to be_checked + expect(find('#application_setting_restricted_visibility_levels_10')).not_to be_checked + expect(find('#application_setting_restricted_visibility_levels_20')).not_to be_checked end it 'modify import sources' do diff --git a/spec/lib/gitlab/data_builder/deployment_spec.rb b/spec/lib/gitlab/data_builder/deployment_spec.rb index e64e6ace6b4..e8fe80f75cb 100644 --- a/spec/lib/gitlab/data_builder/deployment_spec.rb +++ b/spec/lib/gitlab/data_builder/deployment_spec.rb @@ -57,13 +57,31 @@ RSpec.describe Gitlab::DataBuilder::Deployment do project.repository.remove end - it 'does not include commit_url' do + it 'returns nil for commit_url' do expect(data[:commit_url]).to be_nil end - it 'does not include commit_title' do + it 'returns nil for commit_title' do expect(data[:commit_title]).to be_nil end end + + context 'when deployed_by is nil' do + let_it_be(:deployment) { create(:deployment, user: nil, deployable: nil) } + + subject(:data) { described_class.build(deployment, Time.current) } + + before(:all) do + deployment.user = nil + end + + it 'returns nil for user' do + expect(data[:user]).to be_nil + end + + it 'returns nil for user_url' do + expect(data[:user_url]).to be_nil + end + end end end