BigW Consortium Gitlab

lfs_object.rb 704 Bytes
Newer Older
1 2 3 4 5 6 7
class LfsObject < ActiveRecord::Base
  has_many :lfs_objects_projects, dependent: :destroy
  has_many :projects, through: :lfs_objects_projects

  validates :oid, presence: true, uniqueness: true

  mount_uploader :file, LfsObjectUploader
8 9 10

  def storage_project(project)
    if project && project.forked?
11
      storage_project(project.forked_from_project)
12 13 14 15
    else
      project
    end
  end
16 17 18 19

  def project_allowed_access?(project)
    projects.exists?(storage_project(project).id)
  end
20 21 22 23 24 25

  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
26
end