diff options
author | ThibG <thib@sitedethib.com> | 2019-03-17 15:34:56 +0100 |
---|---|---|
committer | Eugen Rochko <eugen@zeonfederated.com> | 2019-03-17 15:34:56 +0100 |
commit | a20354a20b9dffada0e8d6170ebc2ff13c79baea (patch) | |
tree | 74d1a47399b0cbd24187562b1a864ae5e984979c /app | |
parent | 5e38ef87a7b8bac59ffa0d98464086ab8a60a2e1 (diff) |
Set and store report URIs (#10303)
Fixes #10271
Diffstat (limited to 'app')
-rw-r--r-- | app/lib/activitypub/activity/flag.rb | 7 | ||||
-rw-r--r-- | app/models/report.rb | 11 | ||||
-rw-r--r-- | app/serializers/activitypub/flag_serializer.rb | 1 | ||||
-rw-r--r-- | app/services/report_service.rb | 3 |
4 files changed, 19 insertions, 3 deletions
diff --git a/app/lib/activitypub/activity/flag.rb b/app/lib/activitypub/activity/flag.rb index 0d10d6c3c..f73b93058 100644 --- a/app/lib/activitypub/activity/flag.rb +++ b/app/lib/activitypub/activity/flag.rb @@ -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 diff --git a/app/models/report.rb b/app/models/report.rb index 2804020f5..86c303798 100644 --- a/app/models/report.rb +++ b/app/models/report.rb @@ -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 diff --git a/app/serializers/activitypub/flag_serializer.rb b/app/serializers/activitypub/flag_serializer.rb index 53e8f726d..1e7a46dd9 100644 --- a/app/serializers/activitypub/flag_serializer.rb +++ b/app/serializers/activitypub/flag_serializer.rb @@ -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 diff --git a/app/services/report_service.rb b/app/services/report_service.rb index 1bcc1c0d5..73bd6694f 100644 --- a/app/services/report_service.rb +++ b/app/services/report_service.rb @@ -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 |