diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-06 21:15:25 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-10 18:12:21 +0200 |
commit | 1faf786442e393fd56cfc1a016196d87f64825f8 (patch) | |
tree | d2c1d0a31a05f91ef9bb713abcfd244c2487b5eb | |
parent | Send email reminders about meetings using delayed_job (diff) | |
download | council-webapp-1faf786442e393fd56cfc1a016196d87f64825f8.tar.gz council-webapp-1faf786442e393fd56cfc1a016196d87f64825f8.tar.bz2 council-webapp-1faf786442e393fd56cfc1a016196d87f64825f8.zip |
agenda/reminders page lists users that bot should remind about meeting
and gives some additional information to avoid multiple pings
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 4 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 16 | ||||
-rw-r--r-- | site/config/routes.rb | 1 | ||||
-rw-r--r-- | site/doc/sample_configs/reminders.yml | 1 | ||||
-rw-r--r-- | site/spec/models/agenda_spec.rb | 18 |
5 files changed, 36 insertions, 4 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb index ce84f1f..e0fd813 100644 --- a/site/app/controllers/agendas_controller.rb +++ b/site/app/controllers/agendas_controller.rb @@ -17,6 +17,10 @@ class AgendasController < ApplicationController Agenda.process_results JSON.parse(request.env["rack.input"].read) end + def reminders + render :json => Agenda.irc_reminders + end + private def authenticate_bot authenticate_or_request_with_http_basic do |user_name, password| diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index ea58041..55bc6cd 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -102,8 +102,8 @@ class Agenda < ActiveRecord::Base end end - def time_for_reminders - offset = CustomConfig['Reminders']['hours_before_meeting_to_send_email_reminders'].hours + def time_for_reminders(type) + offset = CustomConfig['Reminders']["hours_before_meeting_to_send_#{type}_reminders"].hours meeting_time - offset end @@ -126,7 +126,7 @@ class Agenda < ActiveRecord::Base agenda = Agenda.current return if agenda.email_reminder_sent? - return if Time.now < agenda.time_for_reminders + return if Time.now < agenda.time_for_reminders(:email) for user in Agenda.voters_users UserMailer.delay.deliver_meeting_reminder(user, agenda) @@ -136,6 +136,14 @@ class Agenda < ActiveRecord::Base agenda.save! end + def self.irc_reminders + agenda = Agenda.current + return {} if Time.now < agenda.time_for_reminders(:irc) + return { 'remind_time' => agenda.meeting_time.strftime('%a %b %d %H:%M:%S %Y'), + 'message' => "Remember about council meeting on #{agenda.meeting_time.to_s}", + 'users' => Agenda.voters} + end + before_save do |a| return true if a.new_record? return true unless a.meeting_time_changed? @@ -145,7 +153,7 @@ class Agenda < ActiveRecord::Base 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 + Agenda.delay(:run_at => a.time_for_reminders(:email)).send_current_agenda_reminders end end diff --git a/site/config/routes.rb b/site/config/routes.rb index 8621347..2decbe6 100644 --- a/site/config/routes.rb +++ b/site/config/routes.rb @@ -6,6 +6,7 @@ Council::Application.routes.draw do match 'users/voters' => 'users#voters', :as => 'voters' match 'agendas/current_items' => 'agendas#current_items', :as => 'current_items' match 'agendas/results' => 'agendas#results', :as => 'results' + match 'agendas/reminders' => 'agendas#reminders', :as => 'reminders' # The priority is based upon order of creation: # first created -> highest priority. diff --git a/site/doc/sample_configs/reminders.yml b/site/doc/sample_configs/reminders.yml index edf937a..df47dd2 100644 --- a/site/doc/sample_configs/reminders.yml +++ b/site/doc/sample_configs/reminders.yml @@ -1 +1,2 @@ hours_before_meeting_to_send_email_reminders: 24 +hours_before_meeting_to_send_irc_reminders: 2 diff --git a/site/spec/models/agenda_spec.rb b/site/spec/models/agenda_spec.rb index 83b31a3..32fa2ba 100644 --- a/site/spec/models/agenda_spec.rb +++ b/site/spec/models/agenda_spec.rb @@ -188,4 +188,22 @@ describe Agenda do UserMailer.should_not_receive(:delay) Agenda.send_current_agenda_reminders end + + it 'should return proper irc_reminders hash' do + CustomConfig['Reminders']["hours_befeore_meeting_to_send_irc_reminders"] = 2 + + a1 = Factory(:agenda) + users = users_factory([:council]*2 + [:user]*2) + Agenda.irc_reminders.keys.should include('remind_time') + Agenda.irc_reminders.keys.should include('message') + Agenda.irc_reminders.keys.should include('users') + + Agenda.irc_reminders['remind_time'].should == Agenda.current.meeting_time.strftime('%a %b %d %H:%M:%S %Y') + Agenda.irc_reminders['users'].should == Agenda.voters + + a1.meeting_time = 10.years.from_now + a1.save! + + Agenda.irc_reminders.should be_empty + end end |