Skip to content

Commit

Permalink
Wip: メール通知や設定のテストなど
Browse files Browse the repository at this point in the history
  • Loading branch information
kmycode committed Oct 9, 2023
1 parent 9bd5cc2 commit 4500be5
Show file tree
Hide file tree
Showing 24 changed files with 138 additions and 25 deletions.
6 changes: 3 additions & 3 deletions app/controllers/admin/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,17 +89,17 @@ def set_domain_block

def update_params
params.require(:domain_block).permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag,
:reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end

def resource_params
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag,
:reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end

def form_domain_block_batch_params
params.require(:form_domain_block_batch).permit(domain_blocks_attributes: [:enabled, :domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media,
:reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous])
:reject_send_sensitive, :reject_hashtag, :reject_straight_follow, :reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous])
end

def action_from_button
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/api/v1/admin/domain_blocks_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ def filtered_domain_blocks

def domain_block_params
params.permit(:severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_reports, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow,
:reject_new_follow, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end

def insert_pagination_headers
Expand Down Expand Up @@ -103,6 +103,6 @@ def pagination_params(core_params)

def resource_params
params.permit(:domain, :severity, :reject_media, :reject_favourite, :reject_reply, :reject_reply_exclude_followers, :reject_send_not_public_searchability, :reject_send_public_unlisted, :reject_send_dissubscribable, :reject_send_media, :reject_send_sensitive, :reject_hashtag, :reject_straight_follow,
:reject_new_follow, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
:reject_new_follow, :reject_friend, :detect_invalid_subscription, :reject_reports, :private_comment, :public_comment, :obfuscate, :hidden, :hidden_anonymous)
end
end
16 changes: 14 additions & 2 deletions app/lib/activitypub/activity/follow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,12 @@ def request_follow_for_friend
@friend = FriendDomain.create!(domain: @account.domain, passive_state: :pending, passive_follow_activity_id: @json['id'])
end

# Send acception at after_commit of models/friend_domain.rb when unlocked is true
friend.accept! if already_accepted
if already_accepted || friend.unlocked || Setting.unlocked_friend
friend.accept!
else
# Notify for admin even if unlocked
notify_staff_about_pending_friend_server!
end
end

def friend
Expand Down Expand Up @@ -101,4 +105,12 @@ def proxyable_software?
def instance_info
@instance_info ||= InstanceInfo.find_by(domain: @account.domain)
end

def notify_staff_about_pending_friend_server!
User.those_who_can(:manage_federation).includes(:account).find_each do |u|
next unless u.allows_pending_friend_server_emails?

AdminMailer.with(recipient: u.account).new_pending_friend_server(friend).deliver_later
end
end
end
8 changes: 8 additions & 0 deletions app/mailers/admin_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ def new_pending_account(user)
end
end

def new_pending_friend_server(friend_server)
@friend = friend_server

locale_for_account(@me) do
mail subject: default_i18n_subject(instance: @instance, domain: @friend.domain)
end
end

def new_trends(links, tags, statuses)
@links = links
@tags = tags
Expand Down
4 changes: 4 additions & 0 deletions app/models/concerns/has_user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,10 @@ def allows_pending_account_emails?
settings['notification_emails.pending_account']
end

def allows_pending_friend_server_emails?
settings['notification_emails.pending_friend_server']
end

def allows_appeal_emails?
settings['notification_emails.appeal']
end
Expand Down
2 changes: 2 additions & 0 deletions app/models/form/admin_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Form::AdminSettings
enable_emoji_reaction
check_lts_version_only
enable_public_unlisted_visibility
unlocked_friend
).freeze

INTEGER_KEYS = %i(
Expand Down Expand Up @@ -76,6 +77,7 @@ class Form::AdminSettings
enable_emoji_reaction
check_lts_version_only
enable_public_unlisted_visibility
unlocked_friend
).freeze

