Skip to content

Commit da24629

Browse files
Gargronhiyuki2578
authored andcommitted
Add moderation warnings (mastodon#9519)
* Add moderation warnings Replace individual routes for disabling, silencing, and suspending a user, as well as the report update route, with a unified account action controller that allows you to select an action (none, disable, silence, suspend) as well as whether it should generate an e-mail notification with optional custom text. That notification, with the optional custom text, is saved as a warning. Additionally, there are warning presets you can configure to save time when performing the above. * Use Account#local_username_and_domain
1 parent 0fc2702 commit da24629

72 files changed

Lines changed: 682 additions & 536 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# frozen_string_literal: true
2+
3+
module Admin
4+
class AccountActionsController < BaseController
5+
before_action :set_account
6+
7+
def new
8+
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true)
9+
@warning_presets = AccountWarningPreset.all
10+
end
11+
12+
def create
13+
account_action = Admin::AccountAction.new(resource_params)
14+
account_action.target_account = @account
15+
account_action.current_account = current_account
16+
17+
account_action.save!
18+
19+
if account_action.with_report?
20+
redirect_to admin_report_path(account_action.report)
21+
else
22+
redirect_to admin_account_path(@account.id)
23+
end
24+
end
25+
26+
private
27+
28+
def set_account
29+
@account = Account.find(params[:account_id])
30+
end
31+
32+
def resource_params
33+
params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification)
34+
end
35+
end
36+
end

app/controllers/admin/account_moderation_notes_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ def create
1414
else
1515
@account = @account_moderation_note.target_account
1616
@moderation_notes = @account.targeted_moderation_notes.latest
17+
@warnings = @account.targeted_account_warnings.latest.custom
1718

1819
render template: 'admin/accounts/show'
1920
end

app/controllers/admin/accounts_controller.rb

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33
module Admin
44
class AccountsController < BaseController
5-
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :disable, :memorialize]
5+
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :memorialize]
66
before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
7-
before_action :require_local_account!, only: [:enable, :disable, :memorialize]
7+
before_action :require_local_account!, only: [:enable, :memorialize]
88

99
def index
1010
authorize :account, :index?
@@ -13,8 +13,10 @@ def index
1313

1414
def show
1515
authorize @account, :show?
16+
1617
@account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
17-
@moderation_notes = @account.targeted_moderation_notes.latest
18+
@moderation_notes = @account.targeted_moderation_notes.latest
19+
@warnings = @account.targeted_account_warnings.latest.custom
1820
end
1921

2022
def subscribe
@@ -43,10 +45,17 @@ def enable
4345
redirect_to admin_account_path(@account.id)
4446
end
4547

46-
def disable
47-
authorize @account.user, :disable?
48-
@account.user.disable!
49-
log_action :disable, @account.user
48+
def unsilence
49+
authorize @account, :unsilence?
50+
@account.unsilence!
51+
log_action :unsilence, @account
52+
redirect_to admin_account_path(@account.id)
53+
end
54+
55+
def unsuspend
56+
authorize @account, :unsuspend?
57+
@account.unsuspend!
58+
log_action :unsuspend, @account
5059
redirect_to admin_account_path(@account.id)
5160
end
5261

app/controllers/admin/reports_controller.rb

Lines changed: 23 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -13,75 +13,42 @@ def show
1313
authorize @report, :show?
1414

1515
@report_note = @report.notes.new
16-
@report_notes = (@report.notes.latest + @report.history).sort_by(&:created_at)
16+
@report_notes = (@report.notes.latest + @report.history + @report.target_account.targeted_account_warnings.latest.custom).sort_by(&:created_at)
1717
@form = Form::StatusBatch.new
1818
end
1919

20-
def update
20+
def assign_to_self
2121
authorize @report, :update?
22-
process_report
23-
24-
if @report.action_taken?
25-
redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
26-
else
27-
redirect_to admin_report_path(@report)
28-
end
22+
@report.update!(assigned_account_id: current_account.id)
23+
log_action :assigned_to_self, @report
24+
redirect_to admin_report_path(@report)
2925
end
3026

