このコミットが含まれているのは:
2026-10-10 11:14:01 +09:00
コミット 7840e15d1a
8個のファイルの変更、986行の追加、12行の削除
+73 -9
ファイルの表示
@@ -144,6 +144,17 @@ class WikiPagesController < ApplicationController
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
if title.start_with?(TagGroupRepr::PREFIX)
name = title.delete_prefix(TagGroupRepr::PREFIX)
parsed = TagGroupMarkdownParser.parse(body:, group: nil)
group = TagGroupOperation.create!(name:, **parsed, actor: current_user,
require_compatibility: true)
version = current_group_version(group)
return render_group_representation(TagGroupRepr.one(group), version,
body: parsed.fetch(:compatibility_body),
status: :created)
end
page = if title.include?(':')
ApplicationRecord.transaction do
tag_name = TagName.find_or_create_by!(language_code: 'ja', name: title) do |name|
@@ -168,6 +179,8 @@ class WikiPagesController < ApplicationController
render_validation_error e.record
rescue ActiveRecord::RecordNotUnique
render_record_not_unique
rescue TagGroupMarkdownParser::InvalidDocument => error
render_unprocessable_entity(error.message)
end
def update
@@ -180,7 +193,26 @@ class WikiPagesController < ApplicationController
return render_unprocessable_entity('タイトルは必須です.', field: :title) if title.blank?
return render_unprocessable_entity('本文は必須です.', field: :body) if body.blank?
page = WikiPage.find(params[:id])
group = TagGroup.find_by(id: params[:id])
if title.start_with?(TagGroupRepr::PREFIX)
return head :not_found unless group
name = title.delete_prefix(TagGroupRepr::PREFIX)
parsed = TagGroupMarkdownParser.parse(body:, group:)
TagGroupOperation.update!(group:, name:, **parsed, actor: current_user,
require_compatibility: true)
return head :ok
end
page = WikiPage.find_by(id: params[:id])
if legacy_group_page?(page)
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
@@ -197,11 +229,17 @@ class WikiPagesController < ApplicationController
page.tag_name.update!(name: title) if title != old_title
message = params[:message].presence
Wiki::Commit.content!(page:,
body:,
created_user: current_user,
message:,
base_revision_id:)
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
if tag && title != old_title
tag.reload
@@ -210,6 +248,12 @@ class WikiPagesController < ApplicationController
end
head :ok
rescue ActiveRecord::RecordInvalid => e
render_validation_error e.record
rescue ActiveRecord::RecordNotUnique
render_record_not_unique
rescue TagGroupMarkdownParser::InvalidDocument => error
render_unprocessable_entity(error.message)
end
def changes
@@ -253,6 +297,26 @@ class WikiPagesController < ApplicationController
private
def legacy_group_page? page
return false unless page
return true if page.title.start_with?(TagGroupRepr::PREFIX)
prefix = ApplicationRecord.sanitize_sql_like(TagGroupRepr::PREFIX)
page.wiki_versions.where('title LIKE ?', "#{ prefix }%").exists?
end
def legacy_update_identified? page, title, group
return false unless page
return true if page.title == title
return false if title == group.name
namespace = page.title.split(':', 2)
return true if namespace.size == 2 && title.start_with?("#{ namespace.first }:")
base = params[:base_revision_id].presence
base && page.wiki_revisions.exists?(id: base)
end
def render_tag_group group
version = if params[:version].present?
group_version(group, params[:version])
@@ -274,8 +338,8 @@ class WikiPagesController < ApplicationController
TagGroupMarkdownRenderer.render(representation)
end
def render_group_representation representation, version
body = TagGroupMarkdownRenderer.render(representation)
def render_group_representation representation, version, body: nil, status: :ok
body ||= TagGroupMarkdownRenderer.render(representation)
versions = TagGroupVersion.where(tag_group_id: version.tag_group_id)
pred = versions.find_by(version_no: version.version_no - 1)&.id
succ = versions.find_by(version_no: version.version_no + 1)&.id
@@ -288,7 +352,7 @@ class WikiPagesController < ApplicationController
'revision_id' => version.id,
'pred' => pred,
'succ' => succ,
'updated_at' => updated_at }
'updated_at' => updated_at }, status:
rescue TagGroupMarkdownRenderer::UnsupportedStructure => error
render_unprocessable_entity(error.message)
end