UPLOAD_KEYS = %i(
Expand Down
5 changes: 0 additions & 5 deletions app/models/friend_domain.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ class FriendDomain < ApplicationRecord

before_destroy :ensure_disabled
after_commit :set_default_inbox_url
after_commit :auto_accept_when_unlocked

def mutual?
i_am_accepted? && they_are_accepted?
Expand Down Expand Up @@ -161,8 +160,4 @@ def ensure_disabled
def set_default_inbox_url
self.inbox_url = default_inbox_url if inbox_url.blank?
end

def auto_accept_when_unlocked
accept! if unlocked && they_are_pending?
end
end
1 change: 1 addition & 0 deletions app/models/user_settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class KeyError < Error; end
setting :follow_request, default: true
setting :report, default: true
setting :pending_account, default: true
setting :pending_friend_server, default: true
setting :trends, default: true
setting :appeal, default: true
setting :software_updates, default: 'critical', in: %w(none critical patch all)
Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/domain_blocks/edit.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
.fields-group
= f.input :reject_new_follow, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_new_follow'), hint: I18n.t('admin.domain_blocks.reject_new_follow_hint')

.fields-group
= f.input :reject_friend, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_friend'), hint: I18n.t('admin.domain_blocks.reject_friend_hint')

.fields-group
= f.input :detect_invalid_subscription, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.detect_invalid_subscription'), hint: I18n.t('admin.domain_blocks.detect_invalid_subscription_hint')

Expand Down
3 changes: 3 additions & 0 deletions app/views/admin/domain_blocks/new.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
.fields-group
= f.input :reject_new_follow, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_new_follow'), hint: I18n.t('admin.domain_blocks.reject_new_follow_hint')

.fields-group
= f.input :reject_friend, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_friend'), hint: I18n.t('admin.domain_blocks.reject_friend_hint')

.fields-group
= f.input :detect_invalid_subscription, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.detect_invalid_subscription'), hint: I18n.t('admin.domain_blocks.detect_invalid_subscription_hint')

Expand Down
5 changes: 5 additions & 0 deletions app/views/admin/settings/discovery/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
.fields-group
= f.input :enable_public_unlisted_visibility, as: :boolean, wrapper: :with_label, kmyblue: true, hint: false

%h4= t('admin.settings.discovery.friend_servers')

.fields-group
= f.input :unlocked_friend, as: :boolean, wrapper: :with_label, kmyblue: true, hint: false

%h4= t('admin.settings.discovery.publish_statistics')

.fields-group
Expand Down
5 changes: 5 additions & 0 deletions app/views/admin_mailer/new_pending_friend_server.text.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<%= raw t('application_mailer.salutation', name: display_name(@me)) %>

<%= raw t('admin_mailer.new_pending_friend_server.body', domain: @friend.domain) %>

<%= raw t('application_mailer.view')%> <%= admin_friend_servers_url %>
3 changes: 2 additions & 1 deletion app/views/settings/preferences/notifications/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@
.fields-group
= ff.input :always_send_emails, wrapper: :with_label, label: I18n.t('simple_form.labels.defaults.setting_always_send_emails'), hint: I18n.t('simple_form.hints.defaults.setting_always_send_emails')

- if current_user.can?(:manage_reports, :manage_appeals, :manage_users, :manage_taxonomies) || (SoftwareUpdate.check_enabled? && current_user.can?(:view_devops))
- if current_user.can?(:manage_reports, :manage_appeals, :manage_users, :manage_taxonomies, :manage_federation) || (SoftwareUpdate.check_enabled? && current_user.can?(:view_devops))
%h4= t 'notifications.administration_emails'

.fields-group
= ff.input :'notification_emails.report', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.report') if current_user.can?(:manage_reports)
= ff.input :'notification_emails.appeal', as: :boolean, wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.appeal') if current_user.can?(:manage_appeals)
= ff.input :'notification_emails.pending_account', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.pending_account') if current_user.can?(:manage_users)
= ff.input :'notification_emails.pending_friend_server', as: :boolean, wrapper: :with_label, kmyblue: true, label: I18n.t('simple_form.labels.notification_emails.pending_friend_server') if current_user.can?(:manage_federation)
= ff.input :'notification_emails.trends', wrapper: :with_label, label: I18n.t('simple_form.labels.notification_emails.trending_tag') if current_user.can?(:manage_taxonomies)

- if SoftwareUpdate.check_enabled? && current_user.can?(:view_devops)
Expand Down
7 changes: 7 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,8 @@ en:
public_comment_hint: Comment about this domain limitation for the general public, if advertising the list of domain limitations is enabled.
reject_favourite: Reject favorites
reject_favourite_hint: Reject favorites or emoji-reaction in the future
reject_friend: Reject friend server applications
reject_friend_hint: Reject friend server application in the future
reject_hashtag: Reject hashtags
reject_hashtag_hint: Reject hashtags in the future
reject_media: Reject media files
Expand Down Expand Up @@ -520,6 +522,7 @@ en:
limited_federation_mode_description_html: You can chose whether to allow federation with this domain.
policies:
reject_favourite: Reject favorite
reject_friend: Reject friend server application
reject_hashtag: Reject hashtags
reject_media: Reject media
reject_new_follow: Reject follows
Expand Down Expand Up @@ -810,6 +813,7 @@ en:
discovery:
emoji_reactions: Stamp
follow_recommendations: Follow recommendations
friend_servers: Friend servers
preamble: Surfacing interesting content is instrumental in onboarding new users who may not know anyone Mastodon. Control how various discovery features work on your server.
profile_directory: Profile directory
public_timelines: Public timelines
Expand Down Expand Up @@ -1050,6 +1054,9 @@ en:
new_pending_account:
body: The details of the new account are below. You can approve or reject this application.
subject: New account up for review on %{instance} (%{username})
new_pending_friend_server:
body: The new friend server %{domain} is waiting for your review. You can approve or reject this application.
subject: New friend server up for review on %{instance} (%{domain})
new_report:
body: "%{reporter} has reported %{target}"
body_remote: Someone from %{domain} has reported %{target}
Expand Down
7 changes: 7 additions & 0 deletions config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,8 @@ ja:
public_comment_hint: ドメインブロックの公開を有効にしている場合、このコメントも公開されます。
reject_favourite: お気に入り、スタンプを拒否
reject_favourite_hint: 今後のお気に入り、スタンプを拒否します。停止とは無関係です
reject_friend: フレンドサーバー申請を拒否
reject_friend_hint: 今後のフレンドサーバー申請を全て拒否します。停止とは無関係です
reject_hashtag: ハッシュタグを拒否
reject_hashtag_hint: ハッシュタグで検索できなくなり、トレンドにも影響しなくなります。停止とは無関係です
reject_media: メディアファイルを拒否
Expand Down Expand Up @@ -514,6 +516,7 @@ ja:
policies:
detect_invalid_subscription: 購読のプライバシーなし
reject_favourite: お気に入りを拒否
reject_friend: フレンドサーバー申請を拒否
reject_hashtag: ハッシュタグを拒否
reject_media: メディアを拒否する
reject_new_follow: 新規フォローを拒否
Expand Down Expand Up @@ -807,6 +810,7 @@ ja:
discovery:
emoji_reactions: スタンプ
follow_recommendations: おすすめフォロー
friend_servers: フレンドサーバー
preamble: Mastodon を知らないユーザーを取り込むには、興味深いコンテンツを浮上させることが重要です。サーバー上で様々なディスカバリー機能がどのように機能するかを制御します。
profile_directory: ディレクトリ
public_timelines: 公開タイムライン
Expand Down Expand Up @@ -1043,6 +1047,9 @@ ja:
new_pending_account:
body: 新しいアカウントの詳細は以下の通りです。この申請を承認または却下することができます。
subject: '%{instance}で新しいアカウント (%{username}) が承認待ちです'
new_pending_friend_server:
body: 新しいフレンドサーバー %{domain} の申請が届いています。この申請を承認または却下することができます。
subject: '%{instance}で新しいフレンドサーバー (%{domain}) が承認待ちです'
new_report:
body: "%{reporter}さんが%{target}さんを通報しました"
body_remote: "%{domain}の誰かが%{target}さんを通報しました"
Expand Down
2 changes: 2 additions & 0 deletions config/locales/simple_form.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ en:
trendable_by_default: Allow trends without prior review
trends: Enable trends
trends_as_landing_page: Use trends as the landing page
unlocked_friend: Accept all friend server follows automatically
interactions:
must_be_follower: Block notifications from non-followers
must_be_following: Block notifications from people you don't follow
Expand All @@ -378,6 +379,7 @@ en:
follow_request: Someone requested to follow you
mention: Someone mentioned you
pending_account: New account needs review
pending_friend_server: New friend server needs review
reblog: Someone boosted your post
report: New report is submitted
software_updates:
Expand Down
2 changes: 2 additions & 0 deletions config/locales/simple_form.ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,7 @@ ja:
trendable_by_default: 審査前のトレンドの掲載を許可する
trends: トレンドを有効にする
trends_as_landing_page: 新規登録画面にトレンドを表示する
unlocked_friend: 全てのフレンドサーバー申請を自動承認する
interactions:
must_be_follower: フォロワー以外からの通知をブロック
must_be_following: フォローしていないユーザーからの通知をブロック
Expand All @@ -393,6 +394,7 @@ ja:
follow_request: フォローリクエストを受けた時
mention: 返信が来た時
pending_account: 新しいアカウントの承認が必要な時
pending_friend_server: 新しいフレンドサーバーの承認が必要な時
reblog: 投稿がブーストされた時
report: 新しい通報が送信された時
software_updates:
Expand Down
1 change: 1 addition & 0 deletions config/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
s.item :custom_emojis, safe_join([fa_icon('smile-o fw'), t('admin.custom_emojis.title')]), admin_custom_emojis_path, highlights_on: %r{/admin/custom_emojis}, if: -> { current_user.can?(:manage_custom_emojis) }
s.item :webhooks, safe_join([fa_icon('inbox fw'), t('admin.webhooks.title')]), admin_webhooks_path, highlights_on: %r{/admin/webhooks}, if: -> { current_user.can?(:manage_webhooks) }
s.item :relays, safe_join([fa_icon('exchange fw'), t('admin.relays.title')]), admin_relays_path, highlights_on: %r{/admin/relays}, if: -> { !limited_federation_mode? && current_user.can?(:manage_federation) }
s.item :friend_servers, safe_join([fa_icon('users fw'), t('admin.friend_servers.title')]), admin_friend_servers_path, highlights_on: %r{/admin/friend_servers}, if: -> { current_user.can?(:manage_federation) }
end

n.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_path, link_html: { target: 'sidekiq' }, if: -> { current_user.can?(:view_devops) }
Expand Down
1 change: 1 addition & 0 deletions config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ defaults: &defaults
enable_emoji_reaction: true
check_lts_version_only: true
enable_public_unlisted_visibility: true
unlocked_friend: false

development:
<<: *defaults
Expand Down
2 changes: 1 addition & 1 deletion lib/tasks/tests.rake
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ namespace :tests do
INSERT INTO "settings"
(id, thing_type, thing_id, var, value, created_at, updated_at)
VALUES
(3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\ntrending_tag: true\nappeal: true\n', now(), now()),
(3, 'User', 1, 'notification_emails', E'--- !ruby/hash:ActiveSupport::HashWithIndifferentAccess\nfollow: false\nreblog: true\nfavourite: true\nmention: false\nfollow_request: true\ndigest: true\nreport: true\npending_account: false\npending_friend_server: true\ntrending_tag: true\nappeal: true\n', now(), now()),
(4, 'User', 1, 'trends', E'--- false\n', now(), now());
INSERT INTO "accounts"
Expand Down
Loading

0 comments on commit 4500be5

Please sign in to comment.