mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
2. Add model WebhookEndpoint [migration]
This will store the URL for each user that wants a notification. We probably don't need URL validation (it's not done on Enterprise for example). It could be validated by browser input, and anyway will be validated if the webhook actually works or not. Inspired by Keygen: https://keygen.sh/blog/how-to-build-a-webhook-system-in-rails-using-sidekiq/
This commit is contained in:
6
app/models/webhook_endpoint.rb
Normal file
6
app/models/webhook_endpoint.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
# Records a webhook url to send notifications to
|
||||
class WebhookEndpoint < ApplicationRecord
|
||||
validates :url, presence: true
|
||||
end
|
||||
11
db/migrate/20221028051650_create_webhook_endpoints.rb
Normal file
11
db/migrate/20221028051650_create_webhook_endpoints.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class CreateWebhookEndpoints < ActiveRecord::Migration[6.1]
|
||||
def change
|
||||
create_table :webhook_endpoints do |t|
|
||||
t.string :url, null: false
|
||||
|
||||
t.timestamps null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -1189,6 +1189,12 @@ ActiveRecord::Schema.define(version: 2023_02_13_160135) do
|
||||
t.index ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id"
|
||||
end
|
||||
|
||||
create_table "webhook_endpoints", force: :cascade do |t|
|
||||
t.string "url", null: false
|
||||
t.datetime "created_at", precision: 6, null: false
|
||||
t.datetime "updated_at", precision: 6, null: false
|
||||
end
|
||||
|
||||
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id"
|
||||
add_foreign_key "adjustment_metadata", "enterprises", name: "adjustment_metadata_enterprise_id_fk"
|
||||
|
||||
9
spec/models/webhook_endpoint_spec.rb
Normal file
9
spec/models/webhook_endpoint_spec.rb
Normal file
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'spec_helper'
|
||||
|
||||
describe WebhookEndpoint, type: :model do
|
||||
describe "validations" do
|
||||
it { is_expected.to validate_presence_of(:url) }
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user