Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ AWS_ACCESS_KEY_ID="abc"
AWS_SECRET_ACCESS_KEY="123"
AWS_REGION="us-east-1"
AWS_ENDPOINT=""
SPARKPOST_API_KEY="foo"
SENDGRID_API_KEY="foo"
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
/public/assets
.byebug_history

/coverage

# Ignore master key for decrypting credentials and more.
/config/master.key

Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ gem 'sidekiq-cron', '~> 1.1'
gem 'rails-settings-cached', '~> 0.7.2'
gem 'blazer'
gem 'simple_spark'
gem 'sparkpost_rails'
gem 'sendgrid-actionmailer'
gem 'httparty'
gem 'rollbar', '~> 2.8'
gem 'rubyzip', '>= 1.3.0'
Expand Down
10 changes: 7 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,7 @@ GEM
rollbar (2.26.0)
ruby-progressbar (1.10.1)
ruby_dep (1.5.0)
ruby_http_client (3.5.0)
ruby_parser (3.14.2)
sexp_processor (~> 4.9)
rubyzip (2.3.0)
Expand All @@ -353,6 +354,11 @@ GEM
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
rubyzip (>= 1.2.2)
sendgrid-actionmailer (3.0.2)
mail (~> 2.7)
sendgrid-ruby (~> 6.0)
sendgrid-ruby (6.3.2)
ruby_http_client (~> 3.4)
sexp_processor (4.15.0)
shellany (0.0.1)
shoulda (3.5.0)
Expand All @@ -379,8 +385,6 @@ GEM
docile (~> 1.1)
simplecov-html (~> 0.11)
simplecov-html (0.12.2)
sparkpost_rails (1.5.2)
rails (>= 4.0, < 6.1)
spring (2.1.0)
spring-watcher-listen (2.0.1)
listen (>= 2.7, < 4.0)
Expand Down Expand Up @@ -481,14 +485,14 @@ DEPENDENCIES
sass-rails (~> 6.0)
selectize-rails
selenium-webdriver
sendgrid-actionmailer
shoulda (~> 3.5)
shoulda-matchers (~> 2.0)
sidekiq (< 7)
sidekiq-cron (~> 1.1)
simple_form
simple_spark
simplecov
sparkpost_rails
spring
spring-watcher-listen (~> 2.0.0)
sprockets
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ HackathonManager makes use of a few different third-party services & Ruby gems:

