diff --git a/Gemfile b/Gemfile index 8b10c0e7..2a67142e 100644 --- a/Gemfile +++ b/Gemfile @@ -19,6 +19,7 @@ gem 'honeybadger' gem 'jbuilder', '~> 2.5' gem 'jquery-rails' gem 'pg', '~> 1.1' +gem 'postmark-rails' gem 'puma', '~> 3.12' gem 'rack-cors', require: 'rack/cors' gem 'rails', '~> 5.2.2' diff --git a/Gemfile.lock b/Gemfile.lock index b45ebe43..d016e45e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -190,6 +190,11 @@ GEM capybara (~> 2.1) cliver (~> 0.3.1) websocket-driver (>= 0.2.0) + postmark (1.21.1) + json + postmark-rails (0.20.0) + actionmailer (>= 3.0.0) + postmark (~> 1.15) pry (0.11.3) coderay (~> 1.1.0) method_source (~> 0.9.0) @@ -340,6 +345,7 @@ DEPENDENCIES pg (~> 1.1) phantomjs poltergeist + postmark-rails pry-rails puma (~> 3.12) rack-cors @@ -359,4 +365,4 @@ RUBY VERSION ruby 2.5.1p57 BUNDLED WITH - 1.16.1 + 1.17.3 diff --git a/app/controllers/api/v1/send_grid/events_controller.rb b/app/controllers/api/v1/send_grid/events_controller.rb deleted file mode 100644 index 69a8e6b7..00000000 --- a/app/controllers/api/v1/send_grid/events_controller.rb +++ /dev/null @@ -1,12 +0,0 @@ -class Api::V1::SendGrid::EventsController < Api::V1::ApiController - skip_before_action :doorkeeper_authorize!, only: [:update] - - def update - webhook_data = JSON.parse(request.body.read) - webhook_data.each do |data| - invitation = Invitation.find_by(email: data["email"]) - invitation.status = data["event"] if invitation - invitation.save - end - end -end diff --git a/config/application.rb b/config/application.rb index 69186c23..571eb69e 100644 --- a/config/application.rb +++ b/config/application.rb @@ -18,17 +18,9 @@ module Census class Application < Rails::Application - config.action_mailer.delivery_method = :smtp - - config.action_mailer.smtp_settings = { - address: 'smtp.sendgrid.net', - port: '587', - domain: 'heroku.com', - user_name: ENV["SENDGRID_USERNAME"], - password: ENV["SENDGRID_PASSWORD"], - authentication: 'plain', - enable_starttls_auto: true - } + # Set up transactional emails through Postmark + config.action_mailer.delivery_method = :postmark + config.action_mailer.postmark_settings = { api_token: Rails.application.secrets.postmark_api_token } config.log_tags = [ :request_id, diff --git a/config/routes.rb b/config/routes.rb index 0e8fcde1..c67e01f9 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -49,7 +49,6 @@ resources :groups, only: [:update, :destroy] get '/cohorts', to: 'cohorts#index' get '/user_credentials', to: 'credentials#show' - post '/sendgrid/events', to: 'send_grid/events#update' end end end diff --git a/config/secrets.yml b/config/secrets.yml index 0eafe40d..ab7701cc 100644 --- a/config/secrets.yml +++ b/config/secrets.yml @@ -15,3 +15,4 @@ production: api_auth_secret: <%= ENV.fetch("API_AUTH_SECRET", "no-api-secret-set") %> enroll_graphql_endpoint: <%= ENV.fetch("ENROLL_GRAPHQL_ENDPOINT", "http://localhost:3001/graphql") %> require_ssl_redirect_uri: <%= ENV.fetch('REQUIRE_SSL_REDIRECT_URI', 'true') == 'true' %> + postmark_api_token: <%= ENV['POSTMARK_API_TOKEN'] %> diff --git a/spec/requests/api/v1/send_grid/events_spec.rb b/spec/requests/api/v1/send_grid/events_spec.rb deleted file mode 100644 index 24707262..00000000 --- a/spec/requests/api/v1/send_grid/events_spec.rb +++ /dev/null @@ -1,14 +0,0 @@ -require 'rails_helper' - -RSpec.describe Api::V1::SendGrid::EventsController do - context "Post request is sent to SendGrid" do - it "updates status of bounced email" do - create :invitation, email: "email@example.com", status: "mailed" - post_body = [{event: "bounce", email: "email@example.com"}].to_json - post '/api/v1/sendgrid/events', params: post_body - - expect(Invitation.first.bounce?).to eq(true) - expect(response.status).to eq(204) - end - end -end