parent
							
								
									5e38ef87a7
								
							
						
					
					
						commit
						a20354a20b
					
				
					 8 changed files with 52 additions and 6 deletions
				
			
		| 
						 | 
				
			
			@ -14,7 +14,8 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
 | 
			
		|||
        @account,
 | 
			
		||||
        target_account,
 | 
			
		||||
        status_ids: target_statuses.nil? ? [] : target_statuses.map(&:id),
 | 
			
		||||
        comment: @json['content'] || ''
 | 
			
		||||
        comment: @json['content'] || '',
 | 
			
		||||
        uri: report_uri
 | 
			
		||||
      )
 | 
			
		||||
    end
 | 
			
		||||
  end
 | 
			
		||||
| 
						 | 
				
			
			@ -28,4 +29,8 @@ class ActivityPub::Activity::Flag < ActivityPub::Activity
 | 
			
		|||
  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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,6 +13,7 @@
 | 
			
		|||
#  action_taken_by_account_id :bigint(8)
 | 
			
		||||
#  target_account_id          :bigint(8)        not null
 | 
			
		||||
#  assigned_account_id        :bigint(8)
 | 
			
		||||
#  uri                        :string
 | 
			
		||||
#
 | 
			
		||||
 | 
			
		||||
class Report < ApplicationRecord
 | 
			
		||||
| 
						 | 
				
			
			@ -28,6 +29,12 @@ 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
 | 
			
		||||
| 
						 | 
				
			
			@ -89,4 +96,8 @@ class Report < ApplicationRecord
 | 
			
		|||
 | 
			
		||||
    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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -5,7 +5,6 @@ class ActivityPub::FlagSerializer < ActiveModel::Serializer
 | 
			
		|||
  attribute :virtual_object, key: :object
 | 
			
		||||
 | 
			
		||||
  def id
 | 
			
		||||
    # This is nil for now
 | 
			
		||||
    ActivityPub::TagManager.instance.uri_for(object)
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,7 +21,8 @@ class ReportService < BaseService
 | 
			
		|||
    @report = @source_account.reports.create!(
 | 
			
		||||
      target_account: @target_account,
 | 
			
		||||
      status_ids: @status_ids,
 | 
			
		||||
      comment: @comment
 | 
			
		||||
      comment: @comment,
 | 
			
		||||
      uri: @options[:uri]
 | 
			
		||||
    )
 | 
			
		||||
  end
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
							
								
								
									
										5
									
								
								db/migrate/20190317135723_add_uri_to_reports.rb
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										5
									
								
								db/migrate/20190317135723_add_uri_to_reports.rb
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
				
			
			@ -0,0 +1,5 @@
 | 
			
		|||
class AddUriToReports < ActiveRecord::Migration[5.2]
 | 
			
		||||
  def change
 | 
			
		||||
    add_column :reports, :uri, :string
 | 
			
		||||
  end
 | 
			
		||||
end
 | 
			
		||||
| 
						 | 
				
			
			@ -10,7 +10,7 @@
 | 
			
		|||
#
 | 
			
		||||
# 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"
 | 
			
		||||
| 
						 | 
				
			
			@ -525,6 +525,7 @@ ActiveRecord::Schema.define(version: 2019_03_14_181829) do
 | 
			
		|||
    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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,14 +1,15 @@
 | 
			
		|||
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),
 | 
			
		||||
| 
						 | 
				
			
			@ -34,4 +35,22 @@ RSpec.describe ActivityPub::Activity::Flag do
 | 
			
		|||
      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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -21,6 +21,11 @@ RSpec.describe ReportService, type: :service do
 | 
			
		|||
      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
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
	Add table
		
		Reference in a new issue