diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-10 06:07:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-10 06:07:25 +0300 |
commit | 4a6dacc8662ed65c0b83a3715e4eb05a78168db1 (patch) | |
tree | 04aced9d7d60c1213db9d5152158afe02126599f /app/services | |
parent | 070ac34d473978dc27ea2878ed1cf17865e24e9a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services')
-rw-r--r-- | app/services/environments/stop_stale_service.rb | 24 | ||||
-rw-r--r-- | app/services/error_tracking/list_projects_service.rb | 16 | ||||
-rw-r--r-- | app/services/groups/import_export/export_service.rb | 14 | ||||
-rw-r--r-- | app/services/groups/import_export/import_service.rb | 34 | ||||
-rw-r--r-- | app/services/users/update_service.rb | 8 |
5 files changed, 60 insertions, 36 deletions
diff --git a/app/services/environments/stop_stale_service.rb b/app/services/environments/stop_stale_service.rb new file mode 100644 index 00000000000..b2f1d74365a --- /dev/null +++ b/app/services/environments/stop_stale_service.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +module Environments + class StopStaleService < BaseService + def execute + return ServiceResponse.error(message: 'Before date must be provided') unless params[:before].present? + + return ServiceResponse.error(message: 'Unauthorized') unless can?(current_user, :stop_environment, project) + + Environment.available + .deployed_and_updated_before(project.id, params[:before]) + .without_protected(project) + .in_batches(of: 100) do |env_batch| # rubocop:disable Cop/InBatches + Environments::AutoStopWorker.bulk_perform_async_with_contexts( + env_batch, + arguments_proc: ->(environment) { environment.id }, + context_proc: ->(environment) { { project: project } } + ) + end + + ServiceResponse.success(message: 'Successfully scheduled stale environments to stop') + end + end +end diff --git a/app/services/error_tracking/list_projects_service.rb b/app/services/error_tracking/list_projects_service.rb index 2f23d47029c..d52306ef805 100644 --- a/app/services/error_tracking/list_projects_service.rb +++ b/app/services/error_tracking/list_projects_service.rb @@ -2,6 +2,8 @@ module ErrorTracking class ListProjectsService < ErrorTracking::BaseService + MASKED_TOKEN_REGEX = /\A\*+\z/.freeze + private def perform @@ -20,23 +22,31 @@ module ErrorTracking def project_error_tracking_setting (super || project.build_error_tracking_setting).tap do |setting| + url_changed = !setting.api_url&.start_with?(params[:api_host]) + setting.api_url = ErrorTracking::ProjectErrorTrackingSetting.build_api_url_from( api_host: params[:api_host], organization_slug: 'org', project_slug: 'proj' ) - setting.token = token(setting) + setting.token = token(setting, url_changed) setting.enabled = true end end strong_memoize_attr :project_error_tracking_setting - def token(setting) + def token(setting, url_changed) + return if url_changed && masked_token? + # Use param token if not masked, otherwise use database token - return params[:token] unless /\A\*+\z/.match?(params[:token]) + return params[:token] unless masked_token? setting.token end + + def masked_token? + MASKED_TOKEN_REGEX.match?(params[:token]) + end end end diff --git a/app/services/groups/import_export/export_service.rb b/app/services/groups/import_export/export_service.rb index bd54b48c5f4..2d88283661c 100644 --- a/app/services/groups/import_export/export_service.rb +++ b/app/services/groups/import_export/export_service.rb @@ -71,7 +71,7 @@ module Groups end def tree_exporter - tree_exporter_class.new( + Gitlab::ImportExport::Group::TreeSaver.new( group: group, current_user: current_user, shared: shared, @@ -79,18 +79,6 @@ module Groups ) end - def tree_exporter_class - if ndjson? - Gitlab::ImportExport::Group::TreeSaver - else - Gitlab::ImportExport::Group::LegacyTreeSaver - end - end - - def ndjson? - ::Feature.enabled?(:group_export_ndjson, group&.parent) - end - def version_saver Gitlab::ImportExport::VersionSaver.new(shared: shared) end diff --git a/app/services/groups/import_export/import_service.rb b/app/services/groups/import_export/import_service.rb index ac181245986..15948ab82a2 100644 --- a/app/services/groups/import_export/import_service.rb +++ b/app/services/groups/import_export/import_service.rb @@ -29,7 +29,7 @@ module Groups def execute Gitlab::Tracking.event(self.class.name, 'create', label: 'import_group_from_file') - if valid_user_permissions? && import_file && restorers.all?(&:restore) + if valid_user_permissions? && import_file && valid_import_file? && restorers.all?(&:restore) notify_success Gitlab::Tracking.event( @@ -75,25 +75,11 @@ module Groups def tree_restorer @tree_restorer ||= - if ndjson? - Gitlab::ImportExport::Group::TreeRestorer.new( - user: current_user, - shared: shared, - group: group - ) - else - Gitlab::ImportExport::Group::LegacyTreeRestorer.new( - user: current_user, - shared: shared, - group: group, - group_hash: nil - ) - end - end - - def ndjson? - ::Feature.enabled?(:group_import_ndjson, group&.parent) && - File.exist?(File.join(shared.export_path, 'tree/groups/_all.ndjson')) + Gitlab::ImportExport::Group::TreeRestorer.new( + user: current_user, + shared: shared, + group: group + ) end def remove_import_file @@ -115,6 +101,14 @@ module Groups end end + def valid_import_file? + return true if File.exist?(File.join(shared.export_path, 'tree/groups/_all.ndjson')) + + shared.error(::Gitlab::ImportExport::Error.incompatible_import_file_error) + + false + end + def notify_success @logger.info( group_id: group.id, diff --git a/app/services/users/update_service.rb b/app/services/users/update_service.rb index cb2711b6fee..96018db5974 100644 --- a/app/services/users/update_service.rb +++ b/app/services/users/update_service.rb @@ -31,6 +31,7 @@ module Users assign_identity build_canonical_email + reset_unconfirmed_email if @user.save(validate: validate) && update_status notify_success(user_exists) @@ -64,6 +65,13 @@ module Users Users::UpdateCanonicalEmailService.new(user: @user).execute end + def reset_unconfirmed_email + return unless @user.persisted? + return unless @user.email_changed? + + @user.update_column(:unconfirmed_email, nil) + end + def update_status return true unless @status_params |