- [Devise](https://github.com/plataformatec/devise) + [MyMLH](https://my.mlh.io/) (authentication & attendee identity)
- [Sidekiq](https://github.com/mperham/sidekiq) (background jobs)
- [SparkPost](https://www.sparkpost.com/) (email)
- [Amazon S3](https://aws.amazon.com/s3/) (resume storage)
- [Chartkick](http://chartkick.com/) (management UI charts)
- [SendGrid](https://sendgrid.com) (email)
- [Amazon S3](https://aws.amazon.com/s3) (resume storage)
- [Chartkick](http://chartkick.com) (management UI charts)
- [Blazer](https://github.com/ankane/blazer) (custom SQL queries, analytics, and charts)
- [Doorkeeper](https://github.com/doorkeeper-gem/doorkeeper) (authentication via OAuth for API usage)

Expand Down
8 changes: 2 additions & 6 deletions app.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@
"description": "Rollbar access token for code exception reporting",
"required": false
},
"SPARKPOST_API_KEY": {
"description": "SparkPost API key for sending email",
"required": false
},
"SPARKPOST_CAMPAIGN_ID": {
"description": "SparkPost campaign ID for sending email (e.g. the name of your hackathon)",
"SENDGRID_API_KEY": {
"description": "SendGrid API key for sending email",
"required": false
},
"HM_DOMAIN_NAME": {
Expand Down
6 changes: 1 addition & 5 deletions app/controllers/manage/questionnaires_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Manage::QuestionnairesController < Manage::ApplicationController
include QuestionnairesControllable

before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :convert_to_admin, :update_acc_status, :message_events]
before_action :set_questionnaire, only: [:show, :edit, :update, :destroy, :check_in, :convert_to_admin, :update_acc_status]

respond_to :html, :json

Expand Down Expand Up @@ -146,10 +146,6 @@ def bulk_apply
head :ok
end

def message_events
render json: @questionnaire.message_events
end

private

def questionnaire_params
Expand Down
7 changes: 0 additions & 7 deletions app/mailers/user_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,4 @@ def incomplete_reminder_email(user_id)

Message.queue_for_trigger("user.24hr_incomplete_application", @user.id)
end

rescue_from SparkPostRails::DeliveryException do |e|
error_codes_to_not_retry = [
"1902", # Generation rejection, specific to the Sparkpost API
]
raise e unless e.blank? || error_codes_to_not_retry.include?(e.service_code)
end
end
7 changes: 0 additions & 7 deletions app/models/questionnaire.rb
Original file line number Diff line number Diff line change
Expand Up @@ -191,13 +191,6 @@ def did_rsvp?
['rsvp_confirmed', 'rsvp_denied'].include? acc_status
end

def message_events
return [] unless ENV["SPARKPOST_API_KEY"].presence

simple_spark = SimpleSpark::Client.new
simple_spark.message_events.search(recipients: email)
end

def verbal_status
if acc_status == "rsvp_denied"
"Not Attending"
Expand Down
9 changes: 4 additions & 5 deletions app/views/manage/configs/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -74,21 +74,20 @@
%b Email Provider
- if Rails.application.config.action_mailer.delivery_method == :smtp
%p
%span.badge.badge-secondary SparkPost
%span.badge.badge-secondary SendGrid
%span.badge.badge-success SMTP
%br
%small
%i To switch to SparkPost, unset the <code>SMTP_ADDRESS</code> environment variable
%i To switch to SendGrid, unset the <code>SMTP_ADDRESS</code> environment variable
= render 'config_row', name: 'SMTP Address', key: 'SMTP_ADDRESS'
= render 'config_row', name: 'SMTP Port', key: 'SMTP_PORT', default: 587
= render 'config_row', name: 'SMTP Username', key: 'SMTP_USER_NAME', secret: true
= render 'config_row', name: 'SMTP Password', key: 'SMTP_PASSWORD', secret: true
- else
%p
%span.badge.badge-success SparkPost
%span.badge.badge-success SendGrid
%span.badge.badge-secondary SMTP
%br
%small
%i To switch to SMTP, set the <code>SMTP_ADDRESS</code> environment variable
= render 'config_row', name: 'SparkPost Campaign ID', key: 'SPARKPOST_CAMPAIGN_ID'
= render 'config_row', name: 'SparkPost API Key', key: 'SPARKPOST_API_KEY', secret: true
= render 'config_row', name: 'SendGrid API Key', key: 'SENDGRID_API_KEY', secret: true
14 changes: 1 addition & 13 deletions app/views/manage/questionnaires/_history.html.haml
Original file line number Diff line number Diff line change
@@ -1,18 +1,6 @@
.row
.col-lg-6
.col-lg
.card.mb-3
.card-header Recent Changes
.card-body.pb-2
= render "model_history", model: @questionnaire, audits: @questionnaire.audits + @questionnaire.user.audits

.col-lg-6
.card.mb-3
.card-header Recent Email Events
.card-body
- email_provider = Rails.application.config.action_mailer.delivery_method
- if email_provider == :sparkpost
.email-events{ data: { url: message_events_manage_questionnaire_path(@questionnaire) } }
%em Email events not available at this time.
- else
%p.alert.alert-info
Not supported with current email provider (#{email_provider})
8 changes: 6 additions & 2 deletions config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,12 @@
enable_starttls_auto: ENV["SMTP_STARTTLS_AUTO"] != "false", # defaults to true
}
else
# Send email through SparkPost API
config.action_mailer.delivery_method = :sparkpost
# Send email through SendGrid API
config.action_mailer.delivery_method = :sendgrid_actionmailer
config.action_mailer.sendgrid_actionmailer_settings = {
api_key: ENV['SENDGRID_API_KEY'],
raise_delivery_errors: true
}
end

# Required for email messages
Expand Down
7 changes: 0 additions & 7 deletions config/initializers/sparkpost_rails.rb

This file was deleted.

1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@
patch :convert_to_admin, on: :member
patch :update_acc_status, on: :member
patch :bulk_apply, on: :collection
get :message_events, on: :member
end
resources :checkins do
post :datatable, on: :collection
Expand Down
1 change: 0 additions & 1 deletion docs/api-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ Example for questionnaire management endpoints:
convert_to_admin_manage_questionnaire PATCH /manage/questionnaires/:id/convert_to_admin(.:format) manage/questionnaires#convert_to_admin
update_acc_status_manage_questionnaire PATCH /manage/questionnaires/:id/update_acc_status(.:format) manage/questionnaires#update_acc_status
bulk_apply_manage_questionnaires PATCH /manage/questionnaires/bulk_apply(.:format) manage/questionnaires#bulk_apply
message_events_manage_questionnaire GET /manage/questionnaires/:id/message_events(.:format) manage/questionnaires#message_events
manage_questionnaires GET /manage/questionnaires(.:format) manage/questionnaires#index
POST /manage/questionnaires(.:format) manage/questionnaires#create
new_manage_questionnaire GET /manage/questionnaires/new(.:format) manage/questionnaires#new
Expand Down
17 changes: 8 additions & 9 deletions docs/deployment-environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ AWS_ACCESS_KEY_ID="<AWS access key ID>"
AWS_SECRET_ACCESS_KEY="<AWS secret key>"
AWS_REGION="us-east-1"
ROLLBAR_ACCESS_TOKEN="<server-side rollbar token>"
SPARKPOST_API_KEY="<sparkpost api key>"
SPARKPOST_CAMPAIGN_ID="my-hackathon"
SENDGRID_API_KEY="<sendgrid api key>"
TIME_ZONE="America/New_York"
```

Expand Down Expand Up @@ -61,19 +60,19 @@ S3_FORCE_PATH_STYLE=true

### E-mail

Emails can be sent using [SparkPost](https://www.sparkpost.com) or traditional SMTP.
Emails can be sent using [SendGrid](https://sendgrid.com) or traditional SMTP.

#### SparkPost
#### SendGrid

[SparkPost](https://www.sparkpost.com) is the recommended email provider, and provides a free plan suitable for most hackathons.
[SendGrid](https://sendgrid.com) is the recommended email provider, and provides a free plan suitable for most hackathons.

Create a SparkPost API key with **Transmissions: Read/Write** and **Message Events: Read-only** permissions. The SMTP permission is _not_ required, as email is sent over the SparkPost API instead of SMTP.
Create a SendGrid API key to get started. During the setup process you will be asked to authenticate your sending domain with SendGrid. For guidance on this process please visit [SendGrid Domain Authentication Support](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-domain-authentication/). If you would like to maintain your sending reputation and stay out of the spam folder, we reccomend enabling [SendGrid Link Branding](https://sendgrid.com/docs/ui/account-and-settings/how-to-set-up-link-branding/) when asked during the setup process.

For added security, whitelist the API key to your server's IP address.

>During the verification process ensure you have replaced `hello@example.com` with your own domain in your HackathonManager config. SendGrid will deny the email as you are not authenticated to send on behalf of `example.com`.

```bash
SPARKPOST_API_KEY=""
SPARKPOST_CAMPAIGN_ID=""
SENDGRID_API_KEY=""
```

#### SMTP
Expand Down
24 changes: 1 addition & 23 deletions test/controllers/manage/questionnaires_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase

setup do
@questionnaire = create(:questionnaire)
stub_request(:get, /api.sparkpost.com.*/).to_return(status: 200, body: "", headers: {})
stub_request(:get, /api.sendgrid.com.*/).to_return(status: 200, body: "", headers: {})
end

context "while not authenticated" do
Expand All @@ -32,12 +32,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to new_user_session_path
end

should "not allow access to manage_questionnaires#message_events" do
get :message_events, params: { id: @questionnaire }
assert_response :redirect
assert_redirected_to new_user_session_path
end

should "not allow access to manage_questionnaires#edit" do
get :edit, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -111,12 +105,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_redirected_to root_path
end

should "not allow access to manage_questionnaires#message_events" do
get :message_events, params: { id: @questionnaire }
assert_response :redirect
assert_redirected_to root_path
end

should "not allow access to manage_questionnaires#edit" do
get :edit, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -182,11 +170,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_response :success
end

should "allow access to manage_questionnaires#message_events" do
get :message_events, params: { id: @questionnaire }
assert_response :success
end

should "not allow access to manage_questionnaires#new" do
get :new, params: { id: @questionnaire }
assert_response :redirect
Expand Down Expand Up @@ -257,11 +240,6 @@ class Manage::QuestionnairesControllerTest < ActionController::TestCase
assert_response :success
end

should "allow access to manage_questionnaires#message_events" do
get :message_events, params: { id: @questionnaire }
assert_response :success
end

should "allow access to manage_questionnaires#edit" do
get :edit, params: { id: @questionnaire }
assert_response :success
Expand Down
Binary file added vendor/cache/ruby_http_client-3.5.0.gem
Binary file not shown.
Binary file added vendor/cache/sendgrid-actionmailer-3.0.2.gem
Binary file not shown.
Binary file added vendor/cache/sendgrid-ruby-6.3.2.gem
Binary file not shown.
Binary file removed vendor/cache/sparkpost_rails-1.5.2.gem
Binary file not shown.
Loading