tkh_mailing_list 0.10.8 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 79e7f2d1bcf1082d3e6cbb42d3d1e43beab37915
4
- data.tar.gz: bc8e8b09e5c8a6db8476740a7fc31d62cc4de28d
3
+ metadata.gz: 1eecb38e812f46f5e40069794c1be970d36be891
4
+ data.tar.gz: bce8b79dd8ce25258d181204835affb5117bfee7
5
5
  SHA512:
6
- metadata.gz: 197b80d185e0ef02fa998073c8c58cf88b7d16b84a6ee103e13c2ffe20169107edb3e9f4f11dfeb11dce7b8d1aa8ab480c824959d00a1230c4800ac154628150
7
- data.tar.gz: 2252628d85d811eea547a4fc0a3437cc801f268a54e2de6311d27d1558e664bd4254dc72bec6f5ced9b62c1c93e20f3b24e2d7898ab8b3422b4d0ed22507eac9
6
+ metadata.gz: 96dee981407fd5ca0ed6098cb52b3118432f563ba3144f4ad6b7f5019a2d2353d81ada1ff2beb23ae726a16c8fb3ef2086a7d7bb811288bc0ea5728dd2ceb906
7
+ data.tar.gz: 4fc3bb44ff2c7b9de54c4c736f4f9adb6caf6e88d6627f490a15ffd8ba9b4022f3f748ccc57530a67000d8606188bae49e7c57d4a4b89ffa023aec2abf14fac9
data/CHANGELOG.md CHANGED
@@ -2,6 +2,11 @@
2
2
 
3
3
 
4
4
 
5
+ ## 0.10.9
6
+
7
+ * Created an admin daily digest email. The rake task can be called from a cron job.
8
+
9
+
5
10
  ## 0.10.8
6
11
 
7
12
  * Removed html_safe method from flash messages in profiles update method. Message is rawified in tkh_toolbox gem.
