summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2018-12-22 20:02:09 +0100
committerGitHub <noreply@github.com>2018-12-22 20:02:09 +0100
commit3c033c4352f8b156887cd7157b4a89c23a545838 (patch)
treefa6317223a0104abea84a10e6234a0beef316001
parent00862dcaff7cb918d29947accda1c01873a7ddeb (diff)
Add moderation warnings (#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
-rw-r--r--app/controllers/admin/account_actions_controller.rb36
-rw-r--r--app/controllers/admin/account_moderation_notes_controller.rb1
-rw-r--r--app/controllers/admin/accounts_controller.rb23
-rw-r--r--app/controllers/admin/reports_controller.rb79
-rw-r--r--app/controllers/admin/silences_controller.rb27
-rw-r--r--app/controllers/admin/suspensions_controller.rb60
-rw-r--r--app/controllers/admin/warning_presets_controller.rb58
-rw-r--r--app/helpers/admin/action_logs_helper.rb7
-rw-r--r--app/javascript/images/icon_flag.svg4
-rw-r--r--app/javascript/images/mailer/icon_warning.pngbin0 -> 371 bytes
-rw-r--r--app/javascript/styles/mailer.scss4
-rw-r--r--app/javascript/styles/mastodon/admin.scss4
-rw-r--r--app/mailers/user_mailer.rb12
-rw-r--r--app/models/account.rb8
-rw-r--r--app/models/account_warning.rb23
-rw-r--r--app/models/account_warning_preset.rb15
-rw-r--r--app/models/admin/account_action.rb134
-rw-r--r--app/models/concerns/account_associations.rb2
-rw-r--r--app/models/form/admin_suspension_confirmation.rb7
-rw-r--r--app/policies/account_policy.rb4
-rw-r--r--app/policies/account_warning_preset_policy.rb19
-rw-r--r--app/views/admin/account_actions/new.html.haml26
-rw-r--r--app/views/admin/account_warnings/_account_warning.html.haml6
-rw-r--r--app/views/admin/accounts/show.html.haml14
-rw-r--r--app/views/admin/reports/show.html.haml17
-rw-r--r--app/views/admin/suspensions/new.html.haml25
-rw-r--r--app/views/admin/warning_presets/edit.html.haml11
-rw-r--r--app/views/admin/warning_presets/index.html.haml30
-rw-r--r--app/views/user_mailer/warning.html.haml63
-rw-r--r--app/views/user_mailer/warning.text.erb9
-rw-r--r--app/views/user_mailer/welcome.text.erb2
-rw-r--r--config/locales/ar.yml5
-rw-r--r--config/locales/ast.yml2
-rw-r--r--config/locales/ca.yml6
-rw-r--r--config/locales/co.yml6
-rw-r--r--config/locales/cs.yml6
-rw-r--r--config/locales/cy.yml6
-rw-r--r--config/locales/da.yml6
-rw-r--r--config/locales/de.yml6
-rw-r--r--config/locales/el.yml6
-rw-r--r--config/locales/en.yml32
-rw-r--r--config/locales/eo.yml5
-rw-r--r--config/locales/es.yml6
-rw-r--r--config/locales/eu.yml6
-rw-r--r--config/locales/fa.yml6
-rw-r--r--config/locales/fr.yml6
-rw-r--r--config/locales/gl.yml6
-rw-r--r--config/locales/it.yml6
-rw-r--r--config/locales/ja.yml6
-rw-r--r--config/locales/ko.yml6
-rw-r--r--config/locales/nl.yml6
-rw-r--r--config/locales/oc.yml6
-rw-r--r--config/locales/pl.yml6
-rw-r--r--config/locales/pt-BR.yml6
-rw-r--r--config/locales/ru.yml6
-rw-r--r--config/locales/simple_form.en.yml19
-rw-r--r--config/locales/sk.yml6
-rw-r--r--config/locales/sr.yml6
-rw-r--r--config/routes.rb16
-rw-r--r--db/migrate/20181213184704_create_account_warnings.rb12
-rw-r--r--db/migrate/20181213185533_create_account_warning_presets.rb9
-rw-r--r--db/schema.rb21
-rw-r--r--spec/controllers/admin/accounts_controller_spec.rb52
-rw-r--r--spec/controllers/admin/reports_controller_spec.rb84
-rw-r--r--spec/controllers/admin/silences_controller_spec.rb33
-rw-r--r--spec/controllers/admin/suspensions_controller_spec.rb39
-rw-r--r--spec/fabricators/account_warning_fabricator.rb5
-rw-r--r--spec/fabricators/account_warning_preset_fabricator.rb3
-rw-r--r--spec/mailers/previews/user_mailer_preview.rb5
-rw-r--r--spec/models/account_warning_preset_spec.rb5
-rw-r--r--spec/models/account_warning_spec.rb5
-rw-r--r--spec/models/admin/account_action_spec.rb4
72 files changed, 682 insertions, 536 deletions
diff --git a/app/controllers/admin/account_actions_controller.rb b/app/controllers/admin/account_actions_controller.rb
new file mode 100644
index 00000000000..e847495f1b8
--- /dev/null
+++ b/app/controllers/admin/account_actions_controller.rb
@@ -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
diff --git a/app/controllers/admin/account_moderation_notes_controller.rb b/app/controllers/admin/account_moderation_notes_controller.rb
index 7d5b9bf52c8..44f6e34f80b 100644
--- a/app/controllers/admin/account_moderation_notes_controller.rb
+++ b/app/controllers/admin/account_moderation_notes_controller.rb
@@ -14,6 +14,7 @@ module Admin
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
diff --git a/app/controllers/admin/accounts_controller.rb b/app/controllers/admin/accounts_controller.rb
index 771302db807..10abd1e6aeb 100644
--- a/app/controllers/admin/accounts_controller.rb
+++ b/app/controllers/admin/accounts_controller.rb
@@ -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?
@@ -13,8 +13,10 @@ module Admin
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
@@ -43,10 +45,17 @@ module Admin
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
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb
index e97ddb9b647..f138376b2f7 100644
--- a/app/controllers/admin/reports_controller.rb
+++ b/app/controllers/admin/reports_controller.rb
@@ -13,75 +13,42 @@ module Admin
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
diff --git a/app/controllers/admin/silences_controller.rb b/app/controllers/admin/silences_controller.rb
deleted file mode 100644
index 4c06a9c0cc7..00000000000
--- a/app/controllers/admin/silences_controller.rb
+++ /dev/null
@@ -1,27 +0,0 @@
-# frozen_string_literal: true
-
-module Admin
- class SilencesController < BaseController
- before_action :set_account
-
- def create
- authorize @account, :silence?
- @account.update!(silenced: true)
- log_action :silence, @account
- redirect_to admin_accounts_path
- end
-
- def destroy
- authorize @account, :unsilence?
- @account.update!(silenced: false)
- log_action :unsilence, @account
- redirect_to admin_accounts_path
- end
-
- private
-
- def set_account
- @account = Account.find(params[:account_id])
- end
- end
-end
diff --git a/app/controllers/admin/suspensions_controller.rb b/app/controllers/admin/suspensions_controller.rb
deleted file mode 100644
index f9bbf36fb84..00000000000
--- a/app/controllers/admin/suspensions_controller.rb
+++ /dev/null
@@ -1,60 +0,0 @@
-# frozen_string_literal: true
-
-module Admin
- class SuspensionsController < BaseController
- before_action :set_account
-
- def new
- @suspension = Form::AdminSuspensionConfirmation.new(report_id: params[:report_id])
- end
-
- def create
- authorize @account, :suspend?