このコミットが含まれているのは:
@@ -70,8 +70,15 @@ class PostImportsController < ApplicationController
|
|||||||
end
|
end
|
||||||
raise ArgumentError, '解析結果が大きすぎます.' if rows.sum { Array(_1['values']).sum(&:bytesize) } > PostImportSourceParser::MAX_BYTES
|
raise ArgumentError, '解析結果が大きすぎます.' if rows.sum { Array(_1['values']).sum(&:bytesize) } > PostImportSourceParser::MAX_BYTES
|
||||||
|
|
||||||
{ columns: columns.map { |column| column.slice('key', 'label') },
|
parsed_rows = rows.map do |row|
|
||||||
rows: rows.map { |row| { source_row: row['source_row'], values: Array(row['values']) } } }
|
source_row = Integer(row['source_row'], exception: false)
|
||||||
|
raise ArgumentError, '元行番号が不正です.' if source_row.nil? || source_row <= 0
|
||||||
|
|
||||||
|
{ source_row:, values: Array(row['values']) }
|
||||||
|
end
|
||||||
|
raise ArgumentError, '元行番号が重複しています.' if parsed_rows.map { _1[:source_row] }.uniq.length != parsed_rows.length
|
||||||
|
|
||||||
|
{ columns: columns.map { |column| column.slice('key', 'label') }, rows: parsed_rows }
|
||||||
end
|
end
|
||||||
|
|
||||||
def validate_rows_params
|
def validate_rows_params
|
||||||
|
|||||||
@@ -23,6 +23,14 @@ class PostImportPreviewer
|
|||||||
tag_sources['manual'] = attributes['tags'].to_s if provenance['tags'] == 'manual'
|
tag_sources['manual'] = attributes['tags'].to_s if provenance['tags'] == 'manual'
|
||||||
url = row[:url].presence || values[@url_column].to_s.strip
|
url = row[:url].presence || values[@url_column].to_s.strip
|
||||||
url_for_metadata = normalised_url(url) || url
|
url_for_metadata = normalised_url(url) || url
|
||||||
|
existing_post = normalised_url(url).present? && Post.exists?(url: normalised_url(url))
|
||||||
|
if existing_post && @existing == 'skip'
|
||||||
|
next { source_row: row[:source_row], url: normalised_url(url) || url, attributes:,
|
||||||
|
provenance:, tag_sources:, metadata_url: url_for_metadata,
|
||||||
|
fetch_warnings: [], validation_warnings: ['既存投稿のためスキップします.'],
|
||||||
|
warnings: ['既存投稿のためスキップします.'], validation_errors: { },
|
||||||
|
status: 'warning', existing: true }
|
||||||
|
end
|
||||||
url_changed = row[:metadata_url].present? && row[:metadata_url] != url_for_metadata
|
url_changed = row[:metadata_url].present? && row[:metadata_url] != url_for_metadata
|
||||||
clear_automatic_values!(attributes, provenance, tag_sources) if url_changed
|
clear_automatic_values!(attributes, provenance, tag_sources) if url_changed
|
||||||
provenance['url'] ||= row[:url].present? ? 'manual' : 'mapped'
|
provenance['url'] ||= row[:url].present? ? 'manual' : 'mapped'
|
||||||
@@ -53,7 +61,7 @@ class PostImportPreviewer
|
|||||||
validation_warnings = []
|
validation_warnings = []
|
||||||
errors[:url] = ['URL が重複しています.'] if normal_url.present? && urls.key?(normal_url)
|
errors[:url] = ['URL が重複しています.'] if normal_url.present? && urls.key?(normal_url)
|
||||||
urls[normal_url] = true if normal_url.present?
|
urls[normal_url] = true if normal_url.present?
|
||||||
if normal_url.present? && Post.exists?(url: normal_url)
|
if normal_url.present? && existing_post
|
||||||
@existing == 'error' ? errors[:url] = ['既存投稿です.'] : validation_warnings << '既存投稿のためスキップします.'
|
@existing == 'error' ? errors[:url] = ['既存投稿です.'] : validation_warnings << '既存投稿のためスキップします.'
|
||||||
end
|
end
|
||||||
validate_basic_data(attributes, errors)
|
validate_basic_data(attributes, errors)
|
||||||
@@ -163,10 +171,10 @@ class PostImportPreviewer
|
|||||||
original_created_before: attributes['original_created_before'].presence,
|
original_created_before: attributes['original_created_before'].presence,
|
||||||
video_ms: parse_duration(attributes['duration'], errors))
|
video_ms: parse_duration(attributes['duration'], errors))
|
||||||
post.valid?
|
post.valid?
|
||||||
post.errors.each { |error| (errors[error.attribute] ||= []) << error.message }
|
post.errors.each do |error|
|
||||||
if errors[:url]
|
next if error.attribute == :url && error.type == :taken
|
||||||
errors[:url].reject! { |message| message.include?('すでに存在') || message.include?('taken') }
|
|
||||||
errors.delete(:url) if errors[:url].empty?
|
(errors[error.attribute] ||= []) << error.message
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
新しい課題から参照
ユーザをブロックする