mirror of
https://github.com/abhinavxd/libredesk.git
synced 2025-10-23 05:11:57 +00:00
fix: remove headers field from webhook model and related queries
This commit is contained in:
@@ -9,15 +9,14 @@ import (
|
||||
|
||||
// Webhook represents a webhook configuration
|
||||
type Webhook struct {
|
||||
ID int `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
Name string `db:"name" json:"name"`
|
||||
URL string `db:"url" json:"url"`
|
||||
Events pq.StringArray `db:"events" json:"events"`
|
||||
Secret string `db:"secret" json:"secret,omitempty"`
|
||||
IsActive bool `db:"is_active" json:"is_active"`
|
||||
Headers json.RawMessage `db:"headers" json:"headers"`
|
||||
ID int `db:"id" json:"id"`
|
||||
CreatedAt time.Time `db:"created_at" json:"created_at"`
|
||||
UpdatedAt time.Time `db:"updated_at" json:"updated_at"`
|
||||
Name string `db:"name" json:"name"`
|
||||
URL string `db:"url" json:"url"`
|
||||
Events pq.StringArray `db:"events" json:"events"`
|
||||
Secret string `db:"secret" json:"secret,omitempty"`
|
||||
IsActive bool `db:"is_active" json:"is_active"`
|
||||
}
|
||||
|
||||
// WebhookEvent represents an event that can trigger a webhook
|
||||
|
@@ -7,8 +7,7 @@ SELECT
|
||||
url,
|
||||
events,
|
||||
secret,
|
||||
is_active,
|
||||
headers
|
||||
is_active
|
||||
FROM
|
||||
webhooks
|
||||
ORDER BY created_at DESC;
|
||||
@@ -22,8 +21,7 @@ SELECT
|
||||
url,
|
||||
events,
|
||||
secret,
|
||||
is_active,
|
||||
headers
|
||||
is_active
|
||||
FROM
|
||||
webhooks
|
||||
WHERE
|
||||
@@ -38,8 +36,7 @@ SELECT
|
||||
url,
|
||||
events,
|
||||
secret,
|
||||
is_active,
|
||||
headers
|
||||
is_active
|
||||
FROM
|
||||
webhooks
|
||||
WHERE
|
||||
@@ -55,8 +52,7 @@ SELECT
|
||||
url,
|
||||
events,
|
||||
secret,
|
||||
is_active,
|
||||
headers
|
||||
is_active
|
||||
FROM
|
||||
webhooks
|
||||
WHERE
|
||||
@@ -65,9 +61,9 @@ WHERE
|
||||
|
||||
-- name: insert-webhook
|
||||
INSERT INTO
|
||||
webhooks (name, url, events, secret, is_active, headers)
|
||||
webhooks (name, url, events, secret, is_active)
|
||||
VALUES
|
||||
($1, $2, $3, $4, $5, $6)
|
||||
($1, $2, $3, $4, $5)
|
||||
RETURNING id;
|
||||
|
||||
-- name: update-webhook
|
||||
@@ -79,7 +75,6 @@ SET
|
||||
events = $4,
|
||||
secret = $5,
|
||||
is_active = $6,
|
||||
headers = $7,
|
||||
updated_at = NOW()
|
||||
WHERE
|
||||
id = $1;
|
||||
|
@@ -120,7 +120,7 @@ func (m *Manager) Get(id int) (models.Webhook, error) {
|
||||
// Create creates a new webhook.
|
||||
func (m *Manager) Create(webhook models.Webhook) (int, error) {
|
||||
var id int
|
||||
if err := m.q.InsertWebhook.Get(&id, webhook.Name, webhook.URL, pq.Array(webhook.Events), webhook.Secret, webhook.IsActive, webhook.Headers); err != nil {
|
||||
if err := m.q.InsertWebhook.Get(&id, webhook.Name, webhook.URL, pq.Array(webhook.Events), webhook.Secret, webhook.IsActive); err != nil {
|
||||
if dbutil.IsUniqueViolationError(err) {
|
||||
return 0, envelope.NewError(envelope.ConflictError, m.i18n.Ts("globals.messages.errorAlreadyExists", "name", "webhook"), nil)
|
||||
}
|
||||
@@ -132,7 +132,7 @@ func (m *Manager) Create(webhook models.Webhook) (int, error) {
|
||||
|
||||
// Update updates a webhook by ID.
|
||||
func (m *Manager) Update(id int, webhook models.Webhook) error {
|
||||
if _, err := m.q.UpdateWebhook.Exec(id, webhook.Name, webhook.URL, pq.Array(webhook.Events), webhook.Secret, webhook.IsActive, webhook.Headers); err != nil {
|
||||
if _, err := m.q.UpdateWebhook.Exec(id, webhook.Name, webhook.URL, pq.Array(webhook.Events), webhook.Secret, webhook.IsActive); err != nil {
|
||||
m.lo.Error("error updating webhook", "error", err)
|
||||
return envelope.NewError(envelope.GeneralError, m.i18n.Ts("globals.messages.errorUpdating", "name", "webhook"), nil)
|
||||
}
|
||||
@@ -274,16 +274,6 @@ func (m *Manager) deliverWebhook(task DeliveryTask) {
|
||||
req.Header.Set("Content-Type", "application/json")
|
||||
req.Header.Set("User-Agent", "Libredesk-Webhook/1.0")
|
||||
|
||||
// Add custom headers
|
||||
if len(webhook.Headers) > 0 {
|
||||
var headers map[string]string
|
||||
if err := json.Unmarshal(webhook.Headers, &headers); err == nil {
|
||||
for key, value := range headers {
|
||||
req.Header.Set(key, value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add signature if secret is provided
|
||||
if webhook.Secret != "" {
|
||||
signature := m.generateSignature(payloadBytes, webhook.Secret)
|
||||
|
Reference in New Issue
Block a user