Welcome to mirror list, hosted at ThFree Co, Russian Federation.

approval_removal_settings.rb « merge_request « models « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b07242e257829689e08f2448fe2748bca1f97d85 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# frozen_string_literal: true

class MergeRequest::ApprovalRemovalSettings # rubocop:disable Style/ClassAndModuleChildren
  include ActiveModel::Validations

  attr_accessor :project

  validate :mutually_exclusive_settings

  def initialize(project, reset_approvals_on_push, selective_code_owner_removals)
    @project = project
    @reset_approvals_on_push = reset_approvals_on_push
    @selective_code_owner_removals = selective_code_owner_removals
  end

  private

  def selective_code_owner_removals
    if @selective_code_owner_removals.nil?
      project.project_setting.selective_code_owner_removals
    else
      @selective_code_owner_removals
    end
  end

  def reset_approvals_on_push
    if @reset_approvals_on_push.nil?
      project.reset_approvals_on_push
    else
      @reset_approvals_on_push
    end
  end

  def mutually_exclusive_settings
    return unless selective_code_owner_removals && reset_approvals_on_push

    errors.add(:base, 'selective_code_owner_removals can only be enabled when reset_approvals_on_push is disabled')
  end
end