Refactor create_wopi_file

This commit is contained in:
Jure Grabnar 2019-03-21 08:47:52 +01:00
parent 56bb62c5b0
commit d60cc2cd1c
2 changed files with 12 additions and 41 deletions

View file

@ -42,16 +42,11 @@ function initCreateWopiFileModal() {
}); });
} }
// I couldn't make this work through CSS
function applyImageChangeOnButtons() { function applyImageChangeOnButtons() {
var resetToInActive = function(modal) {
modal.find('img.act').hide();
modal.find('img.inactive').show();
};
var modal = $('#new-office-file-modal'); var modal = $('#new-office-file-modal');
modal.find('.btn-group label').off().click(function() { modal.find('.btn-group label').off().click(function() {
resetToInActive(modal); modal.find('img.act').hide();
modal.find('img.inactive').show();
$(this).find('img.act').show(); $(this).find('img.act').show();
$(this).find('img.inactive').hide(); $(this).find('img.inactive').hide();

View file

@ -176,18 +176,7 @@ class AssetsController < ApplicationController
# POST: create_wopi_file_path # POST: create_wopi_file_path
def create_wopi_file def create_wopi_file
# Presence validation # Presence validation
create_wopi_params params.require(%i(element_type element_id file_type))
unless params[:file_name].present?
respond_to do |format|
format.json do
render json: {
error: true,
message: { file: [t('general.text.not_blank')] }
}, status: 400
end
end and return
end
# File type validation # File type validation
render_403 && return unless %w(docx xlsx pptx).include?(params[:file_type]) render_403 && return unless %w(docx xlsx pptx).include?(params[:file_type])
@ -198,15 +187,10 @@ class AssetsController < ApplicationController
file.content_type = wopi_content_type(params[:file_type]) file.content_type = wopi_content_type(params[:file_type])
asset = Asset.new(file: file, created_by: current_user, file_present: true) asset = Asset.new(file: file, created_by: current_user, file_present: true)
unless asset.valid? unless asset.valid?(:wopi_file_creation)
respond_to do |format| render json: {
format.json do message: asset.errors
render json: { }, status: 400 and return
error: true,
message: asset.errors
}, status: 400
end
end and return
end end
# Create file depending on the type # Create file depending on the type
@ -229,18 +213,14 @@ class AssetsController < ApplicationController
edit_url = edit_asset_url(result_asset.asset_id) edit_url = edit_asset_url(result_asset.asset_id)
else else
render_404 render_404 and return
end end
# Return edit url # Return edit url
respond_to do |format| render json: {
format.json do success: true,
render json: { edit_url: edit_url
success: true, }, status: :ok
edit_url: edit_url
}
end
end
end end
private private
@ -296,10 +276,6 @@ class AssetsController < ApplicationController
url + wd_params url + wd_params
end end
def create_wopi_params
params.require(%i(element_type element_id file_type))
end
def asset_params def asset_params
params.permit( params.permit(
:file :file