aboutsummaryrefslogtreecommitdiff
path: root/site/app
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-06 20:50:58 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2011-06-10 18:11:42 +0200
commita79293f652cedf63f9f3cd88107e98b9b4da99f3 (patch)
treee4621b126b132c31c6d65e250f962fd1d7a6eb24 /site/app
parentBot obtains voters, agenda items and voting options lists from webapp (diff)
downloadcouncil-webapp-a79293f652cedf63f9f3cd88107e98b9b4da99f3.tar.gz
council-webapp-a79293f652cedf63f9f3cd88107e98b9b4da99f3.tar.bz2
council-webapp-a79293f652cedf63f9f3cd88107e98b9b4da99f3.zip
Send email reminders about meetings using delayed_job
Diffstat (limited to 'site/app')
-rw-r--r--site/app/mailers/user_mailer.rb6
-rw-r--r--site/app/models/agenda.rb43
-rw-r--r--site/app/views/user_mailer/meeting_reminder.erb5
3 files changed, 51 insertions, 3 deletions
diff --git a/site/app/mailers/user_mailer.rb b/site/app/mailers/user_mailer.rb
index c5c18f8..d9515f3 100644
--- a/site/app/mailers/user_mailer.rb
+++ b/site/app/mailers/user_mailer.rb
@@ -7,4 +7,10 @@ class UserMailer < ActionMailer::Base
:to => user.email )
end
+ def meeting_reminder(user, agenda)
+ @user = user
+ @agenda = agenda
+ mail(:subject => "Upcoming meeting reminder - #{agenda.meeting_time.to_s}",
+ :to => user.email)
+ end
end
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index 22414d7..ea58041 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -3,7 +3,8 @@ class Agenda < ActiveRecord::Base
hobo_model # Don't put anything above this
fields do
- meeting_time :datetime
+ meeting_time :datetime
+ email_reminder_sent :boolean, :null => false, :default => false
timestamps
end
@@ -101,7 +102,12 @@ class Agenda < ActiveRecord::Base
end
end
- def self.voters
+ def time_for_reminders
+ offset = CustomConfig['Reminders']['hours_before_meeting_to_send_email_reminders'].hours
+ meeting_time - offset
+ end
+
+ def self.voters_users
# It's possible to rewrite this as SQL, but
# * this method is rarely called
# * it fetches little data
@@ -109,7 +115,38 @@ class Agenda < ActiveRecord::Base
# Joachim
council = ::User.council_member_is(true)
proxies = Agenda.current.proxies
- [council - proxies.*.council_member + proxies.*.proxy].flatten.*.irc_nick
+ [council - proxies.*.council_member + proxies.*.proxy].flatten
+ end
+
+ def self.voters
+ Agenda.voters_users.*.irc_nick
+ end
+
+ def self.send_current_agenda_reminders
+ agenda = Agenda.current
+
+ return if agenda.email_reminder_sent?
+ return if Time.now < agenda.time_for_reminders
+
+ for user in Agenda.voters_users
+ UserMailer.delay.deliver_meeting_reminder(user, agenda)
+ end
+
+ agenda.email_reminder_sent = true
+ agenda.save!
+ end
+
+ before_save do |a|
+ return true if a.new_record?
+ return true unless a.meeting_time_changed?
+ a.email_reminder_sent = false
+ true
+ end
+
+ after_save do |a|
+ if a.new_record? or a.meeting_time_changed?
+ Agenda.delay(:run_at => a.time_for_reminders).send_current_agenda_reminders
+ end
end
protected
diff --git a/site/app/views/user_mailer/meeting_reminder.erb b/site/app/views/user_mailer/meeting_reminder.erb
new file mode 100644
index 0000000..b49e7e6
--- /dev/null
+++ b/site/app/views/user_mailer/meeting_reminder.erb
@@ -0,0 +1,5 @@
+<%= @user %>,
+
+meeting will take place on <%= @agenda.meeting_time.to_s %>. You can view agenda for the meeting on:
+
+ <%= agenda_url(@agenda) %>