diff --git a/modules/webhooks/app/workers/attachment_webhook_job.rb b/modules/webhooks/app/workers/attachment_webhook_job.rb index 97a301136d6c..f05d2e855850 100644 --- a/modules/webhooks/app/workers/attachment_webhook_job.rb +++ b/modules/webhooks/app/workers/attachment_webhook_job.rb @@ -38,10 +38,7 @@ def accepted_in_project? webhook.enabled_for_project?(project.id) end - def payload_representer - User.system.run_given do |user| - ::API::V3::Attachments::AttachmentRepresenter - .create(resource, current_user: user, embed_links: true) - end + def payload_representer_class + ::API::V3::Attachments::AttachmentRepresenter end end diff --git a/modules/webhooks/app/workers/project_webhook_job.rb b/modules/webhooks/app/workers/project_webhook_job.rb index 732563074593..b96fd7771840 100644 --- a/modules/webhooks/app/workers/project_webhook_job.rb +++ b/modules/webhooks/app/workers/project_webhook_job.rb @@ -39,10 +39,7 @@ def accepted_in_project? end end - def payload_representer - User.system.run_given do |user| - ::API::V3::Projects::ProjectRepresenter - .create(resource, current_user: user, embed_links: true) - end + def payload_representer_class + ::API::V3::Projects::ProjectRepresenter end end diff --git a/modules/webhooks/app/workers/represented_webhook_job.rb b/modules/webhooks/app/workers/represented_webhook_job.rb index 0d4ca6a21163..0903395d604a 100644 --- a/modules/webhooks/app/workers/represented_webhook_job.rb +++ b/modules/webhooks/app/workers/represented_webhook_job.rb @@ -68,14 +68,22 @@ def payload_key raise NotImplementedError end - def payload_representer + def represented_payload + User.system.run_given do |user| + payload_representer_class + .create(resource, current_user: user, embed_links: true) + .to_hash # to_hash needs to be called within the system user block + end + end + + def payload_representer_class raise NotImplementedError end def request_body { :action => event_name, - payload_key => payload_representer + payload_key => represented_payload }.to_json end end diff --git a/modules/webhooks/app/workers/time_entry_webhook_job.rb b/modules/webhooks/app/workers/time_entry_webhook_job.rb index c8c2013caddb..d9400d8da954 100644 --- a/modules/webhooks/app/workers/time_entry_webhook_job.rb +++ b/modules/webhooks/app/workers/time_entry_webhook_job.rb @@ -31,10 +31,7 @@ def payload_key :time_entry end - def payload_representer - User.system.run_given do |user| - ::API::V3::TimeEntries::TimeEntryRepresenter - .create(resource, current_user: user, embed_links: true) - end + def payload_representer_class + ::API::V3::TimeEntries::TimeEntryRepresenter end end diff --git a/modules/webhooks/app/workers/work_package_webhook_job.rb b/modules/webhooks/app/workers/work_package_webhook_job.rb index b25b01d043a1..4f9cb3928f1b 100644 --- a/modules/webhooks/app/workers/work_package_webhook_job.rb +++ b/modules/webhooks/app/workers/work_package_webhook_job.rb @@ -31,10 +31,7 @@ def payload_key :work_package end - def payload_representer - User.system.run_given do |user| - ::API::V3::WorkPackages::WorkPackageRepresenter - .create(resource, current_user: user, embed_links: true) - end + def payload_representer_class + ::API::V3::WorkPackages::WorkPackageRepresenter end end