2018-08-10 06:45:01 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-03-28 13:17:42 +00:00
|
|
|
class ProtectedBranch::PushAccessLevel < ApplicationRecord
|
2016-08-16 05:09:13 +00:00
|
|
|
include ProtectedBranchAccess
|
2020-11-13 15:09:24 +00:00
|
|
|
|
|
|
|
belongs_to :deploy_key
|
|
|
|
|
|
|
|
validates :access_level, uniqueness: { scope: :protected_branch_id, if: :role?,
|
|
|
|
conditions: -> { where(user_id: nil, group_id: nil, deploy_key_id: nil) } }
|
|
|
|
validates :deploy_key_id, uniqueness: { scope: :protected_branch_id, allow_nil: true }
|
|
|
|
validate :validate_deploy_key_membership
|
|
|
|
|
|
|
|
def type
|
|
|
|
if self.deploy_key.present?
|
|
|
|
:deploy_key
|
|
|
|
else
|
|
|
|
super
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def validate_deploy_key_membership
|
|
|
|
return unless deploy_key
|
|
|
|
|
|
|
|
unless project.deploy_keys_projects.where(deploy_key: deploy_key).exists?
|
|
|
|
self.errors.add(:deploy_key, 'is not enabled for this project')
|
|
|
|
end
|
|
|
|
end
|
2016-07-05 07:40:42 +00:00
|
|
|
end
|