diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 06:06:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-06-20 06:06:58 +0300 |
commit | accf0d7db3d58a62212125703df39e341d327ec6 (patch) | |
tree | 7ea5e828e0350f9ecd3fd9c8d6daee02849ab2ef /app | |
parent | d7511e6d2f947dbae4b19947b746fdabb0897d92 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app')
-rw-r--r-- | app/services/merge_requests/mergeability_check_batch_service.rb | 20 | ||||
-rw-r--r-- | app/workers/merge_requests/mergeability_check_batch_worker.rb | 15 |
2 files changed, 34 insertions, 1 deletions
diff --git a/app/services/merge_requests/mergeability_check_batch_service.rb b/app/services/merge_requests/mergeability_check_batch_service.rb new file mode 100644 index 00000000000..7697b596a83 --- /dev/null +++ b/app/services/merge_requests/mergeability_check_batch_service.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +module MergeRequests + class MergeabilityCheckBatchService + def initialize(merge_requests, user) + @merge_requests = merge_requests + @user = user + end + + def execute + return unless merge_requests.present? + + MergeRequests::MergeabilityCheckBatchWorker.perform_async(merge_requests.map(&:id), user&.id) + end + + private + + attr_reader :merge_requests, :user + end +end diff --git a/app/workers/merge_requests/mergeability_check_batch_worker.rb b/app/workers/merge_requests/mergeability_check_batch_worker.rb index cbe34ac3790..f48e9c234ab 100644 --- a/app/workers/merge_requests/mergeability_check_batch_worker.rb +++ b/app/workers/merge_requests/mergeability_check_batch_worker.rb @@ -15,10 +15,16 @@ module MergeRequests @logger ||= Sidekiq.logger end - def perform(merge_request_ids) + def perform(merge_request_ids, user_id) merge_requests = MergeRequest.id_in(merge_request_ids) + user = User.find_by_id(user_id) merge_requests.each do |merge_request| + # Skip projects that user doesn't have update_merge_request access + next if merge_status_recheck_not_allowed?(merge_request, user) + + merge_request.mark_as_checking + result = merge_request.check_mergeability next unless result&.error? @@ -30,5 +36,12 @@ module MergeRequests ) end end + + private + + def merge_status_recheck_not_allowed?(merge_request, user) + ::Feature.enabled?(:restrict_merge_status_recheck, merge_request.project) && + !Ability.allowed?(user, :update_merge_request, merge_request.project) + end end end |