about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2022-03-02 18:57:08 +0100
committerGitHub <noreply@github.com>2022-03-02 18:57:08 +0100
commit02b8d63fcef2d30e2514111ec89308a9435dd2ed (patch)
tree4cf66422b9aa934e810d320b61ba8d545975c694 /app
parent462a6f7d721fa0717c5627fd0f0d73ee9ec5a675 (diff)
Fix report category not being saved in REST API (#17682)
Diffstat (limited to 'app')
-rw-r--r--app/controllers/api/v1/reports_controller.rb12
-rw-r--r--app/services/report_service.rb14
2 files changed, 10 insertions, 16 deletions
diff --git a/app/controllers/api/v1/reports_controller.rb b/app/controllers/api/v1/reports_controller.rb
index 052d70cc8..8ff6c8fe5 100644
--- a/app/controllers/api/v1/reports_controller.rb
+++ b/app/controllers/api/v1/reports_controller.rb
@@ -10,9 +10,7 @@ class Api::V1::ReportsController < Api::BaseController
     @report = ReportService.new.call(
       current_account,
       reported_account,
-      status_ids: reported_status_ids,
-      comment: report_params[:comment],
-      forward: report_params[:forward]
+      report_params
     )
 
     render json: @report, serializer: REST::ReportSerializer
@@ -20,14 +18,6 @@ class Api::V1::ReportsController < Api::BaseController
 
   private
 
-  def reported_status_ids
-    reported_account.statuses.with_discarded.find(status_ids).pluck(:id)
-  end
-
-  def status_ids
-    Array(report_params[:status_ids])
-  end
-
   def reported_account
     Account.find(report_params[:account_id])
   end
diff --git a/app/services/report_service.rb b/app/services/report_service.rb
index caf99ab6e..9d784c341 100644
--- a/app/services/report_service.rb
+++ b/app/services/report_service.rb
@@ -6,10 +6,10 @@ class ReportService < BaseService
   def call(source_account, target_account, options = {})
     @source_account = source_account
     @target_account = target_account
-    @status_ids     = options.delete(:status_ids) || []
-    @comment        = options.delete(:comment) || ''
-    @category       = options.delete(:category) || 'other'
-    @rule_ids       = options.delete(:rule_ids)
+    @status_ids     = options.delete(:status_ids).presence || []
+    @comment        = options.delete(:comment).presence || ''
+    @category       = options.delete(:category).presence || 'other'
+    @rule_ids       = options.delete(:rule_ids).presence
     @options        = options
 
     raise ActiveRecord::RecordNotFound if @target_account.suspended?
@@ -26,7 +26,7 @@ class ReportService < BaseService
   def create_report!
     @report = @source_account.reports.create!(
       target_account: @target_account,
-      status_ids: @status_ids,
+      status_ids: reported_status_ids,
       comment: @comment,
       uri: @options[:uri],
       forwarded: forward?,
@@ -56,6 +56,10 @@ class ReportService < BaseService
     !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward])
   end
 
+  def reported_status_ids
+    @target_account.statuses.with_discarded.find(Array(@status_ids)).pluck(:id)
+  end
+
   def payload
     Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account))
   end