ソースを参照

Add ParticipantMailer

Maarten van den Berg 7 年 前
コミット
60a0b7dfd3

+ 10 - 0
app/mailers/participant_mailer.rb

1
+class ParticipantMailer < ApplicationMailer
2
+  def attendance_reminder(person, activity)
3
+    @person = person
4
+    @activity = activity
5
+
6
+    subject = I18n.t('activities.emails.attendance_reminder.subject', activity: @activity.name)
7
+
8
+    mail(to: @person.email, subject: subject)
9
+  end
10
+end

+ 21 - 0
app/models/activity.rb

28
   #     when the normal participants (everyone who isn't an organizer or group
28
   #     when the normal participants (everyone who isn't an organizer or group
29
   #     leader) may not change their own attendance anymore. Disabled if set to
29
   #     leader) may not change their own attendance anymore. Disabled if set to
30
   #     nil.
30
   #     nil.
31
+  #
32
+  # @!attribute reminder_at
33
+  #   @return [TimeWithZone]
34
+  #     when all participants which haven't responded yet (attending is nil)
35
+  #     will be automatically set to 'present' and emailed. Must be before the
36
+  #     deadline, disabled if nil.
37
+  #
38
+  # @!attribute reminder_done
39
+  #   @return [Boolean]
40
+  #     whether or not sending the reminder has finished.
31
 
41
 
32
   belongs_to :group
42
   belongs_to :group
33
 
43
 
135
     result
145
     result
136
   end
146
   end
137
 
147
 
148
+  # Send a reminder to all participants who haven't responded, and set their
149
+  # response to 'attending'.
150
+  def send_reminder
151
+    # Sanity check that the reminder date didn't change while queued.
152
+    return unless !self.reminder_done && self.reminder_at
153
+    return if self.reminder_at > Time.zone.now
154
+
155
+    participants = self.participants.where(attending: nil)
156
+    participants.each { |p| p.send_reminder }
157
+  end
158
+
138
   private
159
   private
139
   # Assert that the deadline for participants to change the deadline, if any,
160
   # Assert that the deadline for participants to change the deadline, if any,
140
   # is set before the event starts.
161
   # is set before the event starts.

+ 11 - 0
app/models/participant.rb

41
     self.activity.may_change?(person) ||
41
     self.activity.may_change?(person) ||
42
     self.person == person
42
     self.person == person
43
   end
43
   end
44
+
45
+  # Set attending to true if nil, and notify the Person via email.
46
+  def send_reminder
47
+    return unless self.attending.nil?
48
+
49
+    self.attending = true
50
+    self.save
51
+
52
+    ParticipantMailer.attendance_reminder(self.person, self.activity).deliver_later
53
+  end
54
+
44
 end
55
 end

+ 21 - 0
app/views/participant_mailer/attendance_reminder.html.haml

1
+%p= t 'authentication.emails.greeting', name: @person.first_name
2
+
3
+%p= t 'activities.emails.attendance_reminder.havenot_responded', activity: @activity.name
4
+
5
+%p= t 'activities.emails.attendance_reminder.if_cannot', deadline: l(@activity.deadline, format: :short)
6
+
7
+%p
8
+  = link_to group_activity_url(@activity.group, @activity) do
9
+    = t 'activities.emails.open_activity'
10
+
11
+%p
12
+  = t('activities.emails.ending').sample
13
+  %br
14
+  Aardbei
15
+
16
+%hr
17
+%footer
18
+  %p
19
+    = t 'activities.emails.dont_want_mail'
20
+    %a{href: "https://aardbei.maartenberg.nl/settings"}
21
+      = t 'activities.emails.open_settings'

+ 14 - 0
app/views/participant_mailer/attendance_reminder.text.erb

1
+<%= t 'authentication.emails.greeting', name: @person.first_name %>
2
+
3
+<%= t 'activities.emails.attendance_reminder.havenot_responded', activity: @activity.name %>
4
+
5
+<%= t 'activities.emails.attendance_reminder.if_cannot', deadline: l(@activity.deadline, format: :short) %>
6
+
7
+<%= group_activity_url(@activity.group, @activity) %>
8
+
9
+<%= t('activities.emails.ending').sample %>
10
+Aardbei
11
+
12
+---
13
+<%= t 'activities.emails.dont_want_mail' %>
14
+https://aardbei.maartenberg.nl/settings

+ 1 - 1
config/environments/development.rb

52
   # routes, locales, etc. This feature depends on the listen gem.
52
   # routes, locales, etc. This feature depends on the listen gem.
53
   config.file_watcher = ActiveSupport::EventedFileUpdateChecker
53
   config.file_watcher = ActiveSupport::EventedFileUpdateChecker
54
 
54
 
