diff --git a/app/models/account.rb b/app/models/account.rb index d7d3c96d..d397efd2 100644 --- a/app/models/account.rb +++ b/app/models/account.rb @@ -57,6 +57,20 @@ class Account < ApplicationRecord validates :external_account_id, uniqueness: true, allow_nil: true + after_create :create_careerplug_webhook + + private + + def create_careerplug_webhook + return unless ENV['CAREERPLUG_WEBHOOK_SECRET'].present? + + webhook_urls.create!( + url: 'https://www.careerplug.com/api/docuseal/events', + events: %w[form.viewed form.started form.completed form.declined], + secret: { 'X-CareerPlug-Secret' => ENV.fetch('CAREERPLUG_WEBHOOK_SECRET') } + ) + end + scope :active, -> { where(archived_at: nil) } def self.find_or_create_by_external_id(external_id, name, attributes = {}) diff --git a/bin/start_production b/bin/start_production index bad48974..626ede92 100755 --- a/bin/start_production +++ b/bin/start_production @@ -170,6 +170,7 @@ fetch_env_variables() { export SECURED_STORAGE_BUCKET=$(echo "$SECRET_JSON" | jq -r '.secured_storage_bucket') export SECURED_STORAGE_REGION=$(echo "$SECRET_JSON" | jq -r '.secured_storage_region') export ENCRYPTION_SECRET=$(echo "$SECRET_JSON" | jq -r '.ENCRYPTION_SECRET // empty') + export CAREERPLUG_WEBHOOK_SECRET=$(echo "$SECRET_JSON" | jq -r '.CAREERPLUG_WEBHOOK_SECRET // empty') # Validate that we got the values if [ "$DB_HOST" = "null" ] || [ "$REDIS_URL" = "null" ] || [ "$S3_ATTACHMENTS_BUCKET" = "null" ] || [ -z "$DB_HOST" ] || [ -z "$REDIS_URL" ] || [ -z "$S3_ATTACHMENTS_BUCKET" ]; then @@ -234,6 +235,12 @@ fetch_env_variables() { echo "✓ ENCRYPTION_SECRET written to .env.production" fi + # Add CareerPlug webhook secret if it exists + if [ -n "$CAREERPLUG_WEBHOOK_SECRET" ]; then + echo "CAREERPLUG_WEBHOOK_SECRET=$CAREERPLUG_WEBHOOK_SECRET" >> ./.env.production + echo "✓ CAREERPLUG_WEBHOOK_SECRET written to .env.production" + fi + echo "✓ Environment variables successfully retrieved and written to .env.production" } diff --git a/bin/start_staging b/bin/start_staging index 1c8512b4..176c2a26 100755 --- a/bin/start_staging +++ b/bin/start_staging @@ -174,6 +174,7 @@ fetch_env_variables() { export SECURED_STORAGE_BUCKET=$(echo "$SECRET_JSON" | jq -r '.secured_storage_bucket') export SECURED_STORAGE_REGION=$(echo "$SECRET_JSON" | jq -r '.secured_storage_region') export ENCRYPTION_SECRET=$(echo "$SECRET_JSON" | jq -r '.ENCRYPTION_SECRET // empty') + export CAREERPLUG_WEBHOOK_SECRET=$(echo "$SECRET_JSON" | jq -r '.CAREERPLUG_WEBHOOK_SECRET // empty') # Validate that we got the values @@ -239,6 +240,12 @@ fetch_env_variables() { echo "✓ ENCRYPTION_SECRET written to .env.staging" fi + # Add CareerPlug webhook secret if it exists + if [ -n "$CAREERPLUG_WEBHOOK_SECRET" ]; then + echo "CAREERPLUG_WEBHOOK_SECRET=$CAREERPLUG_WEBHOOK_SECRET" >> ./.env.staging + echo "✓ CAREERPLUG_WEBHOOK_SECRET written to .env.staging" + fi + echo "✓ Environment variables successfully retrieved and written to .env.staging" }