BigW Consortium Gitlab

deploy_key.rb 770 Bytes
Newer Older
1 2 3
class DeployKey < Key
  has_many :deploy_keys_projects, dependent: :destroy
  has_many :projects, through: :deploy_keys_projects
4 5

  scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) }
6 7 8 9 10
  scope :are_public,  -> { where(public: true) }

  def private?
    !public?
  end
Douwe Maan committed
11 12 13 14 15 16 17 18 19 20 21 22

  def orphaned?
    self.deploy_keys_projects.length == 0
  end

  def almost_orphaned?
    self.deploy_keys_projects.length == 1
  end

  def destroyed_when_orphaned?
    self.private?
  end
23

24 25 26 27
  def has_access_to?(project)
    projects.include?(project)
  end

28
  def can_push_to?(project)
29
    can_push? && has_access_to?(project)
30
  end
31 32 33 34 35 36

  private

  # we don't want to notify the user for deploy keys
  def notify_user
  end
37
end