diff --git a/Gemfile b/Gemfile index 55e72eb6..e5858e6e 100644 --- a/Gemfile +++ b/Gemfile @@ -223,6 +223,9 @@ gem 'nokogiri', '>= 1.8.1' # memcached binary connector gem 'dalli' +# Unsubscribe from email +gem 'mailkick' + # Use guard and spring for testing in development group :development do # to launch specs when files are modified diff --git a/Gemfile.lock b/Gemfile.lock index 36198fa8..7ddcce27 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -280,6 +280,8 @@ GEM lumberjack (1.0.12) mail (2.7.1) mini_mime (>= 0.1.1) + mailkick (0.4.0) + activesupport (>= 5) marcel (0.3.3) mimemagic (~> 0.3.2) method_source (0.8.2) @@ -669,6 +671,7 @@ DEPENDENCIES json-schema leaflet-rails letter_opener + mailkick mina mini_magick money-rails diff --git a/app/models/user.rb b/app/models/user.rb index 1ff0e96c..a98d9828 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -8,6 +8,7 @@ end class User < ApplicationRecord rolify + mailkick_user # prevent N+1 queries with has_cached_role? by preloading roles *always* default_scope { preload(:roles) } diff --git a/db/migrate/20190721210158_install_mailkick.rb b/db/migrate/20190721210158_install_mailkick.rb new file mode 100644 index 00000000..9114d460 --- /dev/null +++ b/db/migrate/20190721210158_install_mailkick.rb @@ -0,0 +1,14 @@ +class InstallMailkick < ActiveRecord::Migration[5.2] + def change + create_table :mailkick_opt_outs do |t| + t.string :email + t.references :user, polymorphic: true + t.boolean :active, null: false, default: true + t.string :reason + t.string :list + t.timestamps + end + + add_index :mailkick_opt_outs, :email + end +end diff --git a/db/schema.rb b/db/schema.rb index 683eb437..676833f6 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: 2019_06_12_161235) do +ActiveRecord::Schema.define(version: 2019_07_21_210158) do create_table "answers", force: :cascade do |t| t.string "title" @@ -278,6 +278,19 @@ ActiveRecord::Schema.define(version: 2019_06_12_161235) do t.string "picture" end + create_table "mailkick_opt_outs", force: :cascade do |t| + t.string "email" + t.string "user_type" + t.integer "user_id" + t.boolean "active", default: true, null: false + t.string "reason" + t.string "list" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + t.index ["email"], name: "index_mailkick_opt_outs_on_email" + t.index ["user_type", "user_id"], name: "index_mailkick_opt_outs_on_user_type_and_user_id" + end + create_table "openids", force: :cascade do |t| t.string "provider" t.string "email"