@@ -0,0 +1,73 @@
1
+ class ContactsController < ApplicationController
2
+
3
+ before_action :authenticate, :except => 'create'
4
+ before_action :authenticate_with_admin, :except => 'create'
5
+
6
+ def index
7
+ @contacts = Contact.by_recent.paginate(:page => params[:page], :per_page => 35)
8
+ switch_to_admin_layout
9
+ end
10
+
11
+ def show
12
+ @contact = Contact.find(params[:id])
13
+ switch_to_admin_layout
14
+ end
15
+
16
+ def create
17
+ @contact = Contact.new(contact_params)
18
+ saved = @contact.save
19
+ # disabling this and replacing it with a daily digest
20
+ # this is to mitigate the pain associated with contact spams
21
+ # sent_email = send_message_to_admin(@contact)
22
+ # if saved && sent_email == 'success'
23
+ # redirect_to root_path, notice: t("contacts.create.notice")
24
+ # elsif saved && sent_email == 'exception'
25
+ # flash[:error] = t("contacts.create.warning")
26
+ # redirect_to :back
27
+ # elsif saved && sent_email == 'invalid'
28
+ # flash[:error] = "#{t("contacts.create.warning")} #{t('contacts.create.invalid_email')}"
29
+ # redirect_to :back
30
+ # else
31
+ # flash[:error] = t('contacts.create.did_not_reach')
32
+ # redirect_to :back
33
+ # end
34
+
35
+ if saved
36
+ redirect_to root_path, notice: t("contacts.create.notice")
37
+ else
38
+ redirect_to :back, alert: t('contacts.create.did_not_reach')
39
+ end
40
+ end
41
+
42
+ def valid_email?(string)
43
+ (!string.blank? && string =~ /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i) ? true : false
44
+ end
45
+ # helper_method :valid_email?
46
+
47
+ private
48
+
49
+ # disabled to be replaced by daily digest to admins
50
+ # def send_message_to_admin(contact)
51
+ # # check email validity
52
+ # if valid_email?(contact.sender_email)
53
+ # # Actually send the email to the student
54
+ # begin
55
+ # ContactMailer.message_from_contact_form(contact).deliver
56
+ # return 'success'
57
+ # rescue Exception => e
58
+ # AdminMailer.rescued_exceptions(e, "Some exception occurred while trying to send to site admin a message from contact form").deliver
59
+ # @exception = e
60
+ # return 'exception'
61
+ # end
62
+ # else # for invalid or blank emails
63
+ # return 'invalid'
64
+ # end
65
+ # end
66
+
67
+ # Never trust parameters from the scary internet, only allow the white list through.
68
+ def contact_params
69
+ params.require(:contact).permit(:sender_name, :sender_email, :body)
70
+ end
71
+
72
+
73
+ end
@@ -0,0 +1,16 @@
1
+ class AdministrationMailer < ActionMailer::Base
2
+
3
+ default :from => "#{Setting.first.try(:company_name)} <#{Setting.first.try(:contact_email)}>"
4
+
5
+ def daily_digest( admin_user, yesterdays_contact_messages )
6
+ @recipient = admin_user
7
+ @contact_messages = yesterdays_contact_messages
8
+ # FIXME - only the email addresses show up. not the names :-(
9
+ recipient = "#{@recipient.name} <#{@recipient.email}>"
10
+ reply_to = "#{Setting.first.try(:company_name)} <#{Setting.first.try(:contact_email)}>"
11
+ mail to: recipient,
12
+ reply_to: reply_to,
13
+ subject: "#{t('admin.mailer.daily_digest.subject')}- #{l Time.zone.now.to_date}"
14
+ end
15
+
16
+ end
@@ -0,0 +1,23 @@
1
+ class ContactMailer < ActionMailer::Base
2
+
3
+ # This feature has been suspended. It's meant to be replaced by an admin daily digest.
4
+
5
+ # default :from => "info@yoga.lu"
6
+
7
+ # Subject can be set in your I18n file at config/locales/en.yml
8
+ # with the following lookup:
9
+ #
10
+ # en.user_mailer.password_reset.subject
11
+ #
12
+ def message_from_contact_form(contact)
13
+ @contact = contact
14
+ # FIXME - only the email addresses show up. not the names :-(
15
+ # TODO - what do to if contact_email is not set?
16
+ recipient = "#{Setting.first.try(:company_name)} <#{Setting.first.try(:contact_email)}>"
17
+ reply_to = "#{@contact.sender_name} <#{@contact.sender_email}>"
18
+ mail to: recipient,
19
+ from: "#{Setting.first.site_name} <deploy@mailcenter.tenthousandhours.eu>",
20
+ reply_to: reply_to,
21
+ subject: "Message from #{@contact.sender_name} via #{Setting.first.try(:site_name)} web site"
22
+ end
23
+ end
@@ -0,0 +1,28 @@
1
+ class Administration < ActiveRecord::Base
2
+
3
+ def self.send_daily_digest
4
+ digest_is_needed = false
5
+ @yesterdays_contact_messages = Contact.yesterdays.chronologically
6
+ digest_is_needed = true if @yesterdays_contact_messages.count > 0
7
+ if digest_is_needed
8
+ User.administrators.each do |administrator|
9
+ send_message_to_admin(administrator)
10
+ end
11
+ end
12
+ end
13
+
14
+ private
15
+
16
+ def self.send_message_to_admin(recipient)
17
+ # Actually send the email to the administrator
18
+ begin
19
+ AdministrationMailer.daily_digest( recipient, @yesterdays_contact_messages ).deliver_now
20
+ return 'success'
21
+ rescue Exception => e
22
+ AdminMailer.rescued_exceptions(e, "Some exception occurred while trying to send to site admin a message from contact form").deliver
23
+ @exception = e
24
+ return 'exception'
25
+ end
26
+ end
27
+
28
+ end
@@ -0,0 +1,12 @@
1
+ class Contact < ActiveRecord::Base
2
+
3
+ validates_presence_of :sender_name
4
+ validates_presence_of :sender_email
5
+ # validates :sender_email, :presence => true, :format => { :with => /\A([\A@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})\z/i, :on => :create }
6
+ validates_presence_of :body
7
+
8
+ scope :yesterdays, lambda { where('created_at >= ? AND created_at <= ?', 1.day.ago.beginning_of_day, 1.day.ago.end_of_day ) }
9
+ scope :chronologically, -> { order('created_at') }
10
+ scope :by_recent, -> { order('created_at desc') }
11
+
12
+ end
@@ -0,0 +1,13 @@
1
+ Hi <%= @recipient.friendly_name %>,
2
+
3
+ This a summary of what happened yesterday on the <%= Setting.first.try(:site_name) %> website.
4
+
5
+ List of messages from the contact form:
6
+
7
+ <% @contact_messages.each do |message| %>
8
+ <%= "- from #{message.sender_name} (#{message.sender_email}): #{truncate message.body}" %>
9
+ <% end %>
10
+
11
+ You can see and manage these messages at: <%= contacts_url %>
12
+
13
+ You are receiving this email because you are an administrator of the <%= Setting.first.try(:site_name) %> website.
@@ -0,0 +1,12 @@
1
+ <%= t('contacts.mailer.intro') %>
2
+
3
+ - <%= t('contacts.mailer.sender_name') %> <%= @contact.sender_name %>
4
+ - <%= t('contacts.mailer.sender_email') %> <%= @contact.sender_email %>
5
+
6
+ <%= t('contacts.mailer.message') %>
7
+
8
+ -----------------------------------
9
+
10
+ <%= @contact.body %>
11
+
12
+ -----------------------------------
@@ -0,0 +1,9 @@
1
+ <%= simple_form_for Contact.new do |f| %>
2
+ <%= f.error_notification %>
3
+
4
+ <%= f.input :sender_name, label: t('activerecord.attributes.contacts.sender_name') %>
5
+ <%= f.input :sender_email, label: t('activerecord.attributes.contacts.sender_email') %>
6
+ <%= f.input :body, label: t('activerecord.attributes.contacts.body'), :input_html => { :rows => 10 } %>
7
+
8
+ <%= f.button :submit, t('contacts.send_message'), :class => 'btn btn-primary' %>
9
+ <% end %>
@@ -0,0 +1,4 @@
1
+ <ul class="nav nav-tabs" id="admin-menu-tab">
2
+ <%= content_tag :li, link_to(t('list'), contacts_path), ({ class: 'active' } if controller.action_name.to_s == 'index' ) %>
3
+ <%= content_tag :li, link_to(t('view'), contacts_path), ({ class: 'active' }) if controller.action_name.to_s == 'show' %>
4
+ </ul>
@@ -0,0 +1,30 @@
1
+ <h1><%= t 'activerecord.models.contacts' %></h1>
2
+ <%= render 'tab_admin_menu' %>
3
+
4
+ <table class='table table-striped'>
5
+ <thead>
6
+ <tr>
7
+ <th><%= t 'activerecord.attributes.contacts.sender_name' %></th>
8
+ <th><%= t 'activerecord.attributes.contacts.sender_email' %></th>
9
+ <th><%= t 'activerecord.attributes.contacts.body' %></th>
10
+ <th><%= t 'contacts.sent' %></th>
11
+ <th><%= t('actions') %></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <% @contacts.each do |contact| %>
17
+ <tr>
18
+ <td><%= contact.sender_name %></td>
19
+ <td><%= link_to contact.sender_email, "mailto:#{contact.sender_email}" %></td>
20
+ <td><%= truncate contact.body, length: 85, separator: ' ...' %></td>
21
+ <td><%= l contact.created_at, :format => :tkh_default %></td>
22
+ <td><%= link_to "<span class=\"glyphicon glyphicon-eye-open\"></span>&nbsp;#{t('view')}".html_safe, contact, class: 'btn btn-xs btn-default' %></td>
23
+ </tr>
24
+ <% end %>
25
+ </tbody>
26
+ </table>
27
+
28
+ <%= will_paginate @contacts %>
29
+
30
+ <%= render 'shared/admin_sidebar' %>
@@ -0,0 +1,18 @@
1
+ <h1><%= t('activerecord.models.contacts') %></h1>
2
+
3
+ <%= render 'tab_admin_menu' %>
4
+
5
+ <h2><%= "#{t('contacts.sent')}#{t('colon')} #{ l(@contact.created_at, :format => :tkh_default) }" %></h2>
6
+
7
+ <p>
8
+ <%= "#{t('activerecord.attributes.contacts.sender_name').capitalize}#{t('colon')} #{@contact.sender_name}" %><br />
9
+ <%= "#{t('activerecord.attributes.contacts.sender_email')}#{t('colon')} #{link_to(@contact.sender_email, "mailto:#{@contact.sender_email}")}".capitalize.html_safe %>
10
+ </p>
11
+ <h3><%= t('activerecord.attributes.contacts.body').capitalize %></h3>
12
+ <p><%= sanitize @contact.body.gsub(/\r\n?/, "<br>"), :tags => %w(br), :attributes => %w() %></p>
13
+
14
+ <hr>
15
+
16
+ <p><%= link_to t('list'), contacts_path, class: 'btn' %></p>
17
+
18
+ <%= render 'shared/admin_sidebar' %>
data/config/routes.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  Rails.application.routes.draw do
2
2
  scope "(:locale)", locale: /#{I18n.available_locales.join("|")}/ do
