2018-11-18 11:00:15 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
class DeployKeysProject < ApplicationRecord
|
2019-10-12 21:52:04 +05:30
|
|
|
belongs_to :project, inverse_of: :deploy_keys_projects
|
2018-03-17 18:26:18 +05:30
|
|
|
belongs_to :deploy_key, inverse_of: :deploy_keys_projects
|
|
|
|
scope :in_project, ->(project) { where(project: project) }
|
|
|
|
scope :with_write_access, -> { where(can_push: true) }
|
|
|
|
|
|
|
|
accepts_nested_attributes_for :deploy_key
|
|
|
|
|
|
|
|
validates :deploy_key, presence: true
|
2014-09-02 18:07:02 +05:30
|
|
|
validates :deploy_key_id, uniqueness: { scope: [:project_id], message: "already exists in project" }
|
|
|
|
validates :project_id, presence: true
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
after_destroy :destroy_orphaned_deploy_key
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def destroy_orphaned_deploy_key
|
|
|
|
return unless self.deploy_key.destroyed_when_orphaned? && self.deploy_key.orphaned?
|
2018-03-17 18:26:18 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
self.deploy_key.destroy
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|