BigW Consortium Gitlab

lfs_object.rb 761 Bytes
Newer Older
Stan Hu committed
1 2 3 4 5 6 7 8 9 10 11 12
# == Schema Information
#
# Table name: lfs_objects
#
#  id         :integer          not null, primary key
#  oid        :string(255)      not null
#  size       :integer          not null
#  created_at :datetime
#  updated_at :datetime
#  file       :string(255)
#

13 14 15 16 17 18 19
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
20 21 22

  def storage_project(project)
    if project && project.forked?
23
      storage_project(project.forked_from_project)
24 25 26 27
    else
      project
    end
  end
28 29 30 31

  def project_allowed_access?(project)
    projects.exists?(storage_project(project).id)
  end
32
end