all: deal with nil participant ID

This can happen in the case of EVENT_TICKET_MENTIONED. In the future we
might want to consider swapping ByParticipantID for ParticipantID in the
database for these events.
This commit is contained in:
Drew DeVault 2022-09-05 15:51:30 +02:00
parent 6517544340
commit 050c219153
3 changed files with 18 additions and 13 deletions

View File

@ -17,7 +17,7 @@ type Event struct {
Created time.Time `json:"created"`
EventType int
ParticipantID int
ParticipantID *int
TicketID int
ByParticipantID *int
@ -125,7 +125,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, Created{
EventType: EventTypeCreated,
TicketID: ev.TicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ParticipantID,
})
}
@ -133,7 +133,7 @@ func (ev *Event) Changes() []EventDetail {
comment := Comment{
EventType: EventTypeComment,
TicketID: ev.TicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ParticipantID,
}
comment.Database.ID = *ev.CommentID
changes = append(changes, comment)
@ -143,7 +143,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, StatusChange{
EventType: EventTypeStatusChange,
TicketID: ev.TicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ParticipantID,
OldStatus: TicketStatusFromInt(*ev.OldStatus),
NewStatus: TicketStatusFromInt(*ev.NewStatus),
@ -156,7 +156,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, LabelUpdate{
EventType: EventTypeLabelAdded,
TicketID: ev.TicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ParticipantID,
LabelID: *ev.LabelID,
})
}
@ -165,7 +165,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, LabelUpdate{
EventType: EventTypeLabelRemoved,
TicketID: ev.TicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ParticipantID,
LabelID: *ev.LabelID,
})
}
@ -174,7 +174,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, Assignment{
EventType: EventTypeAssignedUser,
TicketID: ev.TicketID,
AssigneeID: ev.ParticipantID,
AssigneeID: *ev.ParticipantID,
AssignerID: *ev.ByParticipantID,
})
}
@ -183,7 +183,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, Assignment{
EventType: EventTypeUnassignedUser,
TicketID: ev.TicketID,
AssigneeID: ev.ParticipantID,
AssigneeID: *ev.ParticipantID,
AssignerID: *ev.ByParticipantID,
})
}
@ -193,7 +193,7 @@ func (ev *Event) Changes() []EventDetail {
EventType: EventTypeUserMentioned,
TicketID: ev.TicketID,
ParticipantID: *ev.ByParticipantID,
MentionedID: ev.ParticipantID,
MentionedID: *ev.ParticipantID,
})
}
@ -201,7 +201,7 @@ func (ev *Event) Changes() []EventDetail {
changes = append(changes, TicketMention{
EventType: EventTypeTicketMentioned,
TicketID: *ev.FromTicketID,
ParticipantID: ev.ParticipantID,
ParticipantID: *ev.ByParticipantID,
MentionedID: ev.TicketID,
})
}

View File

@ -2784,6 +2784,7 @@ func (r *ticketWebhookSubscriptionResolver) Sample(ctx context.Context, obj *mod
newStatus := model.STATUS_RESOLVED
oldResolution := model.RESOLVED_UNRESOLVED
newResolution := model.RESOLVED_FIXED
participantId := -1
webhook.Payload = &model.EventCreated{
UUID: payloadUUID.String(),
Event: event,
@ -2792,7 +2793,7 @@ func (r *ticketWebhookSubscriptionResolver) Sample(ctx context.Context, obj *mod
ID: -1,
Created: time.Now().UTC(),
EventType: model.EVENT_STATUS_CHANGE,
ParticipantID: -1,
ParticipantID: &participantId,
TicketID: -1,
ByParticipantID: nil,
CommentID: nil,
@ -3169,6 +3170,7 @@ func (r *trackerWebhookSubscriptionResolver) Sample(ctx context.Context, obj *mo
newStatus := model.STATUS_RESOLVED
oldResolution := model.RESOLVED_UNRESOLVED
newResolution := model.RESOLVED_FIXED
participantId := -1
webhook.Payload = &model.EventCreated{
UUID: payloadUUID.String(),
Event: event,
@ -3177,7 +3179,7 @@ func (r *trackerWebhookSubscriptionResolver) Sample(ctx context.Context, obj *mo
ID: -1,
Created: time.Now().UTC(),
EventType: model.EVENT_STATUS_CHANGE,
ParticipantID: -1,
ParticipantID: &participantId,
TicketID: -1,
ByParticipantID: nil,
CommentID: nil,

View File

@ -411,7 +411,10 @@ func DeliverLegacyEventCreate(ctx context.Context,
tracker *model.Tracker, ticket *model.Ticket, event *model.Event) {
q := webhooks.LegacyForContext(ctx)
part, err := loaders.ForContext(ctx).EntitiesByParticipantID.Load(event.ParticipantID)
if event.ParticipantID == nil {
return
}
part, err := loaders.ForContext(ctx).EntitiesByParticipantID.Load(*event.ParticipantID)
if err != nil || part == nil {
panic("Invalid event participant")
}