このコミットが含まれているのは:
2026-10-12 20:10:04 +09:00
コミット 2e98ed02e3
41個のファイルの変更、624行の追加、244行の削除
+26 -31
ファイルの表示
@@ -9,7 +9,8 @@ class WikiPagesController < ApplicationController
TagDescription.where(language_code: 'ja')
.includes(tag: :tag_names)
tag_groups = TagGroup.all
descriptions = descriptions.order(updated_at: :desc, id: :asc)
tag_groups = TagGroup.order(updated_at: :desc, id: :asc)
if title.present?
pattern = "%#{ ApplicationRecord.sanitize_sql_like(title) }%"
descriptions =
@@ -22,7 +23,9 @@ class WikiPagesController < ApplicationController
json = descriptions.map { |description| WikiPageRepr.tag_description(description) }
json.concat(tag_groups.map { WikiPageRepr.tag_group(_1) })
json.sort! { |a, b| b['updated_at'] <=> a['updated_at'] }
json.sort_by! do |row|
[-row['updated_at'].to_f, row.fetch('resource_type'), row.fetch('id')]
end
json = json.first(20) if title.present?
render json:
end
@@ -99,7 +102,7 @@ class WikiPagesController < ApplicationController
'title' => "#{ TagGroupRepr::PREFIX }#{ tag_group.name }",
'deprecated_at' => nil }
else
raise 'お前やりませんねぇスギ!'
return head :not_found
end
end
@@ -141,7 +144,7 @@ class WikiPagesController < ApplicationController
page =
if title.include?(':')
raise 'お前やりませんねぇスギ!'
return render_unprocessable_entity field: :title
else
tag_name = TagName.find_by(language_code: 'ja', name: title)
return render_unprocessable_entity field: :title unless tag_name&.tag
@@ -150,7 +153,8 @@ class WikiPagesController < ApplicationController
tag: tag_name.tag, body:, created_by_user: current_user, message:)
end
render json: WikiPageRepr.base(page), status: :created
description = TagDescription.find_by!(tag_id: page.tag_name.tag_id, language_code: 'ja')
render json: WikiPageRepr.tag_description(description), status: :created
rescue ActiveRecord::RecordInvalid => e
render_validation_error e.record
rescue ActiveRecord::RecordNotUnique
@@ -180,44 +184,34 @@ class WikiPagesController < ApplicationController
return head :ok
end
page = WikiPage.find_by(id: params[:id])
if legacy_group_page?(page)
return render_unprocessable_entity field: :title if title.include?(':')
description = TagDescription.find_by(id: params[:id])
unless description
return render_unprocessable_entity field: :title if group || WikiPage.exists?(id: params[:id])
return head :not_found
end
tag = description.tag
tag_name = TagDescriptionOperation.compatibility_tag_name(tag)
if tag_name.name.include?(':') || (group && title != tag_name.name)
return render_unprocessable_entity field: :title
end
if group && !legacy_update_identified?(page, title, group)
return render_unprocessable_entity field: :title
end
return head :not_found unless page
base_revision_id = params[:base_revision_id].presence
ApplicationRecord.transaction do
page.lock!
old_title = page.title
tag = page.tag_name.tag
if tag && title != old_title
tag.lock!
old_title = tag_name.name
if title != old_title
TagVersioning.ensure_snapshot!(tag, created_by_user: current_user)
end
page.tag_name.update!(name: title) if title != old_title
tag_name.update!(name: title) if title != old_title
message = params[:message].presence
description = TagDescription.find_by(id: page.id)
description_page = description && (
tag&.id == description.tag_id ||
(tag.nil? && !old_title.include?(':')))
if description && !description_page
Wiki::Commit.legacy_content!(page:, body:, created_user: current_user,
message:, base_revision_id:)
else
Wiki::Commit.content!(page:, body:, created_user: current_user,
message:, base_revision_id:)
end
TagDescriptionOperation.update!(tag:, body:, updated_by_user: current_user,
message:, base_revision_id:)
if tag && title != old_title
if title != old_title
tag.reload
TagVersionRecorder.record!(tag:, event_type: :update, created_by_user: current_user)
end
@@ -306,6 +300,7 @@ class WikiPagesController < ApplicationController
updated_at = version.created_at
render json: {
'id' => version.tag_group_id,
'resource_type' => 'tag_group',
'title' => "#{ TagGroupRepr::PREFIX }#{ representation.fetch('name') }",
'deprecated_at' => nil,
'body' => body,