3
3
 
4
+ resources :contacts
5
+
4
6
  # Mailing list records for admin
5
7
  resources :details # deprecated. Should disappear soon.
6
8
 
@@ -1,5 +1,15 @@
1
1
  de:
2
2
 
3
+ activerecord:
4
+ models:
5
+ contact: 'Kontakt'
6
+ contacts: 'Kontakte'
7
+ attributes:
8
+ contacts:
9
+ sender_name: "Absender-Name"
10
+ sender_email: 'Absender-Email'
11
+ body: 'Nachricht'
12
+
3
13
  details:
4
14
  create:
5
15
  notice: 'This user has been created.'
@@ -21,3 +31,23 @@ de:
21
31
  destroy:
22
32
  notice: 'This user has been deleted.'
23
33
  warning: 'A problem occurred while deleting this user.'
34
+
35
+ contacts:
36
+ messages_from_forms: 'Nachrichten vom Kontaktformular'
37
+ send_message: 'Nachricht senden'
38
+ sent: 'Gesendet am'
39
+ create:
40
+ did_not_reach: 'Etwas ist schief gegangen. Deine Nachricht hat den gewünschten Adressaten nicht erreicht.'
41
+ invalid_email: 'Deine Emai-Adresse scheint ungültig zu sein!'
42
+ notice: 'Die Nachricht wurde gesendet.'
43
+ warning: 'Beim Versenden der Nachricht gab es ein Problem.'
44
+ mailer:
45
+ intro: 'Hier ist die Nachricht vom Kontaktformular der Webseite:'
46
+ sender_name: "Absendername:"
47
+ sender_email: "Absender-Email:"
48
+ message: 'Nachricht'
49
+
50
+ admin:
51
+ mailer:
52
+ daily_digest:
53
+ subject: "Admin Daily Digest"
@@ -1,5 +1,15 @@
1
1
  en:
