Skip to content

Commit

Permalink
Add moderation warnings (mastodon#9519)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Gargron authored and hiyuki2578 committed Oct 2, 2019
1 parent 0fc2702 commit da24629
Show file tree
Hide file tree
Showing 72 changed files with 682 additions and 536 deletions.
36 changes: 36 additions & 0 deletions app/controllers/admin/account_actions_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# frozen_string_literal: true

module Admin
class AccountActionsController < BaseController
before_action :set_account

def new
@account_action = Admin::AccountAction.new(type: params[:type], report_id: params[:report_id], send_email_notification: true)
@warning_presets = AccountWarningPreset.all
end

def create
account_action = Admin::AccountAction.new(resource_params)
account_action.target_account = @account
account_action.current_account = current_account

account_action.save!

if account_action.with_report?
redirect_to admin_report_path(account_action.report)
else
redirect_to admin_account_path(@account.id)
end
end

private

def set_account
@account = Account.find(params[:account_id])
end

def resource_params
params.require(:admin_account_action).permit(:type, :report_id, :warning_preset_id, :text, :send_email_notification)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ def create
else
@account = @account_moderation_note.target_account
@moderation_notes = @account.targeted_moderation_notes.latest
@warnings = @account.targeted_account_warnings.latest.custom

render template: 'admin/accounts/show'
end
Expand Down
23 changes: 16 additions & 7 deletions app/controllers/admin/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Admin
class AccountsController < BaseController
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :disable, :memorialize]
before_action :set_account, only: [:show, :subscribe, :unsubscribe, :redownload, :remove_avatar, :remove_header, :enable, :memorialize]
before_action :require_remote_account!, only: [:subscribe, :unsubscribe, :redownload]
before_action :require_local_account!, only: [:enable, :disable, :memorialize]
before_action :require_local_account!, only: [:enable, :memorialize]

def index
authorize :account, :index?
Expand All @@ -13,8 +13,10 @@ def index

def show
authorize @account, :show?

@account_moderation_note = current_account.account_moderation_notes.new(target_account: @account)
@moderation_notes = @account.targeted_moderation_notes.latest
@moderation_notes = @account.targeted_moderation_notes.latest
@warnings = @account.targeted_account_warnings.latest.custom
end

def subscribe
Expand Down Expand Up @@ -43,10 +45,17 @@ def enable
redirect_to admin_account_path(@account.id)
end

def disable
authorize @account.user, :disable?
@account.user.disable!
log_action :disable, @account.user
def unsilence
authorize @account, :unsilence?
@account.unsilence!
log_action :unsilence, @account
redirect_to admin_account_path(@account.id)
end

def unsuspend
authorize @account, :unsuspend?
@account.unsuspend!
log_action :unsuspend, @account
redirect_to admin_account_path(@account.id)
end

Expand Down
79 changes: 23 additions & 56 deletions app/controllers/admin/reports_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,75 +13,42 @@ def show
authorize @report, :show?

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

def update
def assign_to_self
authorize @report, :update?
process_report

if @report.action_taken?
redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
else
redirect_to admin_report_path(@report)
end
@report.update!(assigned_account_id: current_account.id)
log_action :assigned_to_self, @report
redirect_to admin_report_path(@report)
end

private

def process_report
case params[:outcome].to_s
when 'assign_to_self'
@report.update!(assigned_account_id: current_account.id)
log_action :assigned_to_self, @report
when 'unassign'
@report.update!(assigned_account_id: nil)
log_action :unassigned, @report
when 'reopen'
@report.unresolve!
log_action :reopen, @report
when 'resolve'
@report.resolve!(current_account)
log_action :resolve, @report
when 'disable'
@report.resolve!(current_account)
@report.target_account.user.disable!

log_action :resolve, @report
log_action :disable, @report.target_account.user

resolve_all_target_account_reports
when 'silence'
@report.resolve!(current_account)
@report.target_account.update!(silenced: true)

log_action :resolve, @report
log_action :silence, @report.target_account

resolve_all_target_account_reports
else
raise ActiveRecord::RecordNotFound
end

@report.reload
def unassign
authorize @report, :update?
@report.update!(assigned_account_id: nil)
log_action :unassigned, @report
redirect_to admin_report_path(@report)
end

