payloadable.rb 748 B

1234567891011121314151617181920
  1. # frozen_string_literal: true
  2. module Payloadable
  3. def serialize_payload(record, serializer, options = {})
  4. signer = options.delete(:signer)
  5. sign_with = options.delete(:sign_with)
  6. payload = ActiveModelSerializers::SerializableResource.new(record, options.merge(serializer: serializer, adapter: ActivityPub::Adapter)).as_json
  7. object = record.respond_to?(:virtual_object) ? record.virtual_object : record
  8. if (object.respond_to?(:sign?) && object.sign?) && signer && signing_enabled?
  9. ActivityPub::LinkedDataSignature.new(payload).sign!(signer, sign_with: sign_with)
  10. else
  11. payload
  12. end
  13. end
  14. def signing_enabled?
  15. ENV['AUTHORIZED_FETCH'] != 'true' && !Rails.configuration.x.whitelist_mode
  16. end
  17. end