about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/controllers/admin/reported_statuses_controller.rb18
-rw-r--r--app/controllers/admin/reports_controller.rb60
-rw-r--r--app/helpers/admin/accounts_helper.rb2
-rw-r--r--app/models/report.rb4
-rw-r--r--app/views/admin/reports/index.html.haml4
-rw-r--r--app/views/admin/reports/show.html.haml12
6 files changed, 72 insertions, 28 deletions
diff --git a/app/controllers/admin/reported_statuses_controller.rb b/app/controllers/admin/reported_statuses_controller.rb
new file mode 100644
index 000000000..7ae420dfe
--- /dev/null
+++ b/app/controllers/admin/reported_statuses_controller.rb
@@ -0,0 +1,18 @@
+# frozen_string_literal: true
+
+module Admin
+  class ReportedStatusesController < BaseController
+    def destroy
+      status = Status.find params[:id]
+
+      RemovalWorker.perform_async(status.id)
+      redirect_to admin_report_path(report)
+    end
+
+    private
+
+    def report
+      Report.find(params[:report_id])
+    end
+  end
+end
diff --git a/app/controllers/admin/reports_controller.rb b/app/controllers/admin/reports_controller.rb
index 3c3082318..4a6f9ea7f 100644
--- a/app/controllers/admin/reports_controller.rb
+++ b/app/controllers/admin/reports_controller.rb
@@ -5,37 +5,59 @@ module Admin
     before_action :set_report, except: [:index]
 
     def index
-      @reports = Report.includes(:account, :target_account).order('id desc').page(params[:page])
-      @reports = params[:action_taken].present? ? @reports.resolved : @reports.unresolved
+      @reports = filtered_reports.page(params[:page])
     end
 
-    def show
-      @statuses = Status.where(id: @report.status_ids)
-    end
+    def show; end
 
-    def resolve
-      @report.update(action_taken: true, action_taken_by_account_id: current_account.id)
+    def update
+      process_report
       redirect_to admin_report_path(@report)
     end
 
-    def suspend
-      Admin::SuspensionWorker.perform_async(@report.target_account.id)
-      Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id)
-      redirect_to admin_report_path(@report)
+    private
+
+    def process_report
+      case params[:outcome].to_s
+      when 'resolve'
+        @report.update(action_taken_by_current_attributes)
+      when 'suspend'
+        Admin::SuspensionWorker.perform_async(@report.target_account.id)
+        resolve_all_target_account_reports
+      when 'silence'
+        @report.target_account.update(silenced: true)
+        resolve_all_target_account_reports
+      else
+        raise ActiveRecord::RecordNotFound
+      end
     end
 
-    def silence
-      @report.target_account.update(silenced: true)
-      Report.unresolved.where(target_account: @report.target_account).update_all(action_taken: true, action_taken_by_account_id: current_account.id)
-      redirect_to admin_report_path(@report)
+    def action_taken_by_current_attributes
+      { action_taken: true, action_taken_by_account_id: current_account.id }
     end
 
-    def remove
-      RemovalWorker.perform_async(params[:status_id])
-      redirect_to admin_report_path(@report)
+    def resolve_all_target_account_reports
+      unresolved_reports_for_target_account.update_all(
+        action_taken_by_current_attributes
+      )
     end
 
-    private
+    def unresolved_reports_for_target_account
+      Report.where(
+        target_account: @report.target_account
+      ).unresolved
+    end
+
+    def filtered_reports
+      filtering_scope.order('id desc').includes(
+        :account,
+        :target_account
+      )
+    end
+
+    def filtering_scope
+      params[:resolved].present? ? Report.resolved : Report.unresolved
+    end
 
     def set_report
       @report = Report.find(params[:id])
diff --git a/app/helpers/admin/accounts_helper.rb b/app/helpers/admin/accounts_helper.rb
index 6cda77819..497abf80d 100644
--- a/app/helpers/admin/accounts_helper.rb
+++ b/app/helpers/admin/accounts_helper.rb
@@ -2,7 +2,7 @@
 
 module Admin::AccountsHelper
   def filter_params(more_params)
-    params.permit(:local, :remote, :by_domain, :silenced, :suspended, :recent).merge(more_params)
+    params.permit(:local, :remote, :by_domain, :silenced, :suspended, :recent, :resolved).merge(more_params)
   end
 
   def filter_link_to(text, more_params)
diff --git a/app/models/report.rb b/app/models/report.rb
index fd8e46aac..54157ed8c 100644
--- a/app/models/report.rb
+++ b/app/models/report.rb
@@ -7,4 +7,8 @@ class Report < ApplicationRecord
 
   scope :unresolved, -> { where(action_taken: false) }
   scope :resolved,   -> { where(action_taken: true) }
+
+  def statuses
+    Status.where(id: status_ids)
+  end
 end
diff --git a/app/views/admin/reports/index.html.haml b/app/views/admin/reports/index.html.haml
index d5deec8f6..7309c719a 100644
--- a/app/views/admin/reports/index.html.haml
+++ b/app/views/admin/reports/index.html.haml
@@ -5,8 +5,8 @@
   .filter-subset
     %strong= t('admin.reports.status')
     %ul
-      %li= filter_link_to t('admin.reports.unresolved'), action_taken: nil
-      %li= filter_link_to t('admin.reports.resolved'), action_taken: '1'
+      %li= filter_link_to t('admin.reports.unresolved'), resolved: nil
+      %li= filter_link_to t('admin.reports.resolved'), resolved: '1'
 
 = form_tag do
 
diff --git a/app/views/admin/reports/show.html.haml b/app/views/admin/reports/show.html.haml
index a7430f396..5391d99a8 100644
--- a/app/views/admin/reports/show.html.haml
+++ b/app/views/admin/reports/show.html.haml
@@ -14,15 +14,15 @@
   \:
   = @report.comment.presence || t('reports.comment.none')
 
-- unless @statuses.empty?
+- unless @report.statuses.empty?
   %hr/
 
-  - @statuses.each do |status|
+  - @report.statuses.each do |status|
     .report-status
       .activity-stream.activity-stream-headless
         .entry= render partial: 'stream_entries/simple_status', locals: { status: status }
       .report-status__actions
-        = link_to remove_admin_report_path(@report, status_id: status.id), method: :post, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: t('admin.reports.delete') do
+        = link_to admin_report_reported_status_path(@report, status), method: :delete, class: 'icon-button', style: 'font-size: 24px; width: 24px; height: 24px', title: t('admin.reports.delete') do
           = fa_icon 'trash'
 
 - if !@report.action_taken?
@@ -30,10 +30,10 @@
 
   %div{ style: 'overflow: hidden' }
     %div{ style: 'float: right' }
-      = link_to t('admin.reports.silence_account'), silence_admin_report_path(@report), method: :post, class: 'button'
-      = link_to t('admin.reports.suspend_account'), suspend_admin_report_path(@report), method: :post, class: 'button'
+      = link_to t('admin.reports.silence_account'), admin_report_path(@report, outcome: 'silence'), method: :put, class: 'button'
+      = link_to t('admin.reports.suspend_account'), admin_report_path(@report, outcome: 'suspend'), method: :put, class: 'button'
     %div{ style: 'float: left' }
-      = link_to t('admin.reports.mark_as_resolved'), resolve_admin_report_path(@report), method: :post, class: 'button'
+      = link_to t('admin.reports.mark_as_resolved'), admin_report_path(@report, outcome: 'resolve'), method: :put, class: 'button'
 - elsif !@report.action_taken_by_account.nil?
   %hr/