Merge pull request #2004 from okriuchykhin/ok_SCI_3778

Fix new office file creation [SCI-3778]
This commit is contained in:
Alex Kriuchykhin 2019-09-04 15:40:34 +02:00 committed by GitHub
commit 59a85d8181
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 11 deletions

View file

@ -56,14 +56,15 @@ module Api
raise ActiveRecord::RecordInvalid,
I18n.t('api.core.errors.result_wrong_tinymce.detail')
end
image = Paperclip.io_adapters.for(image_params[:file_data])
image.original_filename = image_params[:file_name]
tiny_image = TinyMceAsset.create!(
image: image,
team: @team,
object: result_text,
saved: true
)
tiny_image.image.attach(
io: StringIO.new(Base64.decode64(image_params[:file_data].split(',')[1])),
filename: image_params[:file_name]
)
result_text.text.sub!("data-mce-token=\"#{token}\"", "data-mce-token=\"#{Base62.encode(tiny_image.id)}\"")
end
end

View file

@ -209,7 +209,7 @@ class AssetsController < ApplicationController
render_403 and return unless can_manage_module?(my_module)
# First create result and then the asset
result = Result.create(name: file.original_filename,
result = Result.create(name: asset.file_name,
my_module: my_module,
user: current_user)
result_asset = ResultAsset.create!(result: result, asset: asset)

View file

@ -437,9 +437,7 @@ class Asset < ApplicationRecord
end
def update_contents(new_file)
new_file.class.class_eval { attr_accessor :original_filename }
new_file.original_filename = file_name
file.attach(io: new_file, filename: original_filename)
file.attach(io: new_file, filename: file_name)
self.version = version.nil? ? 1 : version + 1
save
end
@ -473,14 +471,14 @@ class Asset < ApplicationRecord
def wopi_filename_valid
# Check that filename without extension is not blank
unless file.original_filename[0..-6].present?
unless file_name[0..-6].present?
errors.add(
:file,
I18n.t('general.text.not_blank')
)
end
# Check maximum filename length
if file.original_filename.length > Constants::FILENAME_MAX_LENGTH
if file_name.length > Constants::FILENAME_MAX_LENGTH
errors.add(
:file,
I18n.t(

View file

@ -14,8 +14,6 @@ Api.configure do |config|
config.core_api_v1_enabled = true if ENV['CORE_API_V1_ENABLED']
Paperclip::DataUriAdapter.register if ENV['CORE_API_V1_ENABLED']
vars = ENV.select { |name, _| name =~ /^[[:alnum:]]*_AZURE_AD_APP_ID/ }
vars.each do |name, value|
app_name = name.sub('_AZURE_AD_APP_ID', '')