Merge branch 'master' into features/publicity
# Conflicts: # .gitignore
This commit is contained in:
@@ -78,8 +78,6 @@ gem 'rails_admin'
|
|||||||
|
|
||||||
gem 'mongoid_paranoia'
|
gem 'mongoid_paranoia'
|
||||||
|
|
||||||
gem 'mailchimp-api', require: 'mailchimp'
|
|
||||||
|
|
||||||
group :development, :test do
|
group :development, :test do
|
||||||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
# Call 'byebug' anywhere in the code to stop execution and get a debugger console
|
||||||
gem 'byebug'
|
gem 'byebug'
|
||||||
|
|||||||
@@ -103,7 +103,6 @@ GEM
|
|||||||
dotenv (= 2.2.0)
|
dotenv (= 2.2.0)
|
||||||
railties (>= 3.2, < 5.1)
|
railties (>= 3.2, < 5.1)
|
||||||
erubis (2.7.0)
|
erubis (2.7.0)
|
||||||
excon (0.55.0)
|
|
||||||
execjs (2.7.0)
|
execjs (2.7.0)
|
||||||
factory_girl (4.8.0)
|
factory_girl (4.8.0)
|
||||||
activesupport (>= 3.0.0)
|
activesupport (>= 3.0.0)
|
||||||
@@ -145,9 +144,6 @@ GEM
|
|||||||
nokogiri (>= 1.5.9)
|
nokogiri (>= 1.5.9)
|
||||||
mail (2.6.4)
|
mail (2.6.4)
|
||||||
mime-types (>= 1.16, < 4)
|
mime-types (>= 1.16, < 4)
|
||||||
mailchimp-api (2.0.6)
|
|
||||||
excon (>= 0.16.0)
|
|
||||||
json (>= 1.7.7)
|
|
||||||
memory_profiler (0.9.8)
|
memory_profiler (0.9.8)
|
||||||
method_source (0.8.2)
|
method_source (0.8.2)
|
||||||
mime-types (3.1)
|
mime-types (3.1)
|
||||||
@@ -353,7 +349,6 @@ DEPENDENCIES
|
|||||||
jquery-rails
|
jquery-rails
|
||||||
kaminari-actionview
|
kaminari-actionview
|
||||||
kaminari-mongoid
|
kaminari-mongoid
|
||||||
mailchimp-api
|
|
||||||
mongoid (~> 5.0.0)
|
mongoid (~> 5.0.0)
|
||||||
mongoid-paperclip
|
mongoid-paperclip
|
||||||
mongoid-rspec (= 3.0.0)
|
mongoid-rspec (= 3.0.0)
|
||||||
|
|||||||
@@ -36,6 +36,6 @@ class ApplicationController < ActionController::Base
|
|||||||
protected
|
protected
|
||||||
|
|
||||||
def configure_permitted_parameters
|
def configure_permitted_parameters
|
||||||
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category, :unsubscribed])
|
devise_parameter_sanitizer.permit(:account_update, keys: [:first_name, :last_name, :street, :city, :zip, :support, :language, :age_category])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ class SupportersController < ApplicationController
|
|||||||
@supporter.password = random_password = SecureRandom.hex(5)
|
@supporter.password = random_password = SecureRandom.hex(5)
|
||||||
if !input_to_fast? && @supporter.save
|
if !input_to_fast? && @supporter.save
|
||||||
SupporterMailer.welcome_email(@supporter, random_password).deliver_now
|
SupporterMailer.welcome_email(@supporter, random_password).deliver_now
|
||||||
mailchimp_registration
|
sendy_registraion
|
||||||
redirect_to thanks_path
|
redirect_to thanks_path
|
||||||
else
|
else
|
||||||
flash.now[:danger] = input_to_fast? ? t('.timeout') : t('input_error')
|
flash.now[:danger] = input_to_fast? ? t('.timeout') : t('input_error')
|
||||||
@@ -24,20 +24,11 @@ class SupportersController < ApplicationController
|
|||||||
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
|
params.require(:supporter).permit(:first_name, :last_name, :street, :zip, :email, :support, :li_membership, :age_category, :city, :comments)
|
||||||
end
|
end
|
||||||
|
|
||||||
def mailchimp_registration
|
# We use sendy for newsletters atm
|
||||||
return unless Rails.env.production?
|
def sendy_registraion
|
||||||
mailchimp = Mailchimp::API.new(ENV['MAILCHIMP_API'])
|
uri = URI('http://newsletter.cannabis-initiative.ch/subscribe')
|
||||||
mailchimp.lists.subscribe(ENV['CH420_LIST_ID'], { 'email' => @supporter.email }, merge_vars, 'html', false)
|
Net::HTTP.post_form(uri, list: ENV["SENDY_LIST_#{I18n.locale.upcase}"],
|
||||||
end
|
email: @supporter.email,
|
||||||
|
name: "#{@supporter.first_name} #{@supporter.last_name}")
|
||||||
def merge_vars
|
|
||||||
{ 'EMAIL' => @supporter.email,
|
|
||||||
'FNAME' => @supporter.first_name,
|
|
||||||
'LNAME' => @supporter.last_name,
|
|
||||||
'SUPPORT' => @supporter.support,
|
|
||||||
'MEMBERSHIP' => @supporter.li_membership.to_s,
|
|
||||||
'AGE' => @supporter.age_category,
|
|
||||||
'LANG' => @supporter.language,
|
|
||||||
'ZIP' => @supporter.zip }
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -44,7 +44,6 @@ class Supporter
|
|||||||
field :coordinates, type: Array
|
field :coordinates, type: Array
|
||||||
field :comments, type: String
|
field :comments, type: String
|
||||||
field :language, type: String
|
field :language, type: String
|
||||||
field :unsubscribed, type: Boolean, default: false
|
|
||||||
field :duplicate, type: Boolean, default: false
|
field :duplicate, type: Boolean, default: false
|
||||||
|
|
||||||
validates :first_name, presence: true
|
validates :first_name, presence: true
|
||||||
|
|||||||
@@ -23,8 +23,6 @@
|
|||||||
dd == t("age_category.#{current_supporter.age_category}")
|
dd == t("age_category.#{current_supporter.age_category}")
|
||||||
dt = Supporter.human_attribute_name(:language)
|
dt = Supporter.human_attribute_name(:language)
|
||||||
dd = t("languages.#{current_supporter.language}")
|
dd = t("languages.#{current_supporter.language}")
|
||||||
dt = Supporter.human_attribute_name(:unsubscribed)
|
|
||||||
dd = current_supporter.unsubscribed? ? t('shared.yes') : t('shared.no')
|
|
||||||
|
|
||||||
p
|
p
|
||||||
= link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right'
|
= link_to t('.edit'), edit_supporter_registration_path(), class: 'pull-right'
|
||||||
|
|||||||
@@ -19,7 +19,6 @@
|
|||||||
= f.input :support, as: :radio_buttons, collection: t('support_type').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
|
= f.input :support, as: :radio_buttons, collection: t('support_type').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
|
||||||
= f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first
|
= f.input :age_category, as: :radio_buttons, collection: t('age_category'), label_method: :last, value_method: :first
|
||||||
= f.input :language, as: :radio_buttons, collection: t('languages').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
|
= f.input :language, as: :radio_buttons, collection: t('languages').map{ |x| [x.first, raw(x.last)]}, label_method: :last, value_method: :first
|
||||||
= f.input :unsubscribed, as: :boolean
|
|
||||||
.form-actions
|
.form-actions
|
||||||
= f.button :submit, t("devise.registrations.edit.update"), class: 'btn btn-primary'
|
= f.button :submit, t("devise.registrations.edit.update"), class: 'btn btn-primary'
|
||||||
p = link_to t("devise.shared.links.back"), :back
|
p = link_to t("devise.shared.links.back"), :back
|
||||||
|
|||||||
@@ -74,8 +74,8 @@ Rails.application.configure do
|
|||||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||||
config.log_formatter = ::Logger::Formatter.new
|
config.log_formatter = ::Logger::Formatter.new
|
||||||
|
|
||||||
config.action_mailer.default_url_options = { host: 'ch420.herokuapp.com' }
|
config.action_mailer.default_url_options = { host: 'www.cannabis-initiative.ch' }
|
||||||
config.action_mailer.asset_host = 'https://ch420.herokuapp.com'
|
config.action_mailer.asset_host = 'https://www.cannabis-initiative.ch'
|
||||||
|
|
||||||
config.action_mailer.delivery_method = :smtp
|
config.action_mailer.delivery_method = :smtp
|
||||||
config.action_mailer.smtp_settings = {
|
config.action_mailer.smtp_settings = {
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ de:
|
|||||||
remember_me: Angemeldet bleiben
|
remember_me: Angemeldet bleiben
|
||||||
password: Passwort
|
password: Passwort
|
||||||
language: Sprache
|
language: Sprache
|
||||||
unsubscribed: Kein Newsletter
|
|
||||||
password_confirmation: Passwort bestätigen
|
password_confirmation: Passwort bestätigen
|
||||||
current_password: Aktuelles Passwort
|
current_password: Aktuelles Passwort
|
||||||
publicity:
|
publicity:
|
||||||
|
|||||||
@@ -127,7 +127,6 @@ fr:
|
|||||||
remember_me: Se souvenir de moi
|
remember_me: Se souvenir de moi
|
||||||
password: mot de passe
|
password: mot de passe
|
||||||
language: Langue
|
language: Langue
|
||||||
unsubscribed: pas de newslettre
|
|
||||||
password_confirmation: confirmer le mot de passe
|
password_confirmation: confirmer le mot de passe
|
||||||
current_password: Mot de passe actuel
|
current_password: Mot de passe actuel
|
||||||
|
|
||||||
|
|||||||
@@ -128,7 +128,6 @@ it:
|
|||||||
remember_me: Ricordati di mel
|
remember_me: Ricordati di mel
|
||||||
password: Password
|
password: Password
|
||||||
language: Lingua
|
language: Lingua
|
||||||
unsubscribed: No Newsletter
|
|
||||||
password_confirmation: conferma password
|
password_confirmation: conferma password
|
||||||
current_password: Password corrente
|
current_password: Password corrente
|
||||||
publicity:
|
publicity:
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
class MailChimpBatchUpdate
|
|
||||||
def initialize(api_key, list_id)
|
|
||||||
@mailchimp = Mailchimp::API.new(api_key)
|
|
||||||
@list_id = list_id
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_all
|
|
||||||
subscribers = []
|
|
||||||
|
|
||||||
Supporter.each_with_index do |supporter, index|
|
|
||||||
subscribers.push(subscriber(supporter))
|
|
||||||
if index.modulo(20).zero?
|
|
||||||
batch_subscribe(subscribers)
|
|
||||||
subscribers = []
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
batch_subscribe(subscribers)
|
|
||||||
end
|
|
||||||
|
|
||||||
def batch_subscribe(subscribers)
|
|
||||||
@mailchimp.lists.batch_subscribe(@list_id, subscribers, false, true, false)
|
|
||||||
end
|
|
||||||
|
|
||||||
def subscriber(supporter)
|
|
||||||
{ 'EMAIL' => { 'email' => supporter.email }, 'language' => supporter.language, :EMAIL_TYPE => 'html',
|
|
||||||
:merge_vars => {
|
|
||||||
'EMAIL' => supporter.email,
|
|
||||||
'FNAME' => supporter.first_name,
|
|
||||||
'LNAME' => supporter.last_name,
|
|
||||||
'SUPPORT' => supporter.support,
|
|
||||||
'MEMBERSHIP' => supporter.li_membership.to_s,
|
|
||||||
'AGE' => supporter.age_category,
|
|
||||||
'LANG' => supporter.language,
|
|
||||||
'ZIP' => supporter.zip
|
|
||||||
} }
|
|
||||||
end
|
|
||||||
|
|
||||||
def update_unsubscibed
|
|
||||||
unsubscribed_members = @mailchimp.lists.members(@list_id, 'unsubscribed', limit: 100)
|
|
||||||
unsubscribed_members['data'].each do |member|
|
|
||||||
Supporter.where(email: member['email']).each do |supporter|
|
|
||||||
supporter.update_attributes unsubscribed: true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -21,7 +21,7 @@ feature 'Support' do
|
|||||||
sleep 5 # Do a real sleep to have a real integration test
|
sleep 5 # Do a real sleep to have a real integration test
|
||||||
|
|
||||||
expect(ActionMailer::Base.deliveries.count).to eq 0
|
expect(ActionMailer::Base.deliveries.count).to eq 0
|
||||||
expect_any_instance_of(SupportersController).to receive(:mailchimp_registration).and_return(true)
|
expect_any_instance_of(SupportersController).to receive(:sendy_registraion).and_return(true)
|
||||||
|
|
||||||
expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1)
|
expect { click_button 'Unterstützung zusichern' }.to change { Supporter.count }.by(1)
|
||||||
# expect(ActionMailer::Base.deliveries.count).to eq 1
|
# expect(ActionMailer::Base.deliveries.count).to eq 1
|
||||||
|
|||||||
Reference in New Issue
Block a user