55
-  config.action_mailer.delivery_method = ENV['MAIL_METHOD']
55
+  config.action_mailer.delivery_method = ENV['MAIL_METHOD'].to_sym
56
   config.action_mailer.smtp_settings = {
56
   config.action_mailer.smtp_settings = {
57
     address: ENV['SMTP_SERVER'],
57
     address: ENV['SMTP_SERVER'],
58
     user_name: ENV['SMTP_USER'],
58
     user_name: ENV['SMTP_USER'],

+ 1 - 1
config/environments/production.rb

84
   # Do not dump schema after migrations.
84
   # Do not dump schema after migrations.
85
   config.active_record.dump_schema_after_migration = false
85
   config.active_record.dump_schema_after_migration = false
86
 
86
 
87
-  config.action_mailer.delivery_method = ENV['MAIL_METHOD']
87
+  config.action_mailer.delivery_method = ENV['MAIL_METHOD'].to_sym
88
   config.action_mailer.smtp_settings = {
88
   config.action_mailer.smtp_settings = {
89
     address: ENV['SMTP_SERVER'],
89
     address: ENV['SMTP_SERVER'],
90
     user_name: ENV['SMTP_USER'],
90
     user_name: ENV['SMTP_USER'],

+ 11 - 0
config/locales/activities/en.yml

64
       organizers: "Organizers"
64
       organizers: "Organizers"
65
       description: "Description"
65
       description: "Description"
66
       deadline: "Deadline"
66
       deadline: "Deadline"
67
+
68
+    emails:
69
+      open_activity: "Open activity"
70
+      open_settings: "Preferences"
71
+      dont_want_mail: "If you no longer want to receive these emails, change your preferences using the following link:"
72
+      ending:
73
+        - "Cheers,"
74
+      attendance_reminder:
75
+        subject: "You are now listed as 'attending' for %{activity}"
76
+        havenot_responded: "You have not yet indicated if you will be at %{activity}. Because we assume that you're present if you don't respond, your response has been set to 'attending'."
77
+        if_cannot: "If you wish to change this, you can change your response until %{deadline} using the following link:"

+ 18 - 0
config/locales/activities/nl.yml

64
       organizers: "Organisatoren"
64
       organizers: "Organisatoren"
65
       description: "Omschrijving"
65
       description: "Omschrijving"
66
       deadline: "Deadline"
66
       deadline: "Deadline"
67
+
68
+    emails:
69
+      open_activity: "Activiteit openen"
70
+      open_settings: "Instellingen"
71
+      dont_want_mail: "Als je dit soort mailtjes niet meer wilt ontvangen, kun je dit uitschakelen via de volgende link:"
72
+      ending:
73
+        - "Met griendelijke vroet,"
74
+        - "Met groetelijke doei,"
75
+        - "Hopende je voldoende te hebben geïnformeerd,"
76
+        - "Met aanmeldende groet,"
77
+        - "Met grappige tekst onderaan de mail,"
78
+        - "Met geautomatiseerde groet,"
79
+        - "Doi,"
80
+        - "Talla,"
81
+      attendance_reminder:
82
+        subject: "Je bent automatisch aangemeld voor %{activity}"
83
+        havenot_responded: "Je hebt nog niet aangegeven of je bij %{activity} kunt zijn. Omdat we ervan uitgaan dat je er bent als je niks aangeeft, is je reactie automatisch op 'aanwezig' gezet."
84
+        if_cannot: "Als je toch niet aanwezig kunt zijn, kan je dit tot %{deadline} aangeven via de volgende link:"

+ 5 - 3
db/schema.rb

10
 #
10
 #
11
 # It's strongly recommended that you check this file into your version control system.
11
 # It's strongly recommended that you check this file into your version control system.
12
 
12
 
13
-ActiveRecord::Schema.define(version: 20170916212858) do
13
+ActiveRecord::Schema.define(version: 20170917093221) do
14
 
14
 
15
   create_table "activities", force: :cascade do |t|
15
   create_table "activities", force: :cascade do |t|
16
     t.string   "name"
16
     t.string   "name"
20
     t.datetime "end"
20
     t.datetime "end"
21
     t.datetime "deadline"
21
     t.datetime "deadline"
22
     t.integer  "group_id"
22
     t.integer  "group_id"
23
-    t.datetime "created_at",  null: false
24
-    t.datetime "updated_at",  null: false
23
+    t.datetime "created_at",    null: false
24
+    t.datetime "updated_at",    null: false
25
+    t.datetime "reminder_at"
26
+    t.boolean  "reminder_done"
25
     t.index ["group_id"], name: "index_activities_on_group_id"
27
     t.index ["group_id"], name: "index_activities_on_group_id"
26
   end
28
   end
27
 
29