Add enable_block_emoji_reaction_settings setting

This commit is contained in:
KMY 2023-07-24 11:46:21 +09:00
parent a1cfab66cf
commit bf0d6fd2f5
7 changed files with 21 additions and 11 deletions

View file

@ -336,6 +336,7 @@ class Account < ApplicationRecord
end
def emoji_reactions_must_following?
return false unless Setting.enable_block_emoji_reaction_settings
return user&.settings&.[]('emoji_reactions.must_be_following') || false if user.present?
return settings['emoji_reactions_must_be_following'] || false if settings.present?
@ -343,6 +344,7 @@ class Account < ApplicationRecord
end
def emoji_reactions_must_follower?
return false unless Setting.enable_block_emoji_reaction_settings
return user&.settings&.[]('emoji_reactions.must_be_follower') || false if user.present?
return settings['emoji_reaction_must_be_follower'] || false if settings.present?
@ -350,6 +352,7 @@ class Account < ApplicationRecord
end
def emoji_reactions_deny_from_all?
return false unless Setting.enable_block_emoji_reaction_settings
return user&.settings&.[]('emoji_reactions.deny_from_all') || false if user.present?
return settings['emoji_reaction_deny_from_all'] || false if settings.present?

View file

@ -35,6 +35,7 @@ class Form::AdminSettings
status_page_url
captcha_enabled
ng_words
enable_block_emoji_reaction_settings
).freeze
INTEGER_KEYS = %i(
@ -55,6 +56,7 @@ class Form::AdminSettings
noindex
require_invite_text
captcha_enabled
enable_block_emoji_reaction_settings
).freeze
UPLOAD_KEYS = %i(

View file

@ -8,7 +8,7 @@ class EmojiReactionValidator < ActiveModel::Validator
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.blank? && !unicode_emoji?(emoji_reaction.name)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.unrecognized_emoji')) if emoji_reaction.custom_emoji_id.present? && disabled_custom_emoji?(emoji_reaction.custom_emoji)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_from_all?(emoji_reaction) || non_follower?(emoji_reaction) || non_following?(emoji_reaction)
emoji_reaction.errors.add(:name, I18n.t('reactions.errors.banned')) if deny_emoji_reactions?(emoji_reaction)
end
private
@ -21,24 +21,23 @@ class EmojiReactionValidator < ActiveModel::Validator
custom_emoji.nil? ? false : custom_emoji.disabled
end
def deny_from_all?(emoji_reaction)
def deny_emoji_reactions?(emoji_reaction)
return false unless Setting.enable_block_emoji_reaction_settings
return false if emoji_reaction.status.account.user.nil?
return false if emoji_reaction.status.account_id == emoji_reaction.account_id
deny_from_all?(emoji_reaction) || non_follower?(emoji_reaction) || non_following?(emoji_reaction)
end
def deny_from_all?(emoji_reaction)
emoji_reaction.status.account.user.settings['emoji_reactions.deny_from_all']
end
def non_following?(emoji_reaction)
return false if emoji_reaction.status.account.user.nil?
return false if emoji_reaction.status.account_id == emoji_reaction.account_id
emoji_reaction.status.account.user.settings['emoji_reactions.must_be_following'] && !emoji_reaction.status.account.following?(emoji_reaction.account)
end
def non_follower?(emoji_reaction)
return false if emoji_reaction.status.account.user.nil?
return false if emoji_reaction.status.account_id == emoji_reaction.account_id
emoji_reaction.status.account.user.settings['emoji_reactions.must_be_follower'] && !emoji_reaction.account.following?(emoji_reaction.status.account)
end
end

View file

@ -10,5 +10,8 @@
.fields-group
= f.input :ng_words, wrapper: :with_label, as: :text, input_html: { rows: 12 }, label: t('admin.ng_words.keywords')
.fields-group
= f.input :enable_block_emoji_reaction_settings, wrapper: :with_label, as: :boolean, label: t('admin.ng_words.enable_block_emoji_reaction_settings')
.actions
= f.button :button, t('generic.save_changes'), type: :submit

View file

@ -33,9 +33,10 @@
= ff.input :'interactions.must_be_follower', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_follower')
= ff.input :'interactions.must_be_following', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following')
= ff.input :'interactions.must_be_following_dm', wrapper: :with_label, label: I18n.t('simple_form.labels.interactions.must_be_following_dm')
= ff.input :'emoji_reactions.must_be_follower', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_follower')
= ff.input :'emoji_reactions.must_be_following', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_following')
= ff.input :'emoji_reactions.deny_from_all', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.deny_from_all')
- if Setting.enable_block_emoji_reaction_settings
= ff.input :'emoji_reactions.must_be_follower', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_follower')
= ff.input :'emoji_reactions.must_be_following', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.must_be_following')
= ff.input :'emoji_reactions.deny_from_all', kmyblue: true, wrapper: :with_label, label: I18n.t('simple_form.labels.emoji_reactions.deny_from_all')
= f.simple_fields_for :settings, current_user.settings do |ff|
.fields-group

View file

@ -596,6 +596,7 @@ en:
media_attachments:
title: Media attachments
ng_words:
enable_block_emoji_reaction_settings: Enable block emoji reactions settings for users
keywords: Reject keywords
title: NG words and against spams
relationships:

View file

@ -595,6 +595,7 @@ ja:
media_attachments:
title: 投稿された画像
ng_words:
enable_block_emoji_reaction_settings: 各ユーザーにスタンプ機能のブロック設定項目を解放する
keywords: 投稿できないキーワード
title: NGワードとスパム
relationships: