このコミットが含まれているのは:
2026-03-08 02:03:29 +09:00
コミット 6330a05148
11個のファイルの変更54行の追加43行の削除
+2 -2
ファイルの表示
@@ -17,7 +17,7 @@ class DeerjikistsController < ApplicationController
def update def update
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
platform = params[:platform].to_s.strip platform = params[:platform].to_s.strip
code = params[:code].to_s.strip code = params[:code].to_s.strip
@@ -34,7 +34,7 @@ class DeerjikistsController < ApplicationController
def destroy def destroy
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
platform = params[:platform].to_s.strip platform = params[:platform].to_s.strip
code = params[:code].to_s.strip code = params[:code].to_s.strip
+1 -1
ファイルの表示
@@ -25,7 +25,7 @@ class NicoTagsController < ApplicationController
def update def update
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
id = params[:id].to_i id = params[:id].to_i
+2 -2
ファイルの表示
@@ -78,7 +78,7 @@ class PostsController < ApplicationController
def create def create
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
# TODO: サイトに応じて thumbnail_base 設定 # TODO: サイトに応じて thumbnail_base 設定
title = params[:title].presence title = params[:title].presence
@@ -122,7 +122,7 @@ class PostsController < ApplicationController
def update def update
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
title = params[:title].presence title = params[:title].presence
tag_names = params[:tags].to_s.split(' ') tag_names = params[:tags].to_s.split(' ')
+1 -1
ファイルの表示
@@ -109,7 +109,7 @@ class TagsController < ApplicationController
def update def update
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
name = params[:name].presence name = params[:name].presence
category = params[:category].presence category = params[:category].presence
+2 -2
ファイルの表示
@@ -83,7 +83,7 @@ class WikiPagesController < ApplicationController
def create def create
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
name = params[:title]&.strip name = params[:title]&.strip
body = params[:body].to_s body = params[:body].to_s
@@ -105,7 +105,7 @@ class WikiPagesController < ApplicationController
def update def update
return head :unauthorized unless current_user return head :unauthorized unless current_user
return head :forbidden unless current_user.member? return head :forbidden unless current_user.gte_member?
title = params[:title]&.strip title = params[:title]&.strip
body = params[:body].to_s body = params[:body].to_s
+27 -3
ファイルの表示
@@ -64,9 +64,7 @@ class Tag < ApplicationRecord
(self.tag_name ||= build_tag_name).name = val (self.tag_name ||= build_tag_name).name = val
end end
def has_wiki def has_wiki = wiki_page.present?
wiki_page.present?
end
def self.tagme def self.tagme
@tagme ||= find_or_create_by_tag_name!('タグ希望', category: :meta) @tagme ||= find_or_create_by_tag_name!('タグ希望', category: :meta)
@@ -142,6 +140,32 @@ class Tag < ApplicationRecord
retry retry
end 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 private
def nico_tag_name_must_start_with_nico def nico_tag_name_must_start_with_nico
+9 -15
ファイルの表示
@@ -1,29 +1,23 @@
class User < ApplicationRecord 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 :name, length: { maximum: 255 }
validates :inheritance_code, presence: true, length: { maximum: 64 } validates :inheritance_code, presence: true, length: { maximum: 64 }
validates :role, presence: true, inclusion: { in: roles.keys } validates :role, presence: true, inclusion: { in: roles.keys }
validates :banned, inclusion: { in: [true, false] } 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 :settings
has_many :user_ips, dependent: :destroy has_many :user_ips, dependent: :destroy
has_many :ip_addresses, through: :user_ips has_many :ip_addresses, through: :user_ips
has_many :user_post_views, dependent: :destroy has_many :user_post_views, dependent: :destroy
has_many :viewed_posts, through: :user_post_views, source: :post 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 :created_wiki_pages,
has_many :updated_wiki_pages, class_name: 'WikiPage', foreign_key: 'updated_user_id', dependent: :nullify 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 def viewed?(post) = user_post_views.exists?(post_id: post.id)
user_post_views.exists? post_id: post.id def gte_member? = member? || admin?
end
def member?
['member', 'admin'].include?(role)
end
def admin?
role == 'admin'
end
end end
+1 -1
ファイルの表示
@@ -8,7 +8,7 @@ class WikiLine < ApplicationRecord
sha = Digest::SHA256.hexdigest(body) sha = Digest::SHA256.hexdigest(body)
now = Time.current 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) find_by!(sha256: sha)
end end
+4 -11
ファイルの表示
@@ -14,17 +14,13 @@ class WikiPage < ApplicationRecord
belongs_to :tag_name belongs_to :tag_name
validates :tag_name, presence: true validates :tag_name, presence: true
def title def title = tag_name.name
tag_name.name
end
def title= val def title= val
(self.tag_name ||= build_tag_name).name = val (self.tag_name ||= build_tag_name).name = val
end end
def current_revision def current_revision = wiki_revisions.order(id: :desc).first
wiki_revisions.order(id: :desc).first
end
def body def body
rev = current_revision rev = current_revision
@@ -49,11 +45,8 @@ class WikiPage < ApplicationRecord
page page
end end
def pred_revision_id revision_id def pred_revision_id(revision_id) =
wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id) wiki_revisions.where('id < ?', revision_id).order(id: :desc).limit(1).pick(:id)
end def succ_revision_id(revision_id) =
def succ_revision_id revision_id
wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id) wiki_revisions.where('id > ?', revision_id).order(id: :asc).limit(1).pick(:id)
end
end end
+1 -1
ファイルの表示
@@ -7,7 +7,7 @@ class WikiRevision < ApplicationRecord
has_many :wiki_revision_lines, dependent: :delete_all has_many :wiki_revision_lines, dependent: :delete_all
has_many :wiki_lines, through: :wiki_revision_lines 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 :kind, presence: true
validates :lines_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 } validates :lines_count, numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+2 -2
ファイルの表示
@@ -106,8 +106,8 @@ RSpec.describe 'Tags API', type: :request do
end end
before do before do
allow(member_user).to receive(:member?).and_return(true) allow(member_user).to receive(:gte_member?).and_return(true)
allow(non_member_user).to receive(:member?).and_return(false) allow(non_member_user).to receive(:gte_member?).and_return(false)
end end
describe "PATCH /tags/:id" do describe "PATCH /tags/:id" do