Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

[#62444] Webhook embedded resource custom fields are null

Dombi Attilabb5ada3d73e7
diff --git a/modules/webhooks/app/workers/represented_webhook_job.rb b/modules/webhooks/app/workers/represented_webhook_job.rb
index 0903395d604..19486e354e3 100644
--- a/modules/webhooks/app/workers/represented_webhook_job.rb
+++ b/modules/webhooks/app/workers/represented_webhook_job.rb
@@ -69,11 +69,8 @@ class RepresentedWebhookJob < WebhookJob
end
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
+ payload_representer_class
+ .create(resource, current_user: User.current, embed_links: true)
end
def payload_representer_class
@@ -81,9 +78,13 @@ class RepresentedWebhookJob < WebhookJob
end
def request_body
- {
- :action => event_name,
- payload_key => represented_payload
- }.to_json
+ # to_json needs to be called within the system user block in order to
+ # have all the custom field visibility permissions set up correctly.
+ User.system.run_given do
+ {
+ action: event_name,
+ payload_key => represented_payload
+ }.to_json
+ end
end
end
diff --git a/modules/webhooks/spec/workers/work_package_webhook_job_spec.rb b/modules/webhooks/spec/workers/work_package_webhook_job_spec.rb
index 5dfb1430816..22be3a1e0e6 100644
--- a/modules/webhooks/spec/workers/work_package_webhook_job_spec.rb
+++ b/modules/webhooks/spec/workers/work_package_webhook_job_spec.rb
@@ -1,3 +1,5 @@
+# frozen_string_literal: true
+
#-- copyright
# OpenProject is an open source project management software.
# Copyright (C) the OpenProject GmbH
@@ -74,7 +76,6 @@ RSpec.describe WorkPackageWebhookJob, :webmock, type: :model do
before do
allow(Webhooks::Webhook).to receive(:find).with(webhook.id).and_return(webhook)
- login_as user
stub
end
@@ -138,4 +139,31 @@ RSpec.describe WorkPackageWebhookJob, :webmock, type: :model do
let(:response_body) { "not found" }
end
end
+
+ describe "triggering a work package with an admin only custom field set on the embedded project Regression #62444" do
+ shared_let(:project) { work_package.project }
+ shared_let(:custom_field) do
+ create(:project_custom_field, :string, admin_only: true, projects: [project])
+ end
+ shared_let(:custom_value) do
+ create(:custom_value,
+ custom_field:,
+ customized: project,
+ value: "wat")
+ end
+
+ it_behaves_like "a work package webhook call" do
+ let(:event) { "work_package:created" }
+
+ it "includes the custom field value" do
+ subject
+
+ expect(stub).to have_been_requested
+
+ log = Webhooks::Log.last
+ embedded_project = JSON.parse(log.request_body)["work_package"]["_embedded"]["project"]
+ expect(embedded_project[custom_field.attribute_name(:camel_case)]).to eq "wat"
+ end
+ end
+ end
end