Skip to content

Commit bd7f0b0

Browse files
ClearlyClairehiyuki2578
authored andcommitted
Add domain block notes (mastodon#11515)
* Add database columns for adding notes to domain blocks/restrctions * Add admin UI to set private and public comments when blocking a domain * Add text for private and public comments on domain blocks * Show domain block comments in admin UI * Add comments to the domain block undo page * Make UnblockDomainService more robust regarding upgraded domain blocks * Allow editing domain blocks * Rename button from “undo domain block” to “view domain block” in account admin UI * Change test to unsilence silenced users from upgraded blocks
1 parent a300206 commit bd7f0b0

17 files changed

Lines changed: 138 additions & 34 deletions

app/controllers/admin/domain_blocks_controller.rb

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
22

33
module Admin
44
class DomainBlocksController < BaseController
5-
before_action :set_domain_block, only: [:show, :destroy]
5+
before_action :set_domain_block, only: [:show, :destroy, :edit, :update]
66

77
def new
88
authorize :domain_block, :create?
99
@domain_block = DomainBlock.new(domain: params[:_domain])
1010
end
1111

12+
def edit
13+
authorize :domain_block, :create?
14+
end
15+
1216
def create
1317
authorize :domain_block, :create?
1418

@@ -35,6 +39,22 @@ def create
3539
end
3640
end
3741

42+
def update
43+
authorize :domain_block, :create?
44+
45+
@domain_block.update(update_params)
46+
47+
severity_changed = @domain_block.severity_changed?
48+
49+
if @domain_block.save
50+
DomainBlockWorker.perform_async(@domain_block.id, severity_changed)
51+
log_action :create, @domain_block
52+
redirect_to admin_instances_path(limited: '1'), notice: I18n.t('admin.domain_blocks.created_msg')
53+
else
54+
render :edit
55+
end
56+
end
57+
3858
def show
3959
authorize @domain_block, :show?
4060
end
@@ -52,8 +72,12 @@ def set_domain_block
5272
@domain_block = DomainBlock.find(params[:id])
5373
end
5474

75+
def update_params
76+
params.require(:domain_block).permit(:severity, :reject_media, :reject_reports, :private_comment, :public_comment)
77+
end
78+
5579
def resource_params
56-
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports)
80+
params.require(:domain_block).permit(:domain, :severity, :reject_media, :reject_reports, :private_comment, :public_comment)
5781
end
5882
end
5983
end

app/controllers/admin/instances_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ def show
2121
@blocks_count = Block.where(target_account: Account.where(domain: params[:id])).count
2222
@available = DeliveryFailureTracker.available?(Account.select(:shared_inbox_url).where(domain: params[:id]).first&.shared_inbox_url)
2323
@media_storage = MediaAttachment.where(account: Account.where(domain: params[:id])).sum(:file_file_size)
24+
@private_comment = @domain_block&.private_comment
25+
@public_comment = @domain_block&.public_comment
2426
end
2527

2628
private

app/models/domain_block.rb

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33
#
44
# Table name: domain_blocks
55
#
6-
# id :bigint(8) not null, primary key
7-
# domain :string default(""), not null
8-
# created_at :datetime not null
9-
# updated_at :datetime not null
10-
# severity :integer default("silence")
11-
# reject_media :boolean default(FALSE), not null
12-
# reject_reports :boolean default(FALSE), not null
6+
# id :bigint(8) not null, primary key
7+
# domain :string default(""), not null
8+
# created_at :datetime not null
9+
# updated_at :datetime not null
10+
# severity :integer default("silence")
11+
# reject_media :boolean default(FALSE), not null
12+
# reject_reports :boolean default(FALSE), not null
13+
# private_comment :text
14+
# public_comment :text
1315
#
1416

1517
class DomainBlock < ApplicationRecord

app/services/block_domain_service.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,22 @@
33
class BlockDomainService < BaseService
44
attr_reader :domain_block
55

6-
def call(domain_block)
6+
def call(domain_block, update = false)
77
@domain_block = domain_block
88
process_domain_block!
9+
process_retroactive_updates! if update
910
end
1011

1112
private
1213

14+
def process_retroactive_updates!
15+
# If the domain block severity has been changed, undo the appropriate limitations
16+
scope = Account.by_domain_and_subdomains(domain_block.domain)
17+
18+
scope.where(silenced_at: domain_block.created_at).in_batches.update_all(silenced_at: nil) unless domain_block.silence?
19+
scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil) unless domain_block.suspend?
20+
end
21+
1322
def process_domain_block!
1423
clear_media! if domain_block.reject_media?
1524

app/services/unblock_domain_service.rb

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,9 @@ def call(domain_block)
1010
end
1111

1212
def process_retroactive_updates
13-
blocked_accounts.in_batches.update_all(update_options) unless domain_block.noop?
14-
end
15-
16-
def blocked_accounts
1713
scope = Account.by_domain_and_subdomains(domain_block.domain)
1814

19-
if domain_block.silence?
20-
scope.where(silenced_at: @domain_block.created_at)
21-
else
22-
scope.where(suspended_at: @domain_block.created_at)
23-
end
24-
end
25-
26-
def update_options
27-
{ domain_block_impact => nil }
28-
end
29-
30-
def domain_block_impact
31-
domain_block.silence? ? :silenced_at : :suspended_at
15+
scope.where(silenced_at: domain_block.created_at).in_batches.update_all(silenced_at: nil) unless domain_block.noop?
16+
scope.where(suspended_at: domain_block.created_at).in_batches.update_all(suspended_at: nil) if domain_block.suspend?
3217
end
3318
end