31-
private
32-
33-
def process_report
34-
case params[:outcome].to_s
35-
when 'assign_to_self'
36-
@report.update!(assigned_account_id: current_account.id)
37-
log_action :assigned_to_self, @report
38-
when 'unassign'
39-
@report.update!(assigned_account_id: nil)
40-
log_action :unassigned, @report
41-
when 'reopen'
42-
@report.unresolve!
43-
log_action :reopen, @report
44-
when 'resolve'
45-
@report.resolve!(current_account)
46-
log_action :resolve, @report
47-
when 'disable'
48-
@report.resolve!(current_account)
49-
@report.target_account.user.disable!
50-
51-
log_action :resolve, @report
52-
log_action :disable, @report.target_account.user
53-
54-
resolve_all_target_account_reports
55-
when 'silence'
56-
@report.resolve!(current_account)
57-
@report.target_account.update!(silenced: true)
58-
59-
log_action :resolve, @report
60-
log_action :silence, @report.target_account
61-
62-
resolve_all_target_account_reports
63-
else
64-
raise ActiveRecord::RecordNotFound
65-
end
66-
67-
@report.reload
27+
def unassign
28+
authorize @report, :update?
29+
@report.update!(assigned_account_id: nil)
30+
log_action :unassigned, @report
31+
redirect_to admin_report_path(@report)
6832
end
6933

70-
def resolve_all_target_account_reports
71-
unresolved_reports_for_target_account.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
34+
def reopen
35+
authorize @report, :update?
36+
@report.unresolve!
37+
log_action :reopen, @report
38+
redirect_to admin_report_path(@report)
7239
end
7340

74-
def unresolved_reports_for_target_account
75-
Report.where(
76-
target_account: @report.target_account
77-
).unresolved
41+
def resolve
42+
authorize @report, :update?
43+
@report.resolve!(current_account)
44+
log_action :resolve, @report
45+
redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
7846
end
7947

48+
private
49+
8050
def filtered_reports
81-
ReportFilter.new(filter_params).results.order(id: :desc).includes(
82-
:account,
83-
:target_account
84-
)
51+
ReportFilter.new(filter_params).results.order(id: :desc).includes(:account, :target_account)
8552
end
8653

8754
def filter_params

app/controllers/admin/silences_controller.rb

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/controllers/admin/suspensions_controller.rb

Lines changed: 0 additions & 60 deletions
This file was deleted.
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
# frozen_string_literal: true
2+
3+
module Admin
4+
class WarningPresetsController < BaseController
5+
before_action :set_warning_preset, except: [:index, :create]
6+
7+
def index
8+
authorize :account_warning_preset, :index?
9+
10+
@warning_presets = AccountWarningPreset.all
11+
@warning_preset = AccountWarningPreset.new
12+
end
13+
14+
def create
15+
authorize :account_warning_preset, :create?
16+
17+
@warning_preset = AccountWarningPreset.new(warning_preset_params)
18+
19+
if @warning_preset.save
20+
redirect_to admin_warning_presets_path
21+
else
22+
@warning_presets = AccountWarningPreset.all
23+
render :index
24+
end
25+
end
26+
27+
def edit
28+
authorize @warning_preset, :update?
29+
end
30+
31+
def update
32+
authorize @warning_preset, :update?
33+
34+
if @warning_preset.update(warning_preset_params)
35+
redirect_to admin_warning_presets_path
36+
else
37+
render :edit
38+
end
39+
end
40+
41+
def destroy
42+
authorize @warning_preset, :destroy?
43+
44+
@warning_preset.destroy!
45+
redirect_to admin_warning_presets_path
46+
end
47+
48+
private
49+
50+
def set_warning_preset
51+
@warning_preset = AccountWarningPreset.find(params[:id])
52+
end
53+
54+
def warning_preset_params
55+
params.require(:account_warning_preset).permit(:text)
56+
end
57+
end
58+
end

app/helpers/admin/action_logs_helper.rb

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ def linkable_log_target(record)
2323
link_to record.domain, "https://#{record.domain}"
2424
when 'Status'
2525
link_to record.account.acct, TagManager.instance.url_for(record)
26+
when 'AccountWarning'
27+
link_to record.target_account.acct, admin_account_path(record.target_account_id)
2628
end
2729
end
2830

@@ -34,6 +36,7 @@ def log_target_from_history(type, attributes)
3436
link_to attributes['domain'], "https://#{attributes['domain']}"
3537
when 'Status'
3638
tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))
39+
3740
if tmp_status.account
3841
link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
3942
else
@@ -81,6 +84,8 @@ def icon_for_log(log)
8184
'envelope'
8285
when 'Status'
8386
'pencil'
87+
when 'AccountWarning'
88+
'warning'
8489
end
8590
end
8691

@@ -104,6 +109,6 @@ def class_for_log_icon(log)
104109
private
105110

106111
def opposite_verbs?(log)
107-
%w(DomainBlock EmailDomainBlock).include?(log.target_type)
112+
%w(DomainBlock EmailDomainBlock AccountWarning).include?(log.target_type)
108113
end
109114
end
Lines changed: 4 additions & 0 deletions
Loading
371 Bytes
Loading

0 commit comments

Comments
 (0)