このコミットが含まれているのは:
2026-03-08 02:03:29 +09:00
コミット 6330a05148
11個のファイルの変更54行の追加43行の削除
+27 -3
ファイルの表示
@@ -64,9 +64,7 @@ class Tag < ApplicationRecord
(self.tag_name ||= build_tag_name).name = val
end
def has_wiki
wiki_page.present?
end
def has_wiki = wiki_page.present?
def self.tagme
@tagme ||= find_or_create_by_tag_name!('タグ希望', category: :meta)
@@ -142,6 +140,32 @@ class Tag < ApplicationRecord
retry
end
def self.merge_tags target_tag, source_tags
target_tag => Tag
Tag.transaction do
Array(source_tags).compact.uniq.each do |st|
st => Tag
next if st == target_tag
st.post_tags.find_each do |pt|
begin
pt.update!(tag: target_tag)
rescue ActiveRecord::RecordNotUnique
pt.discard_by!(nil)
end
end
tag_name = st.tag_name
st.destroy!
tag_name.update!(canonical: target_tag.tag_name)
end
end
target_tag
end
private
def nico_tag_name_must_start_with_nico
+9 -15
ファイルの表示
@@ -1,29 +1,23 @@
class User < ApplicationRecord
enum :role, { guest: 'guest', member: 'member', admin: 'admin' }
enum :role, guest: 'guest', member: 'member', admin: 'admin'
validates :name, length: { maximum: 255 }
validates :inheritance_code, presence: true, length: { maximum: 64 }
validates :role, presence: true, inclusion: { in: roles.keys }
validates :banned, inclusion: { in: [true, false] }
has_many :posts
has_many :created_posts,
class_name: 'Post', foreign_key: :uploaded_user_id, dependent: :nullify
has_many :settings
has_many :user_ips, dependent: :destroy
has_many :ip_addresses, through: :user_ips
has_many :user_post_views, dependent: :destroy
has_many :viewed_posts, through: :user_post_views, source: :post
has_many :created_wiki_pages, class_name: 'WikiPage', foreign_key: 'created_user_id', dependent: :nullify
has_many :updated_wiki_pages, class_name: 'WikiPage', foreign_key: 'updated_user_id', dependent: :nullify
has_many :created_wiki_pages,
class_name: 'WikiPage', foreign_key: :created_user_id, dependent: :nullify
has_many :updated_wiki_pages,
class_name: 'WikiPage', foreign_key: :updated_user_id, dependent: :nullify
def viewed? post
user_post_views.exists? post_id: post.id
end
def member?
['member', 'admin'].include?(role)
end
def admin?
role == 'admin'
end
def viewed?(post) = user_post_views.exists?(post_id: post.id)
def gte_member? = member? || admin?
end
+1 -1
ファイルの表示
@@ -8,7 +8,7 @@ class WikiLine < ApplicationRecord
sha = Digest::SHA256.hexdigest(body)
now = Time.current
upsert({ sha256: sha, body:, created_at: now, updated_at: now })
upsert(sha256: sha, body:, created_at: now, updated_at: now)
find_by!(sha256: sha)
end
+6 -13
ファイルの表示
@@ -14,17 +14,13 @@ class WikiPage < ApplicationRecord
belongs_to :tag_name
validates :tag_name, presence: true
def title
tag_name.name
end
def title = tag_name.name
def title= val
(self.tag_name ||= build_tag_name).name = val
end
def current_revision
wiki_revisions.order(id: :desc).first
end
def current_revision = wiki_revisions.order(id: :desc).first
def body
rev = current_revision
@@ -49,11 +45,8 @@ class WikiPage < ApplicationRecord
page
end
def pred_revision_id revision_id
wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id)
end
def succ_revision_id revision_id
wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id)
end
def pred_revision_id(revision_id) =
wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id)
def succ_revision_id(revision_id) =
wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id)
end
+1 -1
ファイルの表示
@@ -7,7 +7,7 @@ class WikiRevision < ApplicationRecord
has_many :wiki_revision_lines, dependent: :delete_all
has_many :wiki_lines, through: :wiki_revision_lines
enum :kind, { content: 0, redirect: 1 }
enum :kind, content: 0, redirect: 1
validates :kind, presence: true
validates :lines_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }