debian-mirror-gitlab/app/models/deploy_keys_project.rb

25 lines
795 B
Ruby
Raw Normal View History

2014-09-02 18:07:02 +05:30
class DeployKeysProject < ActiveRecord::Base
belongs_to :project
2018-03-17 18:26:18 +05:30
belongs_to :deploy_key, inverse_of: :deploy_keys_projects
2014-09-02 18:07:02 +05:30
2018-03-17 18:26:18 +05:30
scope :without_project_deleted, -> { joins(:project).where(projects: { pending_delete: false }) }
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