API: Implement legacy label:delete webhook

This commit is contained in:
Drew DeVault 2022-01-12 11:22:42 +01:00
parent bc8aab193e
commit 3ee8d3ada4
2 changed files with 27 additions and 0 deletions

View File

@ -650,6 +650,7 @@ func (r *mutationResolver) DeleteLabel(ctx context.Context, id int) (*model.Labe
}
return nil, err
}
webhooks.DeliverLegacyLabelDelete(ctx, label.TrackerID, label.ID)
return &label, nil
}

View File

@ -189,3 +189,29 @@ func DeliverLegacyLabelCreate(ctx context.Context,
Where("sub.tracker_id = ?", tracker.ID)
q.Schedule(ctx, query, "tracker", "label:create", encoded)
}
func DeliverLegacyLabelDelete(ctx context.Context, trackerID, labelID int) {
q, ok := ctx.Value(legacyWebhooksCtxKey).(*webhooks.LegacyQueue)
if !ok {
panic("No legacy webhooks worker for this context")
}
// It occurs to me that this webhook is completely useless given that the
// legacy API doesn't expose label IDs to the user
type WebhookPayload struct {
ID int `json:"id"`
}
payload := WebhookPayload{labelID}
encoded, err := json.Marshal(&payload)
if err != nil {
panic(err) // Programmer error
}
query := sq.
Select().
From("tracker_webhook_subscription sub").
Where("sub.tracker_id = ?", trackerID)
q.Schedule(ctx, query, "tracker", "label:delete", encoded)
}