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
26 26
  validates_length_of :filename, :maximum => 255
27 27
  validates_length_of :disk_filename, :maximum => 255
28 28
  validates_length_of :description, :maximum => 255
29
  validate :validate_max_file_size
29
validate :validate_max_file_size, :validate_invalid_file_types
30
#validate :validate_max_file_size
30 31

  
31 32
  acts_as_event :title => :filename,
32 33
                :url => Proc.new {|o| {:controller => 'attachments', :action => 'download', :id => o.id, :filename => o.filename}}
......
68 69
    end
69 70
  end
70 71

  
72
# madhu code begin
73

  
74
 def validate_invalid_file_types
75

  
76
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']
77
a_type=['.txt','.pdf']
78
filename = self.filename
79
ext = File.extname(filename) 
80
if allowed_type.include?(ext)
81
puts "#{ext} is valid type"
82
else
83
#puts "#{ext} is not a valid type"
84
errors.add(:base, l(:error_invalid_file_extension))
85
end
86
end
87

  
88
#madhu code ends
89

  
71 90
  def file=(incoming_file)
72 91
    unless incoming_file.nil?
73 92
      @temp_file = incoming_file
(1-1/4)