mirror of
https://github.com/mastodon/mastodon.git
synced 2024-12-18 15:48:22 +00:00
Add category
and rule_ids
params to POST /api/v1/reports
(#17492)
This commit is contained in:
parent
5533fa28b6
commit
2f8159baad
|
@ -33,6 +33,6 @@ class Api::V1::ReportsController < Api::BaseController
|
||||||
end
|
end
|
||||||
|
|
||||||
def report_params
|
def report_params
|
||||||
params.permit(:account_id, :comment, :forward, status_ids: [])
|
params.permit(:account_id, :comment, :category, :forward, status_ids: [], rule_ids: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -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] })) }
|
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 :comment, length: { maximum: 1_000 }
|
||||||
|
validates :rule_ids, absence: true, unless: :violation?
|
||||||
|
|
||||||
|
validate :validate_rule_ids
|
||||||
|
|
||||||
enum category: {
|
enum category: {
|
||||||
other: 0,
|
other: 0,
|
||||||
|
@ -122,4 +125,10 @@ class Report < ApplicationRecord
|
||||||
def set_uri
|
def set_uri
|
||||||
self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
|
self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -8,13 +8,15 @@ class ReportService < BaseService
|
||||||
@target_account = target_account
|
@target_account = target_account
|
||||||
@status_ids = options.delete(:status_ids) || []
|
@status_ids = options.delete(:status_ids) || []
|
||||||
@comment = options.delete(:comment) || ''
|
@comment = options.delete(:comment) || ''
|
||||||
|
@category = options.delete(:category) || 'other'
|
||||||
|
@rule_ids = options.delete(:rule_ids)
|
||||||
@options = options
|
@options = options
|
||||||
|
|
||||||
raise ActiveRecord::RecordNotFound if @target_account.suspended?
|
raise ActiveRecord::RecordNotFound if @target_account.suspended?
|
||||||
|
|
||||||
create_report!
|
create_report!
|
||||||
notify_staff!
|
notify_staff!
|
||||||
forward_to_origin! if !@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward])
|
forward_to_origin! if forward?
|
||||||
|
|
||||||
@report
|
@report
|
||||||
end
|
end
|
||||||
|
@ -27,7 +29,9 @@ class ReportService < BaseService
|
||||||
status_ids: @status_ids,
|
status_ids: @status_ids,
|
||||||
comment: @comment,
|
comment: @comment,
|
||||||
uri: @options[:uri],
|
uri: @options[:uri],
|
||||||
forwarded: ActiveModel::Type::Boolean.new.cast(@options[:forward])
|
forwarded: forward?,
|
||||||
|
category: @category,
|
||||||
|
rule_ids: @rule_ids
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -48,6 +52,10 @@ class ReportService < BaseService
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def forward?
|
||||||
|
!@target_account.local? && ActiveModel::Type::Boolean.new.cast(@options[:forward])
|
||||||
|
end
|
||||||
|
|
||||||
def payload
|
def payload
|
||||||
Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account))
|
Oj.dump(serialize_payload(@report, ActivityPub::FlagSerializer, account: some_local_account))
|
||||||
end
|
end
|
||||||
|
|
|
@ -1225,6 +1225,9 @@ en:
|
||||||
reply:
|
reply:
|
||||||
proceed: Proceed to reply
|
proceed: Proceed to reply
|
||||||
prompt: 'You want to reply to this post:'
|
prompt: 'You want to reply to this post:'
|
||||||
|
reports:
|
||||||
|
errors:
|
||||||
|
invalid_rules: does not reference valid rules
|
||||||
scheduled_statuses:
|
scheduled_statuses:
|
||||||
over_daily_limit: You have exceeded the limit of %{limit} scheduled posts for today
|
over_daily_limit: You have exceeded the limit of %{limit} scheduled posts for today
|
||||||
over_total_limit: You have exceeded the limit of %{limit} scheduled posts
|
over_total_limit: You have exceeded the limit of %{limit} scheduled posts
|
||||||
|
|
Loading…
Reference in a new issue