-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
chore: create email_events_log
view to access Hasura Event metadata
#4211
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DROP VIEW "public"."email_events_log"; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
CREATE OR REPLACE VIEW public.email_events_log AS | ||
WITH retries AS ( | ||
SELECT hdb_scheduled_event_invocation_logs.id | ||
FROM hdb_catalog.hdb_scheduled_event_invocation_logs | ||
WHERE ((hdb_scheduled_event_invocation_logs.event_id, hdb_scheduled_event_invocation_logs.created_at) IN ( | ||
SELECT | ||
seil.event_id, | ||
max(seil.created_at) AS max | ||
FROM (hdb_catalog.hdb_scheduled_event_invocation_logs seil | ||
LEFT JOIN hdb_catalog.hdb_scheduled_events se ON ((se.id = seil.event_id))) | ||
WHERE (se.tries > 1) | ||
GROUP BY seil.event_id)) | ||
), emails AS ( | ||
SELECT | ||
((((seil.request -> 'payload'::text) -> 'payload'::text) ->> 'sessionId'::text))::uuid AS session_id, | ||
se.id AS event_id, | ||
CASE | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/expiry"'::text) THEN 'Session expiry'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/reminder"'::text) THEN 'Session reminder'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/confirmation"'::text) THEN 'Submission confirmation'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/invite-to-pay"'::text) THEN 'Invitation to pay'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/invite-to-pay-agent"'::text) THEN 'Invitation to pay - agent'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/payment-expiry"'::text) THEN 'Payment expiry'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/payment-expiry-agent"'::text) THEN 'Payment expiry - agent'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/payment-reminder"'::text) THEN 'Payment reminder'::text | ||
WHEN ((webhook_conf)::text ~~ '%/send-email/payment-reminder-agent"'::text) THEN 'Payment reminder - agent'::text | ||
ELSE (webhook_conf)::text | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great fallback to catch new templates or other issues. The fact we have to parse this from here (but it's very useful information) suggests we should maybe consider capturing this more explicitly / pro-actively as an audit log when sending emails. This is a really solid and practical solution though - love it 👍 |
||
END AS event_type, | ||
CASE | ||
WHEN (seil.status = 200) THEN 'Success'::text | ||
ELSE format('Failed (%s)'::text, seil.status) | ||
END AS status, | ||
(seil.response)::jsonb AS response, | ||
seil.created_at, | ||
(EXISTS ( | ||
SELECT 1 FROM retries r WHERE (r.id = seil.id))) AS retry | ||
FROM (hdb_catalog.hdb_scheduled_events se | ||
LEFT JOIN hdb_catalog.hdb_scheduled_event_invocation_logs seil ON ((seil.event_id = se.id))) | ||
WHERE (((se.webhook_conf)::text ~~ '%/send-email/%'::text) AND (seil.created_at >= '2024-01-01 00:00:00+00'::timestamp with time zone)) | ||
) | ||
SELECT | ||
ls.flow_id, | ||
e.session_id, | ||
e.event_id, | ||
e.event_type, | ||
e.status, | ||
e.response, | ||
e.created_at, | ||
e.retry | ||
FROM (emails e LEFT JOIN lowcal_sessions ls ON ((ls.id = e.session_id))) | ||
WHERE (ls.flow_id IS NOT NULL) | ||
ORDER BY e.created_at DESC; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I matched "select" permissions to the
submission_services_log
view here - does this seem fine? Alternatively, can keep stricter until explicit plans to expose in editor. View does not include any personal user data like email address or payment details, only session ID.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great question!
I'd favour not exposing it all until we need to - if it's intended to be for platform admins only lets capture that here 👍
If / when we come to exposing it, we set the right permissions then.
I'll checkout the demoUser /
submission_services_log
permissions just now - I would have expected that to have the normal demo user filter of "I can only select my own sessions" applied here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR here - #4212
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep makes sense - will rollback & keep as
admin
-select only