Serialize events

This commit is contained in:
Stanko K.R.
2025-09-11 17:56:28 +02:00
parent 1d69b171b6
commit 4879995013
9 changed files with 106 additions and 1 deletions
+4
View File
@@ -44,6 +44,10 @@ class Webhook < ApplicationRecord
update_columns active: false
end
def renderer
@renderer ||= ApplicationController.renderer.new
end
private
def validate_url
uri = URI.parse(url.presence)
+1 -1
View File
@@ -106,6 +106,6 @@ class Webhook::Delivery < ApplicationRecord
end
def payload
{ test: :test }.to_json
webhook.renderer.render(template: "webhooks/event", assigns: { event: event }, format: :json)
end
end
+26
View File
@@ -0,0 +1,26 @@
json.cache! card do
json.(card, :id, :title, :status)
json.image_url card.image.presence && url_for(card.image)
json.golden card.golden?
json.last_active_at card.last_active_at.utc
json.created_at card.created_at.utc
json.url card_url(card)
json.collection do
json.partial! "collections/collection", locals: { collection: card.collection }
end
json.stage do
if card.stage
json.partial! "workflows/stages/stage", stage: card.stage
else
nil
end
end
json.creator do
json.partial! "users/user", user: card.creator
end
end
@@ -0,0 +1,18 @@
json.cache! comment do
json.(comment, :id)
json.created_at comment.created_at.utc
json.updated_at comment.updated_at.utc
json.body do
json.plain_text comment.body.to_plain_text
json.html comment.body.to_s
end
json.creator do
json.partial! "users/user", user: comment.creator
end
json.reactions_url card_comment_reactions_url(comment.card_id, comment.id)
json.url card_comment_url(comment.card_id, comment.id)
end
@@ -0,0 +1,16 @@
json.cache! collection do
json.(collection, :id, :name, :all_access)
json.created_at collection.created_at.utc
json.creator do
json.partial! "users/user", user: collection.creator
end
json.workflow do
if collection.workflow
json.partial! "workflows/workflow", workflow: collection.workflow
else
nil
end
end
end
+7
View File
@@ -0,0 +1,7 @@
json.cache! user do
json.(user, :id, :name, :email_address, :role, :active)
json.created_at user.created_at.utc
json.url user_url(user)
end
+19
View File
@@ -0,0 +1,19 @@
json.cache! @event do
json.(@event, :id, :action)
json.created_at @event.created_at.utc
json.eventable do
case @event.eventable
when Card then json.partial! "cards/card", card: @event.eventable
when Comment then json.partial! "cards/comments/comment", comment: @event.eventable
end
end
json.collection do
json.partial! "collections/collection", locals: { collection: @event.collection }
end
json.creator do
json.partial! "users/user", user: @event.creator
end
end
@@ -0,0 +1,6 @@
json.cache! workflow do
json.(workflow, :id, :name)
json.created_at workflow.created_at.utc
json.updated_at workflow.updated_at.utc
end
@@ -0,0 +1,9 @@
json.cache! stage do
json.(stage, :id, :name, :color)
json.created_at stage.created_at.utc
json.workflow do
json.partial! "workflows/workflow", workflow: stage.workflow
end
end