diff options
author | Eugen Rochko <eugen@zeonfederated.com> | 2022-02-10 00:10:16 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-02-10 00:10:16 +0100 |
commit | 2f8159baada8dcb59eb185732b8d9501401f8a83 (patch) | |
tree | 72dbe1639971ca8c5b7ebd1107d61781a4ae2dce /app | |
parent | 5533fa28b6cb6ca71775b716a515c1745f76bf02 (diff) |
Add `category` and `rule_ids` params to `POST /api/v1/reports` (#17492)
Diffstat (limited to 'app')
-rw-r--r-- | app/controllers/api/v1/reports_controller.rb | 2 | ||||
-rw-r--r-- | app/models/report.rb | 9 | ||||
-rw-r--r-- | app/services/report_service.rb | 12 |
3 files changed, 20 insertions, 3 deletions
diff --git a/app/controllers/api/v1/reports_controller.rb b/app/controllers/api/v1/reports_controller.rb index e10083d45..052d70cc8 100644 --- a/app/controllers/api/v1/reports_controller.rb +++ b/app/controllers/api/v1/reports_controller.rb @@ -33,6 +33,6 @@ class Api::V1::ReportsController < Api::BaseController end def report_params - params.permit(:account_id, :comment, :forward, status_ids: []) + params.permit(:account_id, :comment, :category, :forward, status_ids: [], rule_ids: []) end end diff --git a/app/models/report.rb b/app/models/report.rb index ceb15133b..3dd8a6fdd 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -39,6 +39,9 @@ class Report < ApplicationRecord scope :with_accounts, -> { includes([:account, :target_account, :action_taken_by_account, :assigned_account].index_with({ user: [:invite_request, :invite] })) } validates :comment, length: { maximum: 1_000 } + validates :rule_ids, absence: true, unless: :violation? + + validate :validate_rule_ids enum category: { other: 0, @@ -122,4 +125,10 @@ class Report < ApplicationRecord def set_uri self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local? end + + def validate_rule_ids + return unless violation? + + errors.add(:rule_ids, I18n.t('reports.errors.invalid_rules')) unless rules.size == rule_ids.size + end end diff --git a/app/services/report_service.rb b/app/services/report_service.rb index bc0a8b464..caf99ab6e 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -8,13 +8,15 @@ class ReportService < BaseService @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) @options = options raise ActiveRecord::RecordNotFound if @target_account.suspended? create_report! notify_staff! - forward_to_origin! if !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward]) + forward_to_origin! if forward? @report end @@ -27,7 +29,9 @@ class ReportService < BaseService status_ids: @status_ids, comment: @comment, uri: @options[:uri], - forwarded: ActiveModel::Type::Boolean.new.cast(@options[:forward]) + forwarded: forward?, + category: @category, + rule_ids: @rule_ids ) end @@ -48,6 +52,10 @@ class ReportService < BaseService ) end + def forward? + !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward]) + end + def payload Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account)) end |