2
2
 
3
+ activerecord:
4
+ models:
5
+ contact: 'contact'
6
+ contacts: 'contacts'
7
+ attributes:
8
+ contacts:
9
+ sender_name: "sender name"
10
+ sender_email: 'sender email'
11
+ body: 'message'
12
+
3
13
  details:
4
14
  create:
5
15
  notice: 'This user has been created.'
@@ -22,3 +32,24 @@ en:
22
32
  destroy:
23
33
  notice: 'This user has been deleted.'
24
34
  warning: 'A problem occurred while deleting this user.'
35
+
36
+
37
+ contacts:
38
+ messages_from_forms: 'messages from contact form'
39
+ send_message: 'send message'
40
+ sent: 'Sent at'
41
+ create:
42
+ did_not_reach: 'Something went wrong. Your message did not reach the intended recipient.'
43
+ invalid_email: 'Your email address does not seem to be valid!'
44
+ notice: 'Thank you. We have received your message.'
45
+ warning: 'There was a problem sending your message.'
46
+ mailer:
47
+ intro: 'Here is the message sent via the contact form on the web site:'
48
+ sender_name: "Sender's name:"
49
+ sender_email: "Sender's email:"
50
+ message: 'Message:'
51
+
52
+ admin:
53
+ mailer:
54
+ daily_digest:
55
+ subject: "Admin Daily Digest"
@@ -1,5 +1,15 @@
1
1
  es:
