about summary refs log tree commit diff
path: root/app/services/concerns
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-06-04 23:11:18 +0200
committermultiple creatures <dev@multiple-creature.party>2019-11-19 16:32:36 -0600
commitfbf08920a0d73231c04b35c263ea4e04224b6e7d (patch)
treeafc2717ba1e5b121d170d0d5adc5236cf73f78dd /app/services/concerns
parent82bd234c3cb4aed81ab4e4c8844bd27d065ea4d9 (diff)
Refactor all ActivityPub deliveries to be serialized and signed through one concern (#10966)
Diffstat (limited to 'app/services/concerns')
-rw-r--r--app/services/concerns/payloadable.rb19
1 files changed, 19 insertions, 0 deletions
diff --git a/app/services/concerns/payloadable.rb b/app/services/concerns/payloadable.rb
new file mode 100644
index 000000000..13d9c3548
--- /dev/null
+++ b/app/services/concerns/payloadable.rb
@@ -0,0 +1,19 @@
+# frozen_string_literal: true
+
+module Payloadable
+  def serialize_payload(record, serializer, options = {})
+    signer    = options.delete(:signer)
+    sign_with = options.delete(:sign_with)
+    payload   = ActiveModelSerializers::SerializableResource.new(record, options.merge(serializer: serializer, adapter: ActivityPub::Adapter)).as_json
+
+    if (record.respond_to?(:sign?) && record.sign?) && signer && signing_enabled?
+      ActivityPub::LinkedDataSignature.new(payload).sign!(signer, sign_with: sign_with)
+    else
+      payload
+    end
+  end
+
+  def signing_enabled?
+    true
+  end
+end