[PR #2135] [MERGED] fix: populate complete entity data in deletion event webhooks #9801

Closed
opened 2026-04-23 09:13:29 -05:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-vikunja/vikunja/pull/2135
Author: @kolaente
Created: 1/23/2026
Status: Merged
Merged: 1/24/2026
Merged by: @kolaente

Base: mainHead: fix-deleted-events-payload


📝 Commits (8)

  • 97c498b fix: populate complete entity data in deletion event webhooks
  • 4cf4c8b refactor: extract event data reload logic into separate functions
  • 8490da2 fix: use doer from web.Auth instead of comment author
  • 7b1cccb cleanup
  • 10b60fe refactor: move CreatedBy fetch into TaskRelation.ReadOne method
  • c8a80fb fix: guard against nil project in reloadProjectInEvent
  • 82c1c6e fix: handle errors in reloadAssigneeInEvent
  • 3461299 fix: treat user not found as non-fatal in TaskAttachment.ReadOne

📊 Changes

4 files changed (+192 additions, -74 deletions)

View changed files

📝 pkg/models/listeners.go (+140 -53)
📝 pkg/models/task_attachment.go (+11 -1)
📝 pkg/models/task_comments.go (+8 -2)
📝 pkg/models/task_relation.go (+33 -18)

📄 Description

Summary

Fixes webhook payloads for deletion events that were previously containing incomplete or empty entity data. This occurred because entities were being deleted from the database before the webhook event was dispatched.

Changes

This PR implements four targeted fixes to ensure complete entity data in deletion event webhooks:

1. TaskAssignee Deletion (pkg/models/listeners.go)

  • Extended reloadEventData() to fetch full assignee user data by ID
  • Webhook payload now includes complete user object (username, email, timestamps, etc.)

2. TaskComment Deletion (pkg/models/task_comments.go)

  • Modified Delete() to call ReadOne() before deletion
  • Ensures comment text, author, and timestamps are included in webhook payload
  • Follows the same pattern used by Task.Delete() and TaskAttachment.Delete()

3. TaskAttachment Deletion (pkg/models/task_attachment.go)

  • Extended ReadOne() to fetch the CreatedBy user
  • Webhook payload now includes file creator information

4. TaskRelation Deletion (pkg/models/task_relation.go)

  • Modified Delete() to fetch complete relation including CreatedBy user before deletion
  • Webhook payload now includes relation timestamps and creator information

Testing

  • All existing tests pass (83 PASS, 0 FAIL)
  • No regressions detected in feature test suite
  • Changes follow existing patterns from Task.Delete() and TaskAttachment.Delete()

Note

The linter reports that reloadEventData() now has a cyclomatic complexity of 32 (threshold is 30). This is a minor increase from the pre-existing complexity. If desired, this can be addressed in a follow-up PR by refactoring the function to extract reload logic into helper functions.

Fixes #2125


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-vikunja/vikunja/pull/2135 **Author:** [@kolaente](https://github.com/kolaente) **Created:** 1/23/2026 **Status:** ✅ Merged **Merged:** 1/24/2026 **Merged by:** [@kolaente](https://github.com/kolaente) **Base:** `main` ← **Head:** `fix-deleted-events-payload` --- ### 📝 Commits (8) - [`97c498b`](https://github.com/go-vikunja/vikunja/commit/97c498bbad082e84264569af9524b894b92eba27) fix: populate complete entity data in deletion event webhooks - [`4cf4c8b`](https://github.com/go-vikunja/vikunja/commit/4cf4c8b2b871c8be362bc8031290864ab7280666) refactor: extract event data reload logic into separate functions - [`8490da2`](https://github.com/go-vikunja/vikunja/commit/8490da2327e1c84ceaa1eedf95c8a7a3d8de5f09) fix: use doer from web.Auth instead of comment author - [`7b1cccb`](https://github.com/go-vikunja/vikunja/commit/7b1cccb8ce2ba710d8111bb727b1f1419e710490) cleanup - [`10b60fe`](https://github.com/go-vikunja/vikunja/commit/10b60fe75e8adc35b4f77e47c3a2c53d8d32bb1b) refactor: move CreatedBy fetch into TaskRelation.ReadOne method - [`c8a80fb`](https://github.com/go-vikunja/vikunja/commit/c8a80fb0a510dcedfa788b03e487e4abc64e35be) fix: guard against nil project in reloadProjectInEvent - [`82c1c6e`](https://github.com/go-vikunja/vikunja/commit/82c1c6e2fdc2587c682cc3db6a12882943057bcb) fix: handle errors in reloadAssigneeInEvent - [`3461299`](https://github.com/go-vikunja/vikunja/commit/3461299805f35e87d37df1f9afcb097546f8ba01) fix: treat user not found as non-fatal in TaskAttachment.ReadOne ### 📊 Changes **4 files changed** (+192 additions, -74 deletions) <details> <summary>View changed files</summary> 📝 `pkg/models/listeners.go` (+140 -53) 📝 `pkg/models/task_attachment.go` (+11 -1) 📝 `pkg/models/task_comments.go` (+8 -2) 📝 `pkg/models/task_relation.go` (+33 -18) </details> ### 📄 Description ## Summary Fixes webhook payloads for deletion events that were previously containing incomplete or empty entity data. This occurred because entities were being deleted from the database before the webhook event was dispatched. ## Changes This PR implements four targeted fixes to ensure complete entity data in deletion event webhooks: ### 1. TaskAssignee Deletion (`pkg/models/listeners.go`) - Extended `reloadEventData()` to fetch full assignee user data by ID - Webhook payload now includes complete user object (username, email, timestamps, etc.) ### 2. TaskComment Deletion (`pkg/models/task_comments.go`) - Modified `Delete()` to call `ReadOne()` before deletion - Ensures comment text, author, and timestamps are included in webhook payload - Follows the same pattern used by `Task.Delete()` and `TaskAttachment.Delete()` ### 3. TaskAttachment Deletion (`pkg/models/task_attachment.go`) - Extended `ReadOne()` to fetch the `CreatedBy` user - Webhook payload now includes file creator information ### 4. TaskRelation Deletion (`pkg/models/task_relation.go`) - Modified `Delete()` to fetch complete relation including `CreatedBy` user before deletion - Webhook payload now includes relation timestamps and creator information ## Testing - ✅ All existing tests pass (83 PASS, 0 FAIL) - ✅ No regressions detected in feature test suite - ✅ Changes follow existing patterns from `Task.Delete()` and `TaskAttachment.Delete()` ## Note The linter reports that `reloadEventData()` now has a cyclomatic complexity of 32 (threshold is 30). This is a minor increase from the pre-existing complexity. If desired, this can be addressed in a follow-up PR by refactoring the function to extract reload logic into helper functions. Fixes #2125 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2026-04-23 09:13:29 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/vikunja#9801