このコミットが含まれているのは:
@@ -7,7 +7,7 @@ class DeerjikistsController < ApplicationController
|
||||
|
||||
deerjikist = Deerjikist
|
||||
.joins(:tag)
|
||||
.includes(tag: :tag_name)
|
||||
.includes(tag: :tag_names)
|
||||
.find_by(platform:, code:)
|
||||
if deerjikist
|
||||
render json: DeerjikistRepr.base(deerjikist)
|
||||
|
||||
@@ -2,7 +2,7 @@ class GekanatorPostsController < ApplicationController
|
||||
def index
|
||||
posts =
|
||||
Post
|
||||
.preload(:post_similarities, tags: :tag_name)
|
||||
.preload(:post_similarities, tags: :tag_names)
|
||||
.with_attached_thumbnail
|
||||
.order(Arel.sql(
|
||||
'COALESCE(posts.original_created_before - INTERVAL 1 MINUTE, ' \
|
||||
@@ -56,7 +56,7 @@ class GekanatorPostsController < ApplicationController
|
||||
def tag_json tag
|
||||
{
|
||||
id: tag.id,
|
||||
name: tag.name,
|
||||
name: tag.name('ja'),
|
||||
category: tag.category
|
||||
}
|
||||
end
|
||||
|
||||
@@ -126,9 +126,9 @@ class GekanatorQuestionsController < ApplicationController
|
||||
end
|
||||
|
||||
Tag
|
||||
.joins(:tag_name)
|
||||
.joins(:tag_names)
|
||||
.where(category: categories.uniq)
|
||||
.where(tag_names: { name: names.uniq })
|
||||
.where(tag_names: { language_code: 'ja', primary_flg: true, name: names.uniq })
|
||||
.where.not(deprecated_at: nil)
|
||||
.pluck('tags.category', 'tag_names.name')
|
||||
.each_with_object({ }) do |(category, name), h|
|
||||
|
||||
@@ -20,7 +20,7 @@ class MaterialsController < ApplicationController
|
||||
q = Material.includes(:material_export_items,
|
||||
thumbnail_attachment: :blob,
|
||||
file_attachment: :blob,
|
||||
tag: :tag_name)
|
||||
tag: :tag_names)
|
||||
q = q.where(tag_id: nil) if filters[:tag_state] == 'untagged'
|
||||
q = q.where.not(tag_id: nil) if filters[:tag_state] == 'tagged'
|
||||
q = apply_material_tag_filter(q, filters, tag_graph)
|
||||
@@ -63,7 +63,7 @@ class MaterialsController < ApplicationController
|
||||
.find_by(id: params[:id])
|
||||
return head :not_found unless material
|
||||
|
||||
wiki_page_body = material.tag&.tag_name&.wiki_page&.current_revision&.body
|
||||
wiki_page_body = material.tag&.tag_name('ja')&.wiki_page&.current_revision&.body
|
||||
|
||||
render json: MaterialRepr.base(material, host: request.base_url).merge(wiki_page_body:)
|
||||
end
|
||||
@@ -96,7 +96,8 @@ class MaterialsController < ApplicationController
|
||||
updated_by_user: current_user)
|
||||
material.file.attach(uploaded_blob) if uploaded_blob
|
||||
material.save!
|
||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
upsert_export_paths!(material)
|
||||
MaterialVersionRecorder.record!(material:, event_type: :create,
|
||||
created_by_user: current_user)
|
||||
@@ -148,7 +149,8 @@ class MaterialsController < ApplicationController
|
||||
material.file.detach
|
||||
end
|
||||
material.save!
|
||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user)
|
||||
TagVersioning.record_tag_snapshot!(tag, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
upsert_export_paths!(material)
|
||||
MaterialVersionRecorder.record!(material:, event_type: :update,
|
||||
created_by_user: current_user)
|
||||
@@ -254,7 +256,12 @@ class MaterialsController < ApplicationController
|
||||
end
|
||||
|
||||
def material_index_join_tag_name q
|
||||
q.left_joins(tag: :tag_name)
|
||||
q.left_joins(:tag).joins(<<~SQL.squish)
|
||||
LEFT JOIN tag_names
|
||||
ON tag_names.tag_id = tags.id
|
||||
AND tag_names.language_code = 'ja'
|
||||
AND tag_names.primary_flg = TRUE
|
||||
SQL
|
||||
end
|
||||
|
||||
def material_index_join_file_blob q
|
||||
@@ -270,9 +277,11 @@ class MaterialsController < ApplicationController
|
||||
|
||||
def apply_material_query q, term
|
||||
like = "%#{ ActiveRecord::Base.sanitize_sql_like(term) }%"
|
||||
q.where('tag_names.name LIKE :q OR materials.url LIKE :q OR ' \
|
||||
'material_file_blobs.filename LIKE :q',
|
||||
q: like)
|
||||
q.where(<<~SQL.squish, q: like)
|
||||
tag_names.name LIKE :q
|
||||
OR materials.url LIKE :q
|
||||
OR material_file_blobs.filename LIKE :q
|
||||
SQL
|
||||
end
|
||||
|
||||
def apply_material_media_kind q, media_kind
|
||||
@@ -324,8 +333,9 @@ class MaterialsController < ApplicationController
|
||||
end
|
||||
tags_by_id =
|
||||
Tag
|
||||
.joins(:tag_name)
|
||||
.where(id: scope_tag_ids)
|
||||
.joins(:tag_names)
|
||||
.where(id: scope_tag_ids,
|
||||
tag_names: { language_code: 'ja', primary_flg: true })
|
||||
.pluck('tags.id', 'tag_names.name', 'tags.category', 'tags.deprecated_at')
|
||||
.each_with_object({ }) do |(id, name, category, deprecated_at), hash|
|
||||
hash[id] = { id:, name:, category:, deprecated: deprecated_at.present? }
|
||||
|
||||
@@ -24,7 +24,7 @@ class NicoTagsController < ApplicationController
|
||||
ExternalTag
|
||||
.joins("LEFT JOIN (#{ post_tag_max_sql }) post_tag_max " \
|
||||
'ON post_tag_max.external_tag_id = external_tags.id')
|
||||
.includes(linked_tags: { tag_name: :wiki_page })
|
||||
.includes(linked_tags: { tag_names: :wiki_page })
|
||||
if name
|
||||
q = q.where(('external_tags.name LIKE ? ' +
|
||||
"OR CONCAT(external_tags.platform, ':', external_tags.name) LIKE ?"),
|
||||
@@ -34,7 +34,8 @@ class NicoTagsController < ApplicationController
|
||||
if linked_tag
|
||||
linked_tag_ids =
|
||||
Tag
|
||||
.joins(:tag_name)
|
||||
.joins(:tag_names)
|
||||
.where(tag_names: { language_code: 'ja', primary_flg: true })
|
||||
.where('tag_names.name LIKE ?', "%#{ linked_tag }%")
|
||||
.pluck(:id)
|
||||
linked_nico_tag_ids = NicoTagRelation.where(tag_id: linked_tag_ids).pluck(:nico_tag_id)
|
||||
@@ -95,7 +96,10 @@ class NicoTagsController < ApplicationController
|
||||
with_tagme: false,
|
||||
with_no_deerjikist: false)
|
||||
|
||||
TagVersioning.record_tag_snapshots!(linked_tags, created_by_user: current_user)
|
||||
TagVersioning.record_tag_snapshots!(
|
||||
linked_tags,
|
||||
created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
|
||||
tag.linked_tags = linked_tags
|
||||
tag.save!
|
||||
|
||||
@@ -53,7 +53,7 @@ class PostsController < ApplicationController
|
||||
.reselect('posts.*', Arel.sql("#{ updated_at_all_sql } AS updated_at_all"))
|
||||
.preload(:external_tags, :uploaded_user, :parents, :children,
|
||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||
{ tag_name: :wiki_page }] }])
|
||||
{ tag_names: :wiki_page }] }])
|
||||
.with_attached_thumbnail
|
||||
|
||||
q = q.where('posts.url LIKE ?', "%#{ url }%") if url
|
||||
@@ -110,7 +110,7 @@ class PostsController < ApplicationController
|
||||
filtered_posts(locale)
|
||||
.preload(:uploaded_user, :parents, :children,
|
||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||
{ tag_name: :wiki_page }] }])
|
||||
{ tag_names: :wiki_page }] }])
|
||||
.with_attached_thumbnail
|
||||
.order('RAND()')
|
||||
.first
|
||||
@@ -195,7 +195,7 @@ class PostsController < ApplicationController
|
||||
Post
|
||||
.includes(:uploaded_user, :parents, :children,
|
||||
post_tags: [:sections, { tag: [:deerjikists, :materials,
|
||||
{ tag_name: :wiki_page }] }])
|
||||
{ tag_names: :wiki_page }] }])
|
||||
.with_attached_thumbnail
|
||||
.find_by(id: params[:id])
|
||||
return head :not_found unless post
|
||||
@@ -341,7 +341,7 @@ class PostsController < ApplicationController
|
||||
base_version = post.post_versions.find_by!(version_no: base_version_no)
|
||||
|
||||
base_snapshot = post_snapshot_from_version(base_version)
|
||||
current_snapshot = post_snapshot_from_record(post)
|
||||
current_snapshot = post_snapshot_from_record(post, locale)
|
||||
end
|
||||
incoming_snapshot = post_incoming_snapshot(locale:,
|
||||
title:,
|
||||
@@ -418,11 +418,11 @@ class PostsController < ApplicationController
|
||||
|
||||
if match_type == 'any'
|
||||
literals.reduce(Post.none) do |posts, literal|
|
||||
posts.or(tag_literal_relation(literal[:name], negative: literal[:negative]))
|
||||
posts.or(tag_literal_relation(locale, literal[:name], negative: literal[:negative]))
|
||||
end
|
||||
else
|
||||
literals.reduce(Post.all) do |posts, literal|
|
||||
ids = tagged_post_ids_for(literal[:name])
|
||||
ids = tagged_post_ids_for(locale, literal[:name])
|
||||
if literal[:negative]
|
||||
posts.where.not(id: ids)
|
||||
else
|
||||
@@ -432,8 +432,8 @@ class PostsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def tag_literal_relation name, negative:
|
||||
ids = tagged_post_ids_for(name)
|
||||
def tag_literal_relation locale, name, negative:
|
||||
ids = tagged_post_ids_for(locale, name)
|
||||
if negative
|
||||
Post.where.not(id: ids)
|
||||
else
|
||||
@@ -441,11 +441,11 @@ class PostsController < ApplicationController
|
||||
end
|
||||
end
|
||||
|
||||
def tagged_post_ids_for(name)
|
||||
def tagged_post_ids_for locale, name
|
||||
posts_by_internal_tags =
|
||||
Post
|
||||
.joins(tags: :tag_name)
|
||||
.where(tag_names: { name: })
|
||||
.joins(tags: :tag_names)
|
||||
.where(tag_names: { language_code: locale.language_code, name: })
|
||||
.select(:id)
|
||||
|
||||
posts_by_external_tags =
|
||||
@@ -688,24 +688,25 @@ class PostsController < ApplicationController
|
||||
.sort
|
||||
end
|
||||
|
||||
def post_snapshot_from_record post
|
||||
def post_snapshot_from_record post, locale
|
||||
{ title: post.title,
|
||||
video_ms: post.video_ms,
|
||||
original_created_from: snapshot_time(post.original_created_from),
|
||||
original_created_before: snapshot_time(post.original_created_before),
|
||||
tag_names: editable_tag_names_from_post(post),
|
||||
tag_names: editable_tag_names_from_post(post, locale.language_code),
|
||||
parent_post_ids: post.parent_posts.order(:id).pluck(:id) }
|
||||
end
|
||||
|
||||
def editable_tag_names_from_post post
|
||||
def editable_tag_names_from_post post, language_code
|
||||
post
|
||||
.post_tags
|
||||
.joins(tag: :tag_name)
|
||||
.joins(tag: :tag_names)
|
||||
.merge(Tag.where(deprecated_at: nil))
|
||||
.includes(:sections, tag: :tag_name)
|
||||
.where(tag_names: { language_code:, primary_flg: true })
|
||||
.includes(:sections, tag: :tag_names)
|
||||
.order('tag_names.name')
|
||||
.map do |post_tag|
|
||||
name = post_tag.tag.tag_name.name
|
||||
name = post_tag.tag.name(language_code)
|
||||
sections = post_tag.sections.sort_by(&:begin_ms)
|
||||
|
||||
next name if sections.empty?
|
||||
@@ -732,7 +733,7 @@ class PostsController < ApplicationController
|
||||
original_created_from: snapshot_time(original_created_from),
|
||||
original_created_before: snapshot_time(original_created_before),
|
||||
tag_names: tags.uniq(&:id).map { |tag|
|
||||
"#{ tag.name }#{ sections[tag.id].to_a.map { section_literal(_1) }.join }"
|
||||
"#{ tag.name(locale.language_code) }#{ sections[tag.id].to_a.map { section_literal(_1) }.join }"
|
||||
}.sort,
|
||||
parent_post_ids: parent_post_ids.sort }
|
||||
end
|
||||
@@ -868,7 +869,8 @@ class PostsController < ApplicationController
|
||||
with_tagme: false,
|
||||
deny_deprecated: true,
|
||||
with_sections: true) => { tags:, sections: }
|
||||
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user)
|
||||
TagVersioning.record_tag_snapshots!(tags, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
|
||||
tags = Tag.expand_parent_tags(tags).reject(&:deprecated?)
|
||||
|
||||
|
||||
@@ -47,7 +47,7 @@ class TagVersionsController < ApplicationController
|
||||
|
||||
tags_by_id =
|
||||
Tag
|
||||
.includes(:tag_name, :materials, { tag_name: :wiki_page })
|
||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||
.where(id: all_parent_tag_ids)
|
||||
.index_by(&:id)
|
||||
|
||||
|
||||
@@ -176,7 +176,7 @@ class TagsController < ApplicationController
|
||||
Tag
|
||||
.joins(:tag_names)
|
||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||
.where(tag_names: { language_code: locale.language.code, primary_flg: true },
|
||||
.where(tag_names: { language_code: locale.language_code, primary_flg: true },
|
||||
id: tag_ids)
|
||||
.index_by(&:id)
|
||||
external_tags_by_id =
|
||||
@@ -186,7 +186,7 @@ class TagsController < ApplicationController
|
||||
|
||||
render json: { tags: rows.map { |row|
|
||||
if row['source'] == 'tag'
|
||||
TagRepr.base(tags_by_id.fetch(row['id']))
|
||||
TagRepr.base(tags_by_id.fetch(row['id']), language_code: locale.language_code)
|
||||
else
|
||||
external_tag_json(external_tags_by_id.fetch(row['id']))
|
||||
end
|
||||
@@ -223,15 +223,15 @@ class TagsController < ApplicationController
|
||||
|
||||
alias_rows =
|
||||
TagName
|
||||
.where(language_code: locale.language_code, primary_code: false)
|
||||
.where(language_code: locale.language_code, primary_flg: false)
|
||||
.where('name LIKE ?', prefix)
|
||||
.pluck(:tag_id, :name)
|
||||
|
||||
matched_alias_by_tag_name_id = { }
|
||||
matched_alias_by_tag_id = { }
|
||||
tag_ids = []
|
||||
alias_rows.each do |tag_id, alias_name|
|
||||
tag_ids << tag_id
|
||||
matched_alias_by_tag_name_id[tag_id] ||= alias_name
|
||||
matched_alias_by_tag_id[tag_id] ||= alias_name
|
||||
end
|
||||
|
||||
base =
|
||||
@@ -251,7 +251,8 @@ class TagsController < ApplicationController
|
||||
.order(Arel.sql('tags.post_count DESC, tag_names.name'))
|
||||
.limit(20)
|
||||
.map { |tag|
|
||||
TagRepr.base(tag).merge(matched_alias: matched_alias_by_tag_name_id[tag.tag_name_id])
|
||||
TagRepr.base(tag, language_code: locale.language_code)
|
||||
.merge(matched_alias: matched_alias_by_tag_id[tag.id])
|
||||
}
|
||||
|
||||
return render json: internal_rows unless with_nico
|
||||
@@ -267,8 +268,8 @@ class TagsController < ApplicationController
|
||||
.map { external_tag_json(_1) }
|
||||
|
||||
rows =
|
||||
(internal_rows + external_rows)
|
||||
.sort_by { |row| [-row['post_count'], row['name']] }
|
||||
(internal_rows + external_rows)
|
||||
.sort_by { |row| [-row['post_count'], row['name'] || row[:name]] }
|
||||
.first(20)
|
||||
|
||||
render json: rows
|
||||
@@ -283,7 +284,7 @@ class TagsController < ApplicationController
|
||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||
.find_by(id: params[:id],
|
||||
tag_names: { language_code: locale.language_code, primary_flg: true })
|
||||
return render json: TagRepr.base(tag) if tag
|
||||
return render json: TagRepr.base(tag, language_code: locale.language_code) if tag
|
||||
|
||||
external_tag = ExternalTag.find_by(id: params[:id])
|
||||
return render json: ExternalTagRepr.base(external_tag) if external_tag
|
||||
@@ -302,7 +303,7 @@ class TagsController < ApplicationController
|
||||
.joins(:tag_names)
|
||||
.includes(:tag_names, :materials, tag_names: :wiki_page)
|
||||
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
||||
return render json: TagRepr.base(tag) if tag
|
||||
return render json: TagRepr.base(tag, language_code: locale.language_code) if tag
|
||||
|
||||
platform, external_name = name.split(':', 2)
|
||||
return head :not_found unless external_name
|
||||
@@ -323,7 +324,7 @@ class TagsController < ApplicationController
|
||||
tag_names: { language_code: locale.language_code, primary_flg: true })
|
||||
return head :not_found unless tag
|
||||
|
||||
render json: { tag: TagRepr.base(tag),
|
||||
render json: { tag: TagRepr.base(tag, language_code: locale.language_code),
|
||||
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
||||
end
|
||||
|
||||
@@ -340,7 +341,7 @@ class TagsController < ApplicationController
|
||||
.find_by(tag_names: { name:, language_code: locale.language_code, primary_flg: true })
|
||||
return head :not_found unless tag
|
||||
|
||||
render json: { tag: TagRepr.base(tag),
|
||||
render json: { tag: TagRepr.base(tag, language_code: locale.language_code),
|
||||
deerjikists: DeerjikistRepr.many(tag.deerjikists) }
|
||||
end
|
||||
|
||||
@@ -348,6 +349,8 @@ class TagsController < ApplicationController
|
||||
return head :unauthorized unless current_user
|
||||
return head :forbidden unless current_user.gte_member?
|
||||
|
||||
locale = resolve_locale!
|
||||
|
||||
tag =
|
||||
Tag
|
||||
.joins(:tag_names)
|
||||
@@ -359,8 +362,6 @@ class TagsController < ApplicationController
|
||||
rows = normalise_deerjikist_rows(tag)
|
||||
return if performed?
|
||||
|
||||
locale = resolve_locale!
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
tag.lock!
|
||||
|
||||
@@ -423,7 +424,7 @@ class TagsController < ApplicationController
|
||||
|
||||
graph = build_with_depth_graph(material_filter)
|
||||
|
||||
render json: build_tag_children(tag, graph:)
|
||||
render json: build_tag_children(tag, graph:, language_code: locale.language_code)
|
||||
end
|
||||
|
||||
def update_all
|
||||
@@ -452,11 +453,12 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
|
||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
|
||||
old_name = tag.name
|
||||
old_name = tag.name(locale.language_code)
|
||||
name_changed = name != old_name
|
||||
wiki_page = tag.tag_name.wiki_page if name_changed
|
||||
wiki_page = tag.tag_name(locale.language_code)&.wiki_page if name_changed
|
||||
|
||||
if tag.deprecated? == deprecated
|
||||
tag.update!(category:)
|
||||
@@ -468,7 +470,7 @@ class TagsController < ApplicationController
|
||||
alias_names << old_name if name_changed
|
||||
alias_names.delete(name)
|
||||
|
||||
update_aliases!(tag, alias_names)
|
||||
update_aliases!(locale, tag, alias_names)
|
||||
update_parent_tags!(locale, tag, parent_names)
|
||||
|
||||
tag.reload
|
||||
@@ -477,11 +479,12 @@ class TagsController < ApplicationController
|
||||
tag,
|
||||
event_type: :update,
|
||||
created_by_user: current_user,
|
||||
language_code: locale.language_code,
|
||||
name_changed:,
|
||||
wiki_page:)
|
||||
end
|
||||
|
||||
render json: TagRepr.base(tag.reload)
|
||||
render json: TagRepr.base(tag.reload, language_code: locale.language_code)
|
||||
end
|
||||
|
||||
def update
|
||||
@@ -504,13 +507,14 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
ApplicationRecord.transaction do
|
||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
|
||||
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
|
||||
old_name = tag.name
|
||||
old_name = tag.name(locale.language_code)
|
||||
name_changed = name.present? && name != old_name
|
||||
wiki_page = tag.tag_name.wiki_page if name_changed
|
||||
wiki_page = tag.tag_name(locale.language_code)&.wiki_page if name_changed
|
||||
|
||||
rename_tag_name!(tag, name) if name_changed
|
||||
rename_tag_name!(locale, tag, name) if name_changed
|
||||
tag.update!(category:) if category.present?
|
||||
if deprecated_given && tag.deprecated? != deprecated
|
||||
tag.update!(deprecated_at: deprecated ? Time.current : nil)
|
||||
@@ -522,11 +526,12 @@ class TagsController < ApplicationController
|
||||
tag,
|
||||
event_type: :update,
|
||||
created_by_user: current_user,
|
||||
language_code: locale.language_code,
|
||||
name_changed:,
|
||||
wiki_page:)
|
||||
end
|
||||
|
||||
render json: TagRepr.base(tag.reload)
|
||||
render json: TagRepr.base(tag.reload, language_code: locale.language_code)
|
||||
end
|
||||
|
||||
private
|
||||
@@ -693,29 +698,30 @@ class TagsController < ApplicationController
|
||||
children: [] }
|
||||
end
|
||||
|
||||
def build_tag_children tag, graph: nil
|
||||
def build_tag_children tag, graph: nil, language_code: 'ja'
|
||||
material = tag.materials.first
|
||||
tag_graph = graph && graph[:tags_by_id][tag.id]
|
||||
material =
|
||||
nil if tag_graph && !with_depth_visible_tag?(tag_graph, graph[:material_filter])
|
||||
|
||||
children = tag.children.sort_by(&:name)
|
||||
children = tag.children.sort_by { _1.name(language_code) }
|
||||
if graph
|
||||
children = children.filter { |child_tag| visible_subtree?(child_tag.id, graph) }
|
||||
end
|
||||
|
||||
TagRepr.base(tag).merge(
|
||||
children: children.map { build_tag_children(_1, graph:) },
|
||||
TagRepr.base(tag, language_code:).merge(
|
||||
children: children.map { build_tag_children(_1, graph:, language_code:) },
|
||||
has_material: tag_graph ? tag_graph[:has_material] : material.present?,
|
||||
material: material && MaterialRepr.base(material, host: request.base_url))
|
||||
end
|
||||
|
||||
def record_tag_version! tag, event_type:, created_by_user:, name_changed: false, wiki_page: nil
|
||||
TagVersionRecorder.record!(tag:, event_type:, created_by_user:)
|
||||
def record_tag_version! tag, event_type:, created_by_user:, language_code: 'ja',
|
||||
name_changed: false, wiki_page: nil
|
||||
TagVersionRecorder.record!(tag:, event_type:, created_by_user:, language_code:)
|
||||
|
||||
return unless name_changed
|
||||
|
||||
wiki_page ||= tag.tag_name.wiki_page
|
||||
wiki_page ||= tag.tag_name('ja')&.wiki_page
|
||||
return unless wiki_page&.wiki_versions&.exists?
|
||||
|
||||
WikiVersionRecorder.record!(
|
||||
@@ -725,9 +731,13 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
def validate_tag_rename locale, tag, name
|
||||
return true if name.blank? || name == tag.name
|
||||
return true if name.blank? || name == tag.name(locale.language_code)
|
||||
|
||||
if tag.in?([Tag.tagme, Tag.bot, Tag.no_deerjikist, Tag.video, Tag.niconico])
|
||||
system_tag_names = ['タグ希望', 'bot操作', 'ニジラー情報不詳', '動画', 'ニコニコ']
|
||||
if TagName.exists?(tag_id: tag.id,
|
||||
language_code: 'ja',
|
||||
primary_flg: true,
|
||||
name: system_tag_names)
|
||||
render_unprocessable_entity 'システム・タグの名称は変更できません.', field: :name
|
||||
return false
|
||||
end
|
||||
@@ -746,7 +756,16 @@ class TagsController < ApplicationController
|
||||
target_tag_name = TagName.find_by(language_code: locale.language_code, name:)
|
||||
|
||||
unless target_tag_name
|
||||
current_tag_name.update!(name:)
|
||||
if current_tag_name
|
||||
current_tag_name.update!(name:)
|
||||
else
|
||||
current_tag_name = TagName.create!(
|
||||
tag:,
|
||||
language_code: locale.language_code,
|
||||
script_code: locale.script_code,
|
||||
name:,
|
||||
primary_flg: true)
|
||||
end
|
||||
return
|
||||
end
|
||||
|
||||
@@ -754,68 +773,79 @@ class TagsController < ApplicationController
|
||||
end
|
||||
|
||||
def promote_tag_alias! tag, current_tag_name:, promoted_tag_name:
|
||||
old_owner_tag = promoted_tag_name.canonical&.tag
|
||||
old_owner_tag = promoted_tag_name.tag
|
||||
|
||||
if old_owner_tag && old_owner_tag != tag
|
||||
TagVersioning.ensure_snapshot!(old_owner_tag, created_by_user: current_user)
|
||||
end
|
||||
|
||||
promoted_tag_name.update!(canonical_id: nil, primary_flg: true)
|
||||
current_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||
promoted_tag_name.update!(tag:, canonical_id: nil, primary_flg: true)
|
||||
|
||||
TagName.where(tag:,
|
||||
language_code: current_tag_name.language.language_code,
|
||||
language_code: current_tag_name.language_code,
|
||||
primary_flg: false)
|
||||
.where.not(id: promoted_tag_name.id)
|
||||
.find_each do |alias_tag_name|
|
||||
alias_tag_name.update!(canonical_id: promoted_tag_name, primary_flg: false)
|
||||
alias_tag_name.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||
end
|
||||
|
||||
current_tag_name.wiki_page&.update!(tag_name_id: promoted_tag_name.id)
|
||||
tag.update!(tag_name_id: promoted_tag_name.id)
|
||||
current_tag_name.association(:wiki_page).reset
|
||||
current_tag_name.association(:tag).reset
|
||||
current_tag_name.reload.update!(canonical_id: promoted_tag_name, primary_flg: false)
|
||||
current_tag_name.reload.update!(canonical_id: promoted_tag_name.id, primary_flg: false)
|
||||
|
||||
return unless old_owner_tag && old_owner_tag != tag
|
||||
|
||||
record_tag_version!(old_owner_tag.reload, event_type: :update, created_by_user: current_user)
|
||||
record_tag_version!(old_owner_tag.reload, event_type: :update,
|
||||
created_by_user: current_user,
|
||||
language_code: current_tag_name.language_code)
|
||||
end
|
||||
|
||||
def update_aliases! tag, alias_names
|
||||
def update_aliases! locale, tag, alias_names
|
||||
alias_names = alias_names.uniq
|
||||
|
||||
affected_tags = [tag]
|
||||
|
||||
current_aliases = tag.tag_name.aliases.to_a
|
||||
primary_tag_name = tag.tag_name(locale.language_code)
|
||||
current_aliases = tag.tag_names.where(language_code: locale.language_code,
|
||||
primary_flg: false).to_a
|
||||
|
||||
current_aliases.each do |alias_tag_name|
|
||||
next if alias_names.include?(alias_tag_name.name)
|
||||
|
||||
affected_tags << alias_tag_name.canonical&.tag
|
||||
affected_tags << alias_tag_name.tag
|
||||
end
|
||||
|
||||
alias_names.each do |alias_name|
|
||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
||||
affected_tags << alias_tag_name.canonical&.tag
|
||||
alias_tag_name = TagName.find_by(language_code: locale.language_code, name: alias_name)
|
||||
affected_tags << alias_tag_name&.tag
|
||||
end
|
||||
|
||||
affected_tags.compact.uniq.each do |affected_tag|
|
||||
TagVersioning.ensure_snapshot!(affected_tag, created_by_user: current_user)
|
||||
TagVersioning.ensure_snapshot!(affected_tag, created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
end
|
||||
|
||||
current_aliases.each do |alias_tag_name|
|
||||
next if alias_names.include?(alias_tag_name.name)
|
||||
|
||||
alias_tag_name.update!(canonical_id: nil)
|
||||
alias_tag_name.update!(canonical_id: nil, tag_id: nil)
|
||||
end
|
||||
|
||||
alias_names.each do |alias_name|
|
||||
alias_tag_name = TagName.find_or_create_by!(name: alias_name)
|
||||
alias_tag_name.update!(canonical_id: tag.tag_name.id)
|
||||
alias_tag_name = TagName.find_or_initialize_by(
|
||||
language_code: locale.language_code,
|
||||
name: alias_name)
|
||||
alias_tag_name.script_code = locale.script_code
|
||||
alias_tag_name.update!(tag:, primary_flg: false, canonical_id: primary_tag_name.id)
|
||||
end
|
||||
|
||||
affected_tags.compact.uniq.each do |affected_tag|
|
||||
record_tag_version!(affected_tag, event_type: :update, created_by_user: current_user)
|
||||
record_tag_version!(affected_tag, event_type: :update,
|
||||
created_by_user: current_user,
|
||||
language_code: locale.language_code)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -899,8 +929,6 @@ class TagsController < ApplicationController
|
||||
conflicts = deerjikists.filter { |deerjikist| deerjikist.tag_id != tag.id }
|
||||
return if conflicts.empty?
|
||||
|
||||
locale = resolve_locale!
|
||||
|
||||
tag_names_by_id =
|
||||
Tag
|
||||
.joins(:tag_names)
|
||||
|
||||
@@ -6,7 +6,7 @@ class TheatreSkipEventsController < ApplicationController
|
||||
events =
|
||||
TheatreSkipEvent
|
||||
.where(theatre_id: params[:theatre_id])
|
||||
.includes(:post, tags: :tag_name)
|
||||
.includes(:post, tags: :tag_names)
|
||||
.order(created_at: :desc)
|
||||
.limit(limit)
|
||||
|
||||
@@ -14,7 +14,7 @@ class TheatreSkipEventsController < ApplicationController
|
||||
{ id: event.id,
|
||||
theatre_id: event.theatre_id,
|
||||
post: { id: event.post.id, title: event.post.title, url: event.post.url },
|
||||
tags: event.tags.map { |tag| { id: tag.id, name: tag.name } },
|
||||
tags: event.tags.map { |tag| { id: tag.id, name: tag.name('ja') } },
|
||||
programme_position: event.programme_position,
|
||||
created_at: event.created_at }
|
||||
}
|
||||
|
||||
新しいイシューから参照
ユーザーをブロックする