このコミットが含まれているのは:
@@ -17,6 +17,7 @@ class TagVersionsController < ApplicationController
|
||||
AND prev.version_no = tag_versions.version_no - 1
|
||||
SQL
|
||||
.select('tag_versions.*', 'prev.name AS prev_name', 'prev.category AS prev_category',
|
||||
'prev.deprecated_at AS prev_deprecated_at',
|
||||
'prev.aliases AS prev_aliases', 'prev.parent_tag_ids AS prev_parent_tag_ids')
|
||||
q = q.where('tag_versions.tag_id = ?', tag_id) if tag_id
|
||||
|
||||
@@ -62,6 +63,8 @@ class TagVersionsController < ApplicationController
|
||||
event_type: row.event_type,
|
||||
name: { current: row.name, prev: row.attributes['prev_name'] },
|
||||
category: { current: row.category, prev: row.attributes['prev_category'] },
|
||||
deprecated_at: { current: row.deprecated_at&.iso8601,
|
||||
prev: row.attributes['prev_deprecated_at']&.iso8601 },
|
||||
aliases: build_version_values(cur_aliases, prev_aliases, key: :name),
|
||||
parent_tags:,
|
||||
created_at: row.created_at.iso8601,
|
||||
|
||||
@@ -14,6 +14,8 @@ class TagsController < ApplicationController
|
||||
post_count_between[1] = nil if post_count_between[1] < 0
|
||||
created_between = params[:created_from].presence, params[:created_to].presence
|
||||
updated_between = params[:updated_from].presence, params[:updated_to].presence
|
||||
deprecated_given = params.key?(:deprecated)
|
||||
deprecated = bool?(:deprecated)
|
||||
|
||||
order = params[:order].to_s.split(':', 2).map(&:strip)
|
||||
unless order[0].in?(['name', 'category', 'post_count', 'created_at', 'updated_at'])
|
||||
@@ -48,6 +50,9 @@ class TagsController < ApplicationController
|
||||
q = q.where('tags.created_at <= ?', created_between[1]) if created_between[1]
|
||||
q = q.where('tags.updated_at >= ?', updated_between[0]) if updated_between[0]
|
||||
q = q.where('tags.updated_at <= ?', updated_between[1]) if updated_between[1]
|
||||
if deprecated_given
|
||||
q = deprecated ? q.where.not(deprecated_at: nil) : q.where(deprecated_at: nil)
|
||||
end
|
||||
|
||||
sort_sql =
|
||||
case order[0]
|
||||
@@ -79,9 +84,21 @@ class TagsController < ApplicationController
|
||||
|
||||
tag_ids =
|
||||
if parent_tag_id
|
||||
TagImplication.where(parent_tag_id:).select(:tag_id)
|
||||
TagImplication.joins(:tag)
|
||||
.where(parent_tag_id:)
|
||||
.where(tags: { deprecated_at: nil })
|
||||
.select(:tag_id)
|
||||
else
|
||||
Tag.where.not(id: TagImplication.select(:tag_id)).select(:id)
|
||||
Tag.where(deprecated_at: nil)
|
||||
.where.not(id: TagImplication
|
||||
.joins(<<~SQL.squish)
|
||||
INNER JOIN
|
||||
tags parent_tags
|
||||
ON parent_tags.id = tag_implications.parent_tag_id
|
||||
SQL
|
||||
.where('parent_tags.deprecated_at IS NULL')
|
||||
.select(:tag_id))
|
||||
.select(:id)
|
||||
end
|
||||
|
||||
tags =
|
||||
@@ -89,6 +106,7 @@ class TagsController < ApplicationController
|
||||
.joins(:tag_name)
|
||||
.includes(:tag_name, :materials, tag_name: :wiki_page)
|
||||
.where(category: [:meme, :character, :material])
|
||||
.where(deprecated_at: nil)
|
||||
.where(id: tag_ids)
|
||||
.order('tag_names.name')
|
||||
.distinct
|
||||
@@ -101,7 +119,8 @@ class TagsController < ApplicationController
|
||||
TagImplication
|
||||
.joins(:tag)
|
||||
.where(parent_tag_id: tags.map(&:id),
|
||||
tags: { category: [:meme, :character, :material] })
|
||||
tags: { category: [:meme, :character, :material],
|
||||
deprecated_at: nil })
|
||||
.distinct
|
||||
.pluck(:parent_tag_id)
|
||||
end
|
||||
@@ -133,6 +152,7 @@ class TagsController < ApplicationController
|
||||
|
||||
base = Tag.joins(:tag_name)
|
||||
.includes(:tag_name, :materials, tag_name: :wiki_page)
|
||||
.where(deprecated_at: nil)
|
||||
base = base.where('tags.post_count > 0') if present_only
|
||||
|
||||
canonical_hit =
|
||||
@@ -252,18 +272,24 @@ class TagsController < ApplicationController
|
||||
category = params[:category].to_s.strip
|
||||
return render_unprocessable_entity('名前は必須です.', field: :name) if name.blank?
|
||||
return render_unprocessable_entity('カテゴリは必須です.', field: :category) if category.blank?
|
||||
return render_unprocessable_entity '廃止状態は必須です.', field: :deprecated unless params.key?(:deprecated)
|
||||
|
||||
if name != tag.name &&
|
||||
tag.in?([Tag.tagme, Tag.bot, Tag.no_deerjikist, Tag.video, Tag.niconico])
|
||||
return render_unprocessable_entity('システム・タグの名称は変更できません.', field: :name)
|
||||
end
|
||||
|
||||
if tag.nico? || category == 'nico'
|
||||
return render_unprocessable_entity('ニコタグは変更できません.', field: :category)
|
||||
if (name != tag.name &&
|
||||
tag.in?([Tag.tagme, Tag.bot, Tag.no_deerjikist, Tag.video, Tag.niconico]))
|
||||
return render_unprocessable_entity 'システム・タグの名称は変更できません.', field: :name
|
||||
end
|
||||
|
||||
alias_names = params[:aliases].to_s.split.uniq
|
||||
parent_names = params[:parent_tags].to_s.split.uniq
|
||||
deprecated = bool?(:deprecated)
|
||||
|
||||
if tag.nico? && deprecated
|
||||
return render_unprocessable_entity 'ニコタグは廃止できません.', field: :deprecated
|
||||
end
|
||||
|
||||
if tag.nico? || category == 'nico'
|
||||
return render_unprocessable_entity 'ニコタグは変更できません.', field: :category
|
||||
end
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
|
||||
@@ -272,7 +298,11 @@ class TagsController < ApplicationController
|
||||
name_changed = name != old_name
|
||||
wiki_page = tag.tag_name.wiki_page if name_changed
|
||||
|
||||
tag.update!(category:)
|
||||
if tag.deprecated? == deprecated
|
||||
tag.update!(category:)
|
||||
else
|
||||
tag.update!(category:, deprecated_at: deprecated ? Time.current : nil)
|
||||
end
|
||||
tag.tag_name.update!(name:)
|
||||
|
||||
alias_names << old_name if name_changed
|
||||
@@ -300,11 +330,17 @@ class TagsController < ApplicationController
|
||||
|
||||
name = params[:name].presence
|
||||
category = params[:category].presence
|
||||
deprecated_given = params.key?(:deprecated)
|
||||
deprecated = bool?(:deprecated)
|
||||
|
||||
tag = Tag.find(params[:id])
|
||||
|
||||
if tag.nico? && deprecated_given && deprecated
|
||||
return render_unprocessable_entity 'ニコタグは廃止できません.', field: :deprecated
|
||||
end
|
||||
|
||||
if tag.nico? || (category.present? && category == 'nico')
|
||||
return render_unprocessable_entity('ニコタグは変更できません.', field: :category)
|
||||
return render_unprocessable_entity 'ニコタグは変更できません.', field: :category
|
||||
end
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
@@ -316,6 +352,9 @@ class TagsController < ApplicationController
|
||||
|
||||
tag.tag_name.update!(name:) if name.present?
|
||||
tag.update!(category:) if category.present?
|
||||
if deprecated_given && tag.deprecated? != deprecated
|
||||
tag.update!(deprecated_at: deprecated ? Time.current : nil)
|
||||
end
|
||||
|
||||
tag.reload
|
||||
|
||||
|
||||
新しい課題から参照
ユーザをブロックする