Skip to content
Snippets Groups Projects
Commit ecd2dc31 authored by Gyan Gupta's avatar Gyan Gupta
Browse files

Added restriction in uploading file

parent 15c541d9
Branches fix/add_restriction_for_upload_file
Tags
1 merge request!239Added restriction in uploading file
Pipeline #11736 failed
......@@ -15,7 +15,9 @@ module Hyrax
belongs_to :user, class_name: '::User'
before_create :set_characterization_data
##
validate :uploaded_file_name, on: :create
##
# Associate a {FileSet} with this uploaded file.
#
# @param [Hyrax::Resource, ActiveFedora::Base] file_set
......@@ -44,5 +46,15 @@ module Hyrax
self.characterization_data[:file_size] = file.size
self.characterization_data[:original_checksum] = Digest::SHA1.file(file.path).to_s
end
def uploaded_file_name
parsed_file = YAML.load_file(Rails.root.join('config', 'restricted_files.yml'))
file_name = file.file.original_filename
if parsed_file['restricted_file_names'].include?(file_name.gsub(/[\s_\-]/, '').downcase) || file_name.start_with?('.')
errors.add(:base, "This file name is restricted.")
end
end
end
end
\ No newline at end of file
restricted_file_names:
- metadata.json
- meta.json
- .DS_Store
- desktop.ini
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment