Skip to content

Commit

Permalink
Add: #30 ローカルユーザーからのスタンプに関するポリシー設定 (#354)
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode authored Dec 12, 2023
1 parent 3e8b475 commit 903b9ad
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 2 deletions.
5 changes: 4 additions & 1 deletion app/models/concerns/account/other_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ def emoji_reaction_policy

def show_emoji_reaction?(account)
return false unless Setting.enable_emoji_reaction
return true if local? && account&.local? && user.setting_slip_local_emoji_reaction

case emoji_reaction_policy
when :block
Expand Down Expand Up @@ -104,7 +105,9 @@ def public_settings
end

def public_settings_for_local
public_settings.merge(public_master_settings)
s = public_settings
s = s.merge({ 'emoji_reaction_policy' => 'allow' }) if local? && user&.setting_slip_local_emoji_reaction
s.merge(public_master_settings)
end
end
end
4 changes: 4 additions & 0 deletions app/models/concerns/user/has_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@ def setting_emoji_reaction_policy
settings['emoji_reaction_policy']
end

def setting_slip_local_emoji_reaction
settings['slip_local_emoji_reaction']
end

def setting_unfollow_modal
settings['web.unfollow_modal']
end
Expand Down
1 change: 1 addition & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class KeyError < Error; end
setting :stop_emoji_reaction_streaming, default: false
setting :emoji_reaction_streaming_notify_impl2, default: false
setting :emoji_reaction_policy, default: :allow, in: %w(allow outside_only followers_only following_only mutuals_only block)
setting :slip_local_emoji_reaction, default: false
setting :unsafe_limited_distribution, default: false
setting :dtl_force_visibility, default: :unchange, in: %w(unchange public public_unlisted unlisted)
setting :dtl_force_searchability, default: :unchange, in: %w(unchange public public_unlisted)
Expand Down
3 changes: 3 additions & 0 deletions app/views/settings/preferences/other/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
.fields-group.fields-row__column.fields-row__column-12
= ff.input :emoji_reaction_policy, kmyblue: true, collection: %w(allow outside_only followers_only following_only mutuals_only block), label_method: ->(item) { safe_join([t("simple_form.labels.defaults.setting_emoji_reaction_policy_items.#{item}")]) }, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', include_blank: false, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_emoji_reaction_policy'), hint: false, warning_hint: I18n.t('simple_form.hints.defaults.setting_emoji_reaction_policy')

.fields-group
= ff.input :slip_local_emoji_reaction, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.defaults.setting_slip_local_emoji_reaction')

- if @dtl_enabled

%h4= t 'preferences.dtl'
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,7 @@ en:
setting_show_quote_in_public: Show quotes in public timelines
setting_simple_timeline_menu: Reduce post menu on timeline
setting_single_ref_to_quote: Deliver single reference to other server as quote
setting_slip_local_emoji_reaction: Allow bypassing emoji reaction from local users
setting_stay_privacy: Not change privacy after post
setting_stop_emoji_reaction_streaming: Disable stamp streamings
setting_system_font_ui: Use system's default font
Expand Down
1 change: 1 addition & 0 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ ja:
setting_show_emoji_reaction_on_timeline: タイムライン上に他の人のつけたスタンプを表示する
setting_simple_timeline_menu: タイムライン上でメニューの項目を減らす
setting_single_ref_to_quote: 参照が1つしかない投稿は、他のサーバーには引用として配信する
setting_slip_local_emoji_reaction: ローカルユーザーに限って上記設定を無視してスタンプを許可する
setting_stay_privacy: 投稿時に公開範囲を保存する
setting_stop_emoji_reaction_streaming: スタンプのストリーミングを停止する
setting_system_font_ui: システムのデフォルトフォントを使う
Expand Down
18 changes: 17 additions & 1 deletion spec/models/account_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@

describe '#allow_emoji_reaction?' do
let(:policy) { :allow }
let(:reactioned) { Fabricate(:user, settings: { emoji_reaction_policy: policy }).account }
let(:allow_local) { false }
let(:reactioned) { Fabricate(:user, settings: { emoji_reaction_policy: policy, slip_local_emoji_reaction: allow_local }).account }
let(:followee) { Fabricate(:account) }
let(:follower) { Fabricate(:account) }
let(:mutual) { Fabricate(:account) }
Expand Down Expand Up @@ -411,6 +412,21 @@
end
end

context 'when policy is block but allow local only' do
let(:policy) { :block }
let(:allow_local) { true }
let(:local) { Fabricate(:user).account }
let(:remote) { Fabricate(:account, domain: 'example.com', uri: 'https://example.com/actor') }

it 'does not allow remote' do
expect(reactioned.allow_emoji_reaction?(remote)).to be false
end

it 'allows local' do
expect(reactioned.allow_emoji_reaction?(local)).to be true
end
end

context 'when reactioned is remote user' do
let(:reactioned) { Fabricate(:account, domain: 'foo.bar', uri: 'https://foo.bar/actor', settings: { emoji_reaction_policy: :following_only }) }

Expand Down

0 comments on commit 903b9ad

Please sign in to comment.