diff --git a/app/controllers/unsubscribes_controller.rb b/app/controllers/unsubscribes_controller.rb new file mode 100644 index 00000000..1e764d2a --- /dev/null +++ b/app/controllers/unsubscribes_controller.rb @@ -0,0 +1,23 @@ +class UnsubscribesController < ApplicationController + def new + end + + def create + if unsubscribe_email.present? + if user = User.find_by(email: unsubscribe_email) + user.update(can_be_emailed: false) + end + + render :success + else + render :new + end + end + + private + + def unsubscribe_email + params[:unsubscribe][:email] + end + helper_method :unsubscribe_email +end diff --git a/app/javascript/src/css/default/Button.css b/app/javascript/src/css/default/Button.css new file mode 100644 index 00000000..37cd21a2 --- /dev/null +++ b/app/javascript/src/css/default/Button.css @@ -0,0 +1,16 @@ +.btn { + background-color: #404458; + border: none; + color: white; + padding: 15px 32px; + text-align: center; + text-decoration: none; + display: inline-block; + font-size: 16px; + border-radius: 3px; +} + +.btn:hover { + background-color: #525670; + cursor: pointer; +} diff --git a/app/javascript/src/global.css b/app/javascript/src/global.css index d2655b9d..333cf2d1 100644 --- a/app/javascript/src/global.css +++ b/app/javascript/src/global.css @@ -2,6 +2,7 @@ @import './reset.css'; @import './css/default/AdventureHeader.css'; @import './css/default/Badge.css'; +@import './css/default/Button.css'; @import './css/default/Brand.css'; @import './css/default/Footer.css'; @@ -23,7 +24,7 @@ main { .screenreader-only { border: 0; - clip: rect(0,0,0,0); + clip: rect(0, 0, 0, 0); height: 1px; margin: -1px; overflow: hidden; diff --git a/app/mailers/application_mailer.rb b/app/mailers/application_mailer.rb index 286b2239..5ed4ad9e 100644 --- a/app/mailers/application_mailer.rb +++ b/app/mailers/application_mailer.rb @@ -1,4 +1,4 @@ class ApplicationMailer < ActionMailer::Base - default from: 'from@example.com' + default from: 'no-reply@storyboard.viget.com' layout 'mailer' end diff --git a/app/mailers/survey_mailer.rb b/app/mailers/survey_mailer.rb new file mode 100644 index 00000000..46ff41e3 --- /dev/null +++ b/app/mailers/survey_mailer.rb @@ -0,0 +1,9 @@ +class SurveyMailer < ApplicationMailer + default from: "Storyboard Team " + + def initial_feedback(user) + @user = user + + mail(to: user.email, subject: "Storyboard User Survey") + end +end diff --git a/app/views/survey_mailer/initial_feedback.html.erb b/app/views/survey_mailer/initial_feedback.html.erb new file mode 100644 index 00000000..961525fb --- /dev/null +++ b/app/views/survey_mailer/initial_feedback.html.erb @@ -0,0 +1,36 @@ +

+ Hello, +

+ +

+ Storyboard is conducting an online survey to gather user feedback and to learn more about how people use Storyboard. Your input would be incredibly helpful, and be used to inform the future of Storyboard. +

+ +

+ All respondents who complete the survey will be entered in a drawing to win a $20 Amazon.com gift card. +

+ +

+ It should take 5-10 minutes to complete. You may access the survey using the link below. +

+ +

+ <%= link_to "https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey", "https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey" %> +

+ +

+ If you have any questions, you can contact Laura Sweltz at laura.sweltz@viget.com. +

+ +

+ Thank you, +
+ Storyboard Team +

+ +
+
+ +

+ Don’t want to hear from us again? <%= link_to "Unsubscribe here", new_unsubscribe_url(email: @user.email) %>. +

diff --git a/app/views/survey_mailer/initial_feedback.text.erb b/app/views/survey_mailer/initial_feedback.text.erb new file mode 100644 index 00000000..8dffde5a --- /dev/null +++ b/app/views/survey_mailer/initial_feedback.text.erb @@ -0,0 +1,17 @@ +Hello, + +Storyboard is conducting an online survey to gather user feedback and to learn more about how people use Storyboard. Your input would be incredibly helpful. + +All respondents who complete the survey will be entered in a drawing to win a $20 Amazon.com gift card. + +It should take 5-10 minutes to complete. You may access the survey using the link below. + +https://www.surveygizmo.com/s3/5759951/Storyboard-User-Survey + +If you have any questions, you can contact Laura Sweltz at laura.sweltz@viget.com. + +Thank you, +Storyboard Team + +================================================================ +Don’t want to hear from us again? Unsubscribe here: <%= new_unsubscribe_url(email: @user.email) %>. diff --git a/app/views/unsubscribes/new.html.erb b/app/views/unsubscribes/new.html.erb new file mode 100644 index 00000000..9f837cea --- /dev/null +++ b/app/views/unsubscribes/new.html.erb @@ -0,0 +1,10 @@ +
+ <%= form_for :unsubscribe, url: unsubscribes_path do |f| %> +
+ <%= f.label :email %> + <%= f.email_field :email, value: params[:email] %> +
+ + <%= f.submit "Unsubscribe", class: "btn" %> + <% end %> +
diff --git a/app/views/unsubscribes/success.html.erb b/app/views/unsubscribes/success.html.erb new file mode 100644 index 00000000..ed10d868 --- /dev/null +++ b/app/views/unsubscribes/success.html.erb @@ -0,0 +1,5 @@ +
+

+ We've removed <%= unsubscribe_email %> from our mailing list. Fare thee well. +

+
diff --git a/config/application.rb b/config/application.rb index fda0a5e1..1b44bafb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -21,6 +21,8 @@ class Application < Rails::Application # Initialize configuration defaults for originally generated Rails version. config.load_defaults 5.2 + config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews" + # Settings in config/environments/* take precedence over those specified here. # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading diff --git a/config/database.yml b/config/database.yml index e5afa59c..15c16c14 100644 --- a/config/database.yml +++ b/config/database.yml @@ -17,7 +17,10 @@ default: &default adapter: postgresql encoding: unicode - host: db + + # Uncomment this line if you're running in Docker + # host: db + # For details on connection pooling, see Rails configuration guide # http://guides.rubyonrails.org/configuring.html#database-pooling pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> diff --git a/config/routes.rb b/config/routes.rb index 3419349b..01e3645d 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -17,6 +17,9 @@ post "/api/:id", to: "api/adventures#update" get "/api/:id", to: "api/adventures#show" + get "unsubscribe", to: "unsubscribes#new", as: :new_unsubscribe + resources :unsubscribes, only: [:create] + # Keep this block at the bottom so the "/:id adventures#show" # doesn't catch other routes resources :adventures, path: "/" do diff --git a/db/migrate/20200806131054_add_can_be_emailed_to_users.rb b/db/migrate/20200806131054_add_can_be_emailed_to_users.rb new file mode 100644 index 00000000..54b22a0c --- /dev/null +++ b/db/migrate/20200806131054_add_can_be_emailed_to_users.rb @@ -0,0 +1,5 @@ +class AddCanBeEmailedToUsers < ActiveRecord::Migration[5.2] + def change + add_column :users, :can_be_emailed, :boolean, default: true + end +end diff --git a/db/schema.rb b/db/schema.rb index cfd559ba..296e97cd 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_05_27_151913) do +ActiveRecord::Schema.define(version: 2020_08_06_131054) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -54,6 +54,7 @@ t.inet "last_sign_in_ip" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "can_be_emailed", default: true t.index ["email"], name: "index_users_on_email", unique: true t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true end diff --git a/lib/mailer_previews/survey_mailer_preview.rb b/lib/mailer_previews/survey_mailer_preview.rb new file mode 100644 index 00000000..de2ff54e --- /dev/null +++ b/lib/mailer_previews/survey_mailer_preview.rb @@ -0,0 +1,5 @@ +class SurveyMailerPreview < ActionMailer::Preview + def initial_feedback + SurveyMailer.initial_feedback(User.first) + end +end