タグ履歴 (#309) (#319)

#309

#309

#309

#309

#309

Merge remote-tracking branch 'origin/main' into feature/309

#309

Co-authored-by: miteruzo <miteruzo@naver.com>
Reviewed-on: #319
This commit was merged in pull request #319.
This commit is contained in:
2026-04-19 20:21:51 +09:00
parent 5c7580d571
commit bde7d33949
27 changed files with 923 additions and 123 deletions
@@ -30,15 +30,21 @@ class NicoTagsController < ApplicationController
id = params[:id].to_i
tag = Tag.find(id)
return head :bad_request if tag.category != 'nico'
return head :bad_request unless tag.nico?
linked_tag_names = params[:tags].to_s.split(' ')
linked_tag_names = params[:tags].to_s.split
linked_tags = Tag.normalise_tags(linked_tag_names, with_tagme: false,
with_no_deerjikist: false)
return head :bad_request if linked_tags.any? { |t| t.category == 'nico' }
return head :bad_request if linked_tags.any? { |t| t.nico? }
tag.linked_tags = linked_tags
tag.save!
ApplicationRecord.transaction do
TagVersioning.record_tag_snapshots!(linked_tags, created_by_user: current_user)
tag.linked_tags = linked_tags
tag.save!
NicoTagVersionRecorder.record!(tag:, event_type: :update, created_by_user: current_user)
end
render json: tag.linked_tags.map { |t| TagRepr.base(t) }, status: :ok
end
+11 -4
View File
@@ -128,9 +128,11 @@ class PostsController < ApplicationController
original_created_from:, original_created_before:)
post.thumbnail.attach(thumbnail)
ActiveRecord::Base.transaction do
ApplicationRecord.transaction do
post.save!
tags = Tag.normalise_tags(tag_names)
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user)
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
post.resized_thumbnail!
@@ -170,10 +172,15 @@ class PostsController < ApplicationController
post = Post.find(params[:id].to_i)
ActiveRecord::Base.transaction do
ApplicationRecord.transaction do
PostVersionRecorder.ensure_snapshot!(post, created_by_user: current_user)
post.update!(title:, original_created_from:, original_created_before:)
tags = post.tags.where(category: 'nico').to_a +
Tag.normalise_tags(tag_names, with_tagme: false)
normalised_tags = Tag.normalise_tags(tag_names, with_tagme: false)
TagVersioning.record_tag_snapshots!(normalised_tags, created_by_user: current_user)
tags = post.tags.nico.to_a + normalised_tags
tags = Tag.expand_parent_tags(tags)
sync_post_tags!(post, tags)
PostVersionRecorder.record!(post:, event_type: :update, created_by_user: current_user)
@@ -7,7 +7,16 @@ class TagChildrenController < ApplicationController
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children << Tag.find(child_id) rescue nil
parent = Tag.find(parent_id)
child = Tag.find(child_id)
return head :bad_request if parent.nico? || child.nico?
ApplicationRecord.transaction do
TagVersioning.ensure_snapshot!(child, created_by_user: current_user)
TagImplication.find_or_create_by!(parent_tag: parent, tag: child)
TagVersionRecorder.record!(tag: child, event_type: :update, created_by_user: current_user)
end
head :no_content
end
@@ -20,7 +29,16 @@ class TagChildrenController < ApplicationController
child_id = params[:child_id]
return head :bad_request if parent_id.blank? || child_id.blank?
Tag.find(parent_id).children.delete(Tag.find(child_id)) rescue nil
parent = Tag.find(parent_id)
child = Tag.find(child_id)
return head :bad_request if parent.nico? || child.nico?
ApplicationRecord.transaction do
TagVersioning.ensure_snapshot!(child, created_by_user: current_user)
TagImplication.find_by(parent_tag: parent, tag: child)&.destroy!
TagVersionRecorder.record!(tag: child, event_type: :update, created_by_user: current_user)
end
head :no_content
end
+19 -5
View File
@@ -218,15 +218,21 @@ class TagsController < ApplicationController
tag = Tag.find(params[:id])
if name.present?
tag.tag_name.update!(name:)
if category.present? && tag.nico? != (category == 'nico')
return render json: { error: 'ニコタグのカテゴリ変更はできません.' },
status: :unprocessable_entity
end
if category.present?
tag.update!(category:)
ApplicationRecord.transaction do
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
tag.tag_name.update!(name:) if name.present?
tag.update!(category:) if category.present?
record_tag_version!(tag, event_type: :update, created_by_user: current_user)
end
render json: TagRepr.base(tag)
render json: TagRepr.base(tag.reload)
end
private
@@ -244,4 +250,12 @@ class TagsController < ApplicationController
children: tag.children.sort_by { _1.name }.map { build_tag_children(_1) },
material: material.as_json&.merge(file:, content_type:))
end
def record_tag_version!(tag, event_type:, created_by_user:)
if tag.nico?
NicoTagVersionRecorder.record!(tag:, event_type:, created_by_user:)
else
TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
end
end
end