このコミットが含まれているのは:
@@ -12,6 +12,7 @@ class PostCreatePlan
|
||||
direct_tag_specs, tag_sections = parse_direct_tag_specs
|
||||
default_tag_specs = build_default_tag_specs(direct_tag_specs)
|
||||
snapshot_tag_specs = merge_tag_specs(direct_tag_specs + default_tag_specs)
|
||||
validate_new_tag_specs!(snapshot_tag_specs)
|
||||
post_tag_specs = expand_parent_tag_specs(snapshot_tag_specs)
|
||||
video_ms = normalise_video_ms(snapshot_tag_specs)
|
||||
validate_video_sections!(video_ms, tag_sections)
|
||||
@@ -103,6 +104,31 @@ class PostCreatePlan
|
||||
default_tag_specs
|
||||
end
|
||||
|
||||
def validate_new_tag_specs! specs
|
||||
Array(specs).each do |spec|
|
||||
next if existing_tags_by_name.key?(spec[:name])
|
||||
|
||||
validate_new_tag_spec!(spec)
|
||||
end
|
||||
end
|
||||
|
||||
def validate_new_tag_spec! spec
|
||||
tag_name = TagName.new(name: spec[:name])
|
||||
tag = Tag.new(category: spec[:category], tag_name:)
|
||||
return if tag_name.valid? && tag.valid?
|
||||
|
||||
post = Post.new
|
||||
tag_name.errors[:name].each do |message|
|
||||
post.errors.add :tags, "#{ spec[:name] }: #{ message }"
|
||||
end
|
||||
tag.errors.each do |error|
|
||||
next if error.attribute == :tag_name
|
||||
|
||||
post.errors.add :tags, "#{ spec[:name] }: #{ error.message }"
|
||||
end
|
||||
raise ActiveRecord::RecordInvalid, post
|
||||
end
|
||||
|
||||
def expand_parent_tag_specs snapshot_tag_specs
|
||||
existing_snapshot_tags = snapshot_tag_specs.filter_map { existing_tags_by_name[_1[:name]] }
|
||||
expanded_parent_specs =
|
||||
|
||||
新しい課題から参照
ユーザをブロックする