2
2
 
3
+ activerecord:
4
+ models:
5
+ contact: 'contact'
6
+ contacts: 'contacts'
7
+ attributes:
8
+ contacts:
9
+ sender_name: "nombre del remitente"
10
+ sender_email: 'correo electrónico del remitente'
11
+ body: 'mensaje'
12
+
3
13
  details:
4
14
  create:
5
15
  notice: 'This user has been created.'
@@ -21,3 +31,23 @@ es:
21
31
  destroy:
22
32
  notice: 'This user has been deleted.'
23
33
  warning: 'A problem occurred while deleting this user.'
34
+
35
+ contacts:
36
+ messages_from_forms: 'mensajes del formulario de contacto'
37
+ send_message: 'enviar el mensaje'
38
+ sent: 'Enviado a las'
39
+ create:
40
+ did_not_reach: 'Something went wrong. Your message did not reach the intended recipient.'
41
+ invalid_email: 'Your email address does not seem to be valid!'
42
+ notice: 'Tu mensaje ha sido enviado.'
43
+ warning: 'Hubo un problema al enviar su mensaje.'
44
+ mailer:
45
+ intro: 'Here is the message sent via the contact form on the web site:'
46
+ sender_name: "Sender's name:"
47
+ sender_email: "Sender's email:"
48
+ message: 'Message:'
49
+
50
+ admin:
51
+ mailer:
52
+ daily_digest:
53
+ subject: "Admin Daily Digest"
@@ -1,5 +1,16 @@
1
1
  fr:
2
2
 
3
+ activerecord:
4
+ models:
5
+ contact: 'contact'
6
+ contacts: 'les contacts'
7
+ attributes:
8
+ contacts:
9
+ sender_name: "votre nom"
10
+ sender_email: "votre adresse email"
11
+ body: 'contenu du message'
12
+
13
+
3
14
  details:
4
15
  create:
5
16
  notice: 'Un nouvel utilisateur a été ajouté à la base de données.'
@@ -21,3 +32,23 @@ fr:
21
32
  destroy:
22
33
  notice: "Cet utilisateur n'est plus dans la base de données."
23
34
  warning: "Il y a eu un problème qui n'a pas permis d'éléliminer cet utilisateur"
35
+
36
+ contacts:
37
+ messages_from_forms: 'messages du formulaire de contact'
38
+ send_message: 'envoyez le message'
39
+ sent: 'Envoyé le'
40
+ create:
41
+ did_not_reach: "Il y a eu un problem. Le message n'a pas été acheminé a sa destination."
42
+ invalid_email: 'Votre adresse courriel ne semble pas bonne !'
43
+ notice: 'Merci. Nous avons bien reçu votre message.'
44
+ warning: "Il y'a eu un probleme en envoyant votre message."
45
+ mailer:
46
+ intro: 'Voici le message envoyé par un visiteur avec le formulaire de contact sur le site web :'
47
+ sender_name: "Nom de l'auteur :"
48
+ sender_email: "Adresse courriel de l'auteur :"
49
+ message: 'Message :'
50
+
51
+ admin:
52
+ mailer:
53
+ daily_digest:
54
+ subject: "Résumé d'activité"
@@ -19,6 +19,7 @@ module TkhMailingList
19
19
  puts 'creating teacher and profile migrations'
