Skip to content

Commit

Permalink
Ensure representer#to_hash is called as system user
Browse files Browse the repository at this point in the history
The getter was only called outside the user system block,
which caused the custom fields to not be visible
  • Loading branch information
oliverguenther committed Oct 8, 2024
1 parent eb2c755 commit 98959e8
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 22 deletions.
7 changes: 2 additions & 5 deletions modules/webhooks/app/workers/attachment_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions modules/webhooks/app/workers/project_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
12 changes: 10 additions & 2 deletions modules/webhooks/app/workers/represented_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions modules/webhooks/app/workers/time_entry_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 2 additions & 5 deletions modules/webhooks/app/workers/work_package_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 98959e8

Please sign in to comment.