Project

General

Profile

Feature #20008 » attachment.rb.patch

actual file blocking - madhusudan kh, 2015-06-09 14:51

View differences:

attachment.rb 2015-06-09 16:13:29.721406673 +0530
validates_length_of :filename, :maximum => 255
validates_length_of :disk_filename, :maximum => 255
validates_length_of :description, :maximum => 255
validate :validate_max_file_size
validate :validate_max_file_size, :validate_invalid_file_types
#validate :validate_max_file_size
acts_as_event :title => :filename,
:url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
......
end
end
# madhu code begin
def validate_invalid_file_types
allowed_type = ['.txt','.csv','.htm','.html','.xml','.css','.doc','.docx','.xls','.xlsx','.rtf','.ppt','.pptx','.pdf','.swf','.flv','.avi','.wmv','.mov','.jpg','.jpeg','.gif','.png']
a_type=['.txt','.pdf']
filename = self.filename
ext = File.extname(filename)
if allowed_type.include?(ext)
puts "#{ext} is valid type"
else
#puts "#{ext} is not a valid type"
errors.add(:base, l(:error_invalid_file_extension))
end
end
#madhu code ends
def file=(incoming_file)
unless incoming_file.nil?
@temp_file = incoming_file
(1-1/4)