Add ng words for post/update

This commit is contained in:
KMY 2023-07-24 10:38:36 +09:00
parent d4602118fb
commit c553275381
12 changed files with 110 additions and 2 deletions

View file

@ -0,0 +1,15 @@
# frozen_string_literal: true
class Admin::NgWord
class << self
def reject?(text)
ng_words.any? { |word| text.include?(word) }
end
private
def ng_words
Setting.ng_words
end
end
end

View file

@ -34,6 +34,7 @@ class Form::AdminSettings
backups_retention_period
status_page_url
captcha_enabled
ng_words
).freeze
INTEGER_KEYS = %i(
@ -61,6 +62,10 @@ class Form::AdminSettings
mascot
).freeze
STRING_ARRAY_KEYS = %i(
ng_words
).freeze
attr_accessor(*KEYS)
validates :registrations_mode, inclusion: { in: %w(open approved none) }, if: -> { defined?(@registrations_mode) }
@ -80,6 +85,8 @@ class Form::AdminSettings
stored_value = if UPLOAD_KEYS.include?(key)
SiteUpload.where(var: key).first_or_initialize(var: key)
elsif STRING_ARRAY_KEYS.include?(key)
Setting.public_send(key)&.join("\n") || ''
else
Setting.public_send(key)
end
@ -122,6 +129,8 @@ class Form::AdminSettings
value == '1'
elsif INTEGER_KEYS.include?(key)
value.blank? ? value : Integer(value)
elsif STRING_ARRAY_KEYS.include?(key)
value&.split(/\r\n|\r|\n/)&.filter(&:present?)&.uniq || []
else
value
end

View file

@ -36,6 +36,7 @@ class UserRole < ApplicationRecord
manage_roles: (1 << 17),
manage_user_access: (1 << 18),
delete_user_data: (1 << 19),
manage_ng_words: (1 << 30),
}.freeze
module Flags
@ -61,6 +62,7 @@ class UserRole < ApplicationRecord
manage_blocks
manage_taxonomies
manage_invites
manage_ng_words
).freeze,
administration: %w(