20
20
  migration_template "add_teacher_status_to_users.rb", "db/migrate/add_teacher_status_to_users.rb"
21
21
  migration_template "add_profile_fields_to_users.rb", "db/migrate/add_profile_fields_to_users.rb"
22
+ migration_template "create_contacts.rb", "db/migrate/create_contacts.rb"
22
23
  end
23
24
 
24
25
  end
@@ -0,0 +1,19 @@
1
+ class CreateContacts < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :contacts do |t|
5
+ t.string :sender_name
6
+ t.string :sender_email
7
+ t.text :body
8
+
9
+ t.timestamps
10
+ end
11
+ add_index :contacts, :updated_at
12
+ end
13
+
14
+ def self.down
15
+ drop_table :contacts
16
+ remove_index :contacts, :updated_at
17
+ end
18
+
19
+ end
@@ -10,4 +10,9 @@ namespace :tkh_mailing_list do
10
10
  system 'rails g tkh_mailing_list:create_or_update_migrations -s'
11
11
  system 'rails g tkh_mailing_list:create_or_update_locales -f'
12
12
  end
13
+
14
+ desc "Send to the administrators a email digest of important activities."
15
+ task :daily_admin_digest do
16
+ Administration.send_daily_digest
17
+ end
13
18
  end
@@ -1,3 +1,3 @@
1
1
  module TkhMailingList
2
- VERSION = "0.10.8"
2
+ VERSION = "0.10.9"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tkh_mailing_list
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.8
4
+ version: 0.10.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Swami Atma
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-23 00:00:00.000000000 Z
11
+ date: 2015-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -56,14 +56,25 @@ files:
56
56
  - app/assets/javascripts/jquery.jcrop.min.js
57
57
  - app/assets/javascripts/profiles.js.coffee
58
58
  - app/assets/stylesheets/jquery.jcrop.min.css.scss
59
+ - app/controllers/contacts_controller.rb
59
60
  - app/controllers/details_controller.rb
60
61
  - app/controllers/members_controller.rb
61
62
  - app/controllers/profiles_controller.rb
62
63
  - app/helpers/members_helper.rb
64
+ - app/mailers/administration_mailer.rb
65
+ - app/mailers/contact_mailer.rb
66
+ - app/models/administration.rb
67
+ - app/models/contact.rb
63
68
  - app/models/detail.rb
64
69
  - app/models/member.rb
65
70
  - app/models/profile.rb
66
71
  - app/uploaders/portrait_uploader.rb
72
+ - app/views/administration_mailer/daily_digest.text.erb
73
+ - app/views/contact_mailer/message_from_contact_form.text.erb
74
+ - app/views/contacts/_form.html.erb
75
+ - app/views/contacts/_tab_admin_menu.html.erb
76
+ - app/views/contacts/index.html.erb
77
+ - app/views/contacts/show.html.erb
67
78
  - app/views/details/_form.html.erb
68
79
  - app/views/details/_tab_admin_menu.html.erb
69
80
  - app/views/details/edit.html.erb
@@ -94,6 +105,7 @@ files:
94
105
  - lib/generators/tkh_mailing_list/create_or_update_migrations/create_or_update_migrations_generator.rb
95
106
  - lib/generators/tkh_mailing_list/create_or_update_migrations/templates/add_profile_fields_to_users.rb
96
107
  - lib/generators/tkh_mailing_list/create_or_update_migrations/templates/add_teacher_status_to_users.rb
108
+ - lib/generators/tkh_mailing_list/create_or_update_migrations/templates/create_contacts.rb
97
109
  - lib/tasks/tkh_mailing_list_tasks.rake
98
110
  - lib/tkh_mailing_list.rb
99
111
  - lib/tkh_mailing_list/version.rb