demarches-normaliennes/app/models/cerfa.rb

32 lines
683 B
Ruby
Raw Normal View History

2015-08-18 13:52:00 +02:00
class Cerfa < ActiveRecord::Base
belongs_to :dossier, touch: true
belongs_to :user
2015-08-18 13:52:00 +02:00
mount_uploader :content, CerfaUploader
2016-11-25 12:07:01 +01:00
validates :content, :file_size => {:maximum => 20.megabytes}
2015-08-18 16:30:57 +02:00
2018-01-11 19:08:04 +01:00
after_save :internal_notification, if: Proc.new { dossier.present? }
2016-12-26 11:33:12 +01:00
2015-08-18 16:30:57 +02:00
def empty?
content.blank?
end
def content_url
2018-01-11 19:04:39 +01:00
if content.url.present?
2016-05-18 11:43:32 +02:00
if Features.remote_storage
(RemoteDownloader.new content.filename).url
else
2016-05-24 18:35:25 +02:00
(LocalDownloader.new content.path, 'CERFA').url
end
end
end
2016-12-26 11:33:12 +01:00
private
def internal_notification
2018-01-11 19:04:39 +01:00
if dossier.state != 'brouillon'
NotificationService.new('cerfa', self.dossier.id).notify
end
2016-12-26 11:33:12 +01:00
end
2017-04-04 15:27:04 +02:00
end