33 lines
1018 B
Ruby
33 lines
1018 B
Ruby
module JamRuby
|
|
|
|
# describes what users have rights to which tracks
|
|
class JamTrackRight < ActiveRecord::Base
|
|
attr_accessible :user, :jam_track, :user_id, :jam_track_id, :url, :md5, :length, :download_count
|
|
belongs_to :user, class_name: "JamRuby::User" # the owner, or purchaser of the jam_track
|
|
belongs_to :jam_track, class_name: "JamRuby::JamTrack"
|
|
|
|
validates :user, presence:true
|
|
validates :jam_track, presence:true
|
|
validate :verify_download_count
|
|
|
|
validates_uniqueness_of :user_id, scope: :jam_track_id
|
|
|
|
# Uploads the JKZ:
|
|
mount_uploader :url, JamTrackRightUploader
|
|
|
|
MAX_JAM_TRACK_DOWNLOADS = 1000
|
|
|
|
def verify_download_count
|
|
if (self.download_count < 0 || self.download_count > MAX_JAM_TRACK_DOWNLOADS) && !@current_user.admin
|
|
errors.add(:download_count, "must be less than or equal to #{MAX_JAM_TRACK_DOWNLOADS}")
|
|
end
|
|
end
|
|
|
|
# Create user-specific JKZ for the associated jam_track:
|
|
def create_jkz
|
|
|
|
end
|
|
|
|
end
|
|
end
|