app/views/admin/accounts/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@
174174

175175
- unless @account.local?
176176
- if DomainBlock.where(domain: @account.domain).exists?
177-
= link_to t('admin.domain_blocks.undo'), admin_instance_path(@account.domain), class: 'button'
177+
= link_to t('admin.domain_blocks.view'), admin_instance_path(@account.domain), class: 'button'
178178
- else
179179
= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path(_domain: @account.domain), class: 'button button--destructive'
180180

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
- content_for :header_tags do
2+
= javascript_pack_tag 'admin', integrity: true, async: true, crossorigin: 'anonymous'
3+
4+
- content_for :page_title do
5+
= t('admin.domain_blocks.edit')
6+
7+
= simple_form_for @domain_block, url: admin_domain_block_path(@domain_block), method: :put do |f|
8+
= render 'shared/error_messages', object: @domain_block
9+
10+
.fields-row
11+
.fields-row__column.fields-row__column-6.fields-group
12+
= f.input :domain, wrapper: :with_label, label: t('admin.domain_blocks.domain'), hint: t('admin.domain_blocks.new.hint'), required: true, readonly: true, disabled: true
13+
14+
.fields-row__column.fields-row__column-6.fields-group
15+
= f.input :severity, collection: DomainBlock.severities.keys, wrapper: :with_label, include_blank: false, label_method: lambda { |type| t("admin.domain_blocks.new.severity.#{type}") }, hint: t('admin.domain_blocks.new.severity.desc_html')
16+
17+
.fields-group
18+
= f.input :reject_media, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_media'), hint: I18n.t('admin.domain_blocks.reject_media_hint')
19+
20+
.fields-group
21+
= f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint')
22+
23+
.field-group
24+
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6
25+
26+
.field-group
27+
= f.input :public_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.public_comment'), hint: t('admin.domain_blocks.public_comment_hint'), rows: 6
28+
29+
.actions
30+
= f.button :button, t('generic.save_changes'), type: :submit

app/views/admin/domain_blocks/new.html.haml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,11 @@
2020
.fields-group
2121
= f.input :reject_reports, as: :boolean, wrapper: :with_label, label: I18n.t('admin.domain_blocks.reject_reports'), hint: I18n.t('admin.domain_blocks.reject_reports_hint')
2222

23+
.field-group
24+
= f.input :private_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.private_comment'), hint: t('admin.domain_blocks.private_comment_hint'), rows: 6
25+
26+
.field-group
27+
= f.input :public_comment, wrapper: :with_label, label: I18n.t('admin.domain_blocks.public_comment'), hint: t('admin.domain_blocks.public_comment_hint'), rows: 6
28+
2329
.actions
2430
= f.button :button, t('.create'), type: :submit

app/views/admin/domain_blocks/show.html.haml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
- content_for :page_title do
22
= t('admin.domain_blocks.show.title', domain: @domain_block.domain)
33

4+
- if @domain_block.private_comment.present?
5+
.speech-bubble
6+
.speech-bubble__bubble
7+
= simple_format(h(@domain_block.private_comment))
8+
.speech-bubble__owner= t 'admin.instances.private_comment'
9+
10+
- if @domain_block.public_comment.present?
11+
.speech-bubble
12+
.speech-bubble__bubble
13+
= simple_format(h(@domain_block.public_comment))
14+
.speech-bubble__owner= t 'admin.instances.public_comment'
15+
416
= simple_form_for @domain_block, url: admin_domain_block_path(@domain_block), method: :delete do |f|
517

618
- unless (@domain_block.noop?)

app/views/admin/instances/show.html.haml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,18 @@
3131
= fa_icon 'times'
3232
.dashboard__counters__label= t 'admin.instances.delivery_available'
3333

34+
- if @private_comment.present?
35+
.speech-bubble
36+
.speech-bubble__bubble
37+
= simple_format(h(@private_comment))
38+
.speech-bubble__owner= t 'admin.instances.private_comment'
39+
40+
- if @public_comment.present?
41+
.speech-bubble
42+
.speech-bubble__bubble
43+
= simple_format(h(@public_comment))
44+
.speech-bubble__owner= t 'admin.instances.public_comment'
45+
3446
%hr.spacer/
3547

3648
%div{ style: 'overflow: hidden' }
@@ -41,6 +53,7 @@
4153
- if @domain_allow
4254
= link_to t('admin.domain_allows.undo'), admin_domain_allow_path(@domain_allow), class: 'button button--destructive', data: { confirm: t('admin.accounts.are_you_sure'), method: :delete }
4355
- elsif @domain_block
56+
= link_to t('admin.domain_blocks.edit'), edit_admin_domain_block_path(@domain_block), class: 'button'
4457
= link_to t('admin.domain_blocks.undo'), admin_domain_block_path(@domain_block), class: 'button'
4558
- else
4659
= link_to t('admin.domain_blocks.add_new'), new_admin_domain_block_path(_domain: @instance.domain), class: 'button'

0 commit comments

Comments
 (0)