2013-05-06 05:26:36 -04:00
|
|
|
class DeployKey < Key
|
2017-06-08 11:16:27 -04:00
|
|
|
has_many :deploy_keys_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2013-05-06 05:26:36 -04:00
|
|
|
has_many :projects, through: :deploy_keys_projects
|
2013-05-06 08:10:55 -04:00
|
|
|
|
|
|
|
scope :in_projects, ->(projects) { joins(:deploy_keys_projects).where('deploy_keys_projects.project_id in (?)', projects) }
|
2015-03-27 09:43:48 -04:00
|
|
|
scope :are_public, -> { where(public: true) }
|
|
|
|
|
|
|
|
def private?
|
|
|
|
!public?
|
|
|
|
end
|
2015-04-03 06:22:44 -04:00
|
|
|
|
|
|
|
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
|
2016-11-11 08:44:33 -05:00
|
|
|
|
2016-11-16 07:31:08 -05:00
|
|
|
def has_access_to?(project)
|
|
|
|
projects.include?(project)
|
|
|
|
end
|
|
|
|
|
2016-11-11 08:44:33 -05:00
|
|
|
def can_push_to?(project)
|
2016-11-16 07:31:08 -05:00
|
|
|
can_push? && has_access_to?(project)
|
2016-11-11 08:44:33 -05:00
|
|
|
end
|
2016-11-17 12:23:04 -05:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
# we don't want to notify the user for deploy keys
|
|
|
|
def notify_user
|
|
|
|
end
|
2013-05-06 05:26:36 -04:00
|
|
|
end
|