def resolve_all_target_account_reports
unresolved_reports_for_target_account.update_all(action_taken: true, action_taken_by_account_id: current_account.id)
def reopen
authorize @report, :update?
@report.unresolve!
log_action :reopen, @report
redirect_to admin_report_path(@report)
end

def unresolved_reports_for_target_account
Report.where(
target_account: @report.target_account
).unresolved
def resolve
authorize @report, :update?
@report.resolve!(current_account)
log_action :resolve, @report
redirect_to admin_reports_path, notice: I18n.t('admin.reports.resolved_msg')
end

private

def filtered_reports
ReportFilter.new(filter_params).results.order(id: :desc).includes(
:account,
:target_account
)
ReportFilter.new(filter_params).results.order(id: :desc).includes(:account, :target_account)
end

def filter_params
Expand Down
27 changes: 0 additions & 27 deletions app/controllers/admin/silences_controller.rb

This file was deleted.

60 changes: 0 additions & 60 deletions app/controllers/admin/suspensions_controller.rb

This file was deleted.

58 changes: 58 additions & 0 deletions app/controllers/admin/warning_presets_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# frozen_string_literal: true

module Admin
class WarningPresetsController < BaseController
before_action :set_warning_preset, except: [:index, :create]

def index
authorize :account_warning_preset, :index?

@warning_presets = AccountWarningPreset.all
@warning_preset = AccountWarningPreset.new
end

def create
authorize :account_warning_preset, :create?

@warning_preset = AccountWarningPreset.new(warning_preset_params)

if @warning_preset.save
redirect_to admin_warning_presets_path
else
@warning_presets = AccountWarningPreset.all
render :index
end
end

def edit
authorize @warning_preset, :update?
end

def update
authorize @warning_preset, :update?

if @warning_preset.update(warning_preset_params)
redirect_to admin_warning_presets_path
else
render :edit
end
end

def destroy
authorize @warning_preset, :destroy?

@warning_preset.destroy!
redirect_to admin_warning_presets_path
end

private

def set_warning_preset
@warning_preset = AccountWarningPreset.find(params[:id])
end

def warning_preset_params
params.require(:account_warning_preset).permit(:text)
end
end
end
7 changes: 6 additions & 1 deletion app/helpers/admin/action_logs_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ def linkable_log_target(record)
link_to record.domain, "https://#{record.domain}"
when 'Status'
link_to record.account.acct, TagManager.instance.url_for(record)
when 'AccountWarning'
link_to record.target_account.acct, admin_account_path(record.target_account_id)
end
end

Expand All @@ -34,6 +36,7 @@ def log_target_from_history(type, attributes)
link_to attributes['domain'], "https://#{attributes['domain']}"
when 'Status'
tmp_status = Status.new(attributes.except('reblogs_count', 'favourites_count'))

if tmp_status.account
link_to tmp_status.account&.acct || "##{tmp_status.account_id}", admin_account_path(tmp_status.account_id)
else
Expand Down Expand Up @@ -81,6 +84,8 @@ def icon_for_log(log)
'envelope'
when 'Status'
'pencil'
when 'AccountWarning'
'warning'
end
end

Expand All @@ -104,6 +109,6 @@ def class_for_log_icon(log)
private

def opposite_verbs?(log)
%w(DomainBlock EmailDomainBlock).include?(log.target_type)
%w(DomainBlock EmailDomainBlock AccountWarning).include?(log.target_type)
end
end
4 changes: 4 additions & 0 deletions app/javascript/images/icon_flag.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/javascript/images/mailer/icon_warning.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions app/javascript/styles/mailer.scss
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,10 @@ h5 {
background: $success-green;
}

&.alert-icon td {
background: $error-red;
}

img {
max-width: 32px;
width: 32px;
Expand Down
4 changes: 4 additions & 0 deletions app/javascript/styles/mastodon/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,10 @@ a.name-tag,
border-left-color: lighten($error-red, 12%);
}

&.warning {
border-left-color: $gold-star;
}

&__bubble {
padding: 16px;
padding-left: 14px;
Expand Down
Loading

0 comments on commit da24629

Please sign in to comment.