Skip to content
Snippets Groups Projects
Commit 0931e1e0 authored by Mauricio Giacomini Girardello's avatar Mauricio Giacomini Girardello
Browse files

Merge branch 'feature-mimetypes-validation-on-upload' into 'master'

Feature mimetypes validation on upload



See merge request !209
parents a598e7a6 b3b44f0b
No related branches found
No related tags found
No related merge requests found
......@@ -7,19 +7,26 @@ class ChunksController < ApplicationController
def show
chunk = resumable_chunk chunk_number
if File.exists?(chunk)
post_file_and_create_thumbnail @learning_object, resumable_filename if last_chunk?
#Let resumable.js know this chunk already exists
render :nothing => true, :status => 200
unless valid_mime_type?
render :nothing => true, :status => 415
else
#Let resumable.js know this chunk doesnt exists and needs to be uploaded
render :nothing => true, :status => 404
if File.exists?(chunk)
post_file_and_create_thumbnail @learning_object, resumable_filename if last_chunk?
#Let resumable.js know this chunk already exists
render :nothing => true, :status => 200
else
#Let resumable.js know this chunk doesnt exists and needs to be uploaded
render :nothing => true, :status => 404
end
end
end
#POST /chunk
def create
unless valid_mime_type?
return render :nothing => true, :status => 415
end
#chunk path based on the parameters
chunk = resumable_chunk chunk_number
......@@ -101,6 +108,13 @@ class ChunksController < ApplicationController
@learning_object = LearningObject.find chunks_params[:learning_object_id]
end
def resumable_file_extension
File.extname(chunks_params[:resumableFilename])[1..-1]
end
def valid_mime_type?
@learning_object.object_type.mime_types.map(&:extension).include? resumable_file_extension
end
# Never trust parameters from the scary internet, only allow the white list through.
def chunks_params
params.permit(:file, :learning_object_id, :resumableIdentifier, :resumableFilename, :resumableChunkNumber, :resumableTotalChunks, :resumableChunkSize)
......
module LearningObjects::BuilderHelper
def get_mime_types learning_object
@learning_object.object_type.mime_types.map(&:extension)
end
end
\ No newline at end of file
......@@ -161,7 +161,7 @@
maxFiles: 3,
simultaneousUploads: 4,
chunkSize: 1024 * 256,
fileType: []
fileType: <%= raw(get_mime_types @learning_object) %>
});
var results = $('#results'),
......
......@@ -13,7 +13,11 @@
<fieldset>
<label class="ls-label col-md-6">
<b class="ls-label-text">Extensões</b>
<b class="ls-label-text">Extensões&nbsp
<a style="text-decoration: none;" href="#" data-toggle="popover" title="Informação" data-trigger="hover" data-content="Inclua somente a extensão. Exemplo: 'jpg' e não '.jpg'">
<i class="ls-ico-info"></i>
</a>
</b>
<p>Digite o nome do tipo</p>
<%= f.text_field :extension, {required: true} %>
......@@ -31,3 +35,8 @@
<%= link_to "Cancelar", management_mime_types_path,class: "ls-btn-danger"%>
</div>
<% end %>
<script>
$(document).ready(function(){
$('[data-toggle="popover"]').popover();
});
</script>
......@@ -3,7 +3,7 @@
<table class="ls-table">
<thead>
<tr>
<th>Nome</th>
<th>Extensão</th>
<th>MimeType</th>
<th></th>
<th></th>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment