@account,
target_account,
status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
- comment: @json['content'] || ''
+ comment: @json['content'] || '',
+ uri: report_uri
)
end
end
def object_uris
@object_uris ||= Array(@object.is_a?(Array) ? @object.map { |item| value_or_id(item) } : value_or_id(@object))
end
+
+ def report_uri
+ @json['id'] unless @json['id'].nil? || invalid_origin?(@json['id'])
+ end
end
# action_taken_by_account_id :bigint(8)
# target_account_id :bigint(8) not null
# assigned_account_id :bigint(8)
+# uri :string
#
class Report < ApplicationRecord
validates :comment, length: { maximum: 1000 }
+ def local?
+ false # Force uri_for to use uri attribute
+ end
+
+ before_validation :set_uri, only: :create
+
def object_type
:flag
end
Admin::ActionLog.from("(#{sql}) AS admin_action_logs")
end
+
+ def set_uri
+ self.uri = ActivityPub::TagManager.instance.generate_uri_for(self) if uri.nil? && account.local?
+ end
end
attribute :virtual_object, key: :object
def id
- # This is nil for now
ActivityPub::TagManager.instance.uri_for(object)
end
@report = @source_account.reports.create!(
target_account: @target_account,
status_ids: @status_ids,
- comment: @comment
+ comment: @comment,
+ uri: @options[:uri]
)
end
--- /dev/null
+class AddUriToReports < ActiveRecord::Migration[5.2]
+ def change
+ add_column :reports, :uri, :string
+ end
+end
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 2019_03_14_181829) do
+ActiveRecord::Schema.define(version: 2019_03_17_135723) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
t.bigint "action_taken_by_account_id"
t.bigint "target_account_id", null: false
t.bigint "assigned_account_id"
+ t.string "uri"
t.index ["account_id"], name: "index_reports_on_account_id"
t.index ["target_account_id"], name: "index_reports_on_target_account_id"
end
require 'rails_helper'
RSpec.describe ActivityPub::Activity::Flag do
- let(:sender) { Fabricate(:account, domain: 'example.com') }
+ let(:sender) { Fabricate(:account, domain: 'example.com', uri: 'http://example.com/account') }
let(:flagged) { Fabricate(:account) }
let(:status) { Fabricate(:status, account: flagged, uri: 'foobar') }
+ let(:flag_id) { nil }
let(:json) do
{
'@context': 'https://www.w3.org/ns/activitystreams',
- id: nil,
+ id: flag_id,
type: 'Flag',
content: 'Boo!!',
actor: ActivityPub::TagManager.instance.uri_for(sender),
expect(report.status_ids).to eq [status.id]
end
end
+
+ describe '#perform with a defined uri' do
+ subject { described_class.new(json, sender) }
+ let (:flag_id) { 'http://example.com/reports/1' }
+
+ before do
+ subject.perform
+ end
+
+ it 'creates a report' do
+ report = Report.find_by(account: sender, target_account: flagged)
+
+ expect(report).to_not be_nil
+ expect(report.comment).to eq 'Boo!!'
+ expect(report.status_ids).to eq [status.id]
+ expect(report.uri).to eq flag_id
+ end
+ end
end
subject.call(source_account, remote_account, forward: false)
expect(a_request(:post, 'http://example.com/inbox')).to_not have_been_made
end
+
+ it 'has an uri' do
+ report = subject.call(source_account, remote_account, forward: true)
+ expect(report.uri).to_not be_nil
+ end
end
context 'when other reports already exist for the same target' do