mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2025-09-07 13:44:23 +08:00
Few fixes after review [SCI-2718]
This commit is contained in:
parent
ab3aeac26b
commit
e06684b7cf
1 changed files with 17 additions and 7 deletions
|
@ -6,8 +6,8 @@ module Api
|
||||||
include TinyMceHelper
|
include TinyMceHelper
|
||||||
|
|
||||||
before_action :load_vars
|
before_action :load_vars
|
||||||
before_action :load_result, only: %i(show update destroy)
|
before_action :load_result, only: %i(show)
|
||||||
before_action :check_manage_permissions, only: %i(create update destroy)
|
before_action :check_manage_permissions, only: %i(create)
|
||||||
|
|
||||||
def index
|
def index
|
||||||
results = @task.results
|
results = @task.results
|
||||||
|
@ -59,9 +59,7 @@ module Api
|
||||||
end
|
end
|
||||||
|
|
||||||
def create_text_result
|
def create_text_result
|
||||||
result_text = ResultText.new(
|
result_text = ResultText.new(text: result_text_params[:text])
|
||||||
text: result_text_params.require(:attributes).require(:text)
|
|
||||||
)
|
|
||||||
result_text.transaction do
|
result_text.transaction do
|
||||||
if tiny_mce_asset_params.present?
|
if tiny_mce_asset_params.present?
|
||||||
tiny_mce_asset_params.each do |t|
|
tiny_mce_asset_params.each do |t|
|
||||||
|
@ -95,13 +93,16 @@ module Api
|
||||||
'Wrong object type within parameters'
|
'Wrong object type within parameters'
|
||||||
end
|
end
|
||||||
params.require(:data).require(:attributes).require(:name)
|
params.require(:data).require(:attributes).require(:name)
|
||||||
params.permit(data: { attributes: :name })[:data]
|
params.permit(data: { attributes: :name })[:data][:attributes]
|
||||||
end
|
end
|
||||||
|
|
||||||
# Partially implement sideposting draft
|
# Partially implement sideposting draft
|
||||||
# https://github.com/json-api/json-api/pull/1197
|
# https://github.com/json-api/json-api/pull/1197
|
||||||
def result_text_params
|
def result_text_params
|
||||||
params[:included]&.select { |el| el[:type] == 'result_texts' }&.first
|
prms =
|
||||||
|
params[:included]&.select { |el| el[:type] == 'result_texts' }&.first
|
||||||
|
prms.require(:attributes).require(:text)
|
||||||
|
prms[:attributes]
|
||||||
end
|
end
|
||||||
|
|
||||||
def tiny_mce_asset_params
|
def tiny_mce_asset_params
|
||||||
|
@ -109,6 +110,15 @@ module Api
|
||||||
prms.each do |p|
|
prms.each do |p|
|
||||||
p.require(:attributes).require(%i(file_data file_name file_token))
|
p.require(:attributes).require(%i(file_data file_name file_token))
|
||||||
end
|
end
|
||||||
|
file_tokens = prms.map { |p| p[:attributes][:file_token] }
|
||||||
|
result_text_params[:text].scan(
|
||||||
|
/\[~tiny_mce_id:(\w+)\]/
|
||||||
|
).flatten.each do |token|
|
||||||
|
unless file_tokens.include?(token)
|
||||||
|
raise StandardError,
|
||||||
|
'Text contains reference to nonexisting TinyMCE image'
|
||||||
|
end
|
||||||
|
end
|
||||||
prms
|
prms
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue