2015-10-12 10:42:14 -04:00
|
|
|
class LfsObject < ActiveRecord::Base
|
2017-06-08 11:16:27 -04:00
|
|
|
has_many :lfs_objects_projects, dependent: :destroy # rubocop:disable Cop/ActiveRecordDependent
|
2015-10-12 10:42:14 -04:00
|
|
|
has_many :projects, through: :lfs_objects_projects
|
|
|
|
|
|
|
|
validates :oid, presence: true, uniqueness: true
|
|
|
|
|
|
|
|
mount_uploader :file, LfsObjectUploader
|
2015-12-03 08:59:10 -05:00
|
|
|
|
2015-12-07 09:03:50 -05:00
|
|
|
def project_allowed_access?(project)
|
2017-11-08 07:59:48 -05:00
|
|
|
projects.exists?(project.lfs_storage_project.id)
|
2015-12-07 09:03:50 -05:00
|
|
|
end
|
2016-10-28 13:39:20 -04:00
|
|
|
|
|
|
|
def self.destroy_unreferenced
|
|
|
|
joins("LEFT JOIN lfs_objects_projects ON lfs_objects_projects.lfs_object_id = #{table_name}.id")
|
|
|
|
.where(lfs_objects_projects: { id: nil })
|
|
|
|
.destroy_all
|
|
|
|
end
|
2015-10-12 10:42:14 -04:00
|
|
|
end
|