Implement notification for upcoming tasks via a daily fired rake-task.

This commit is contained in:
Benjamin Meichsner 2009-02-10 15:07:47 +01:00
parent 053593f718
commit 67743cd014
7 changed files with 54 additions and 9 deletions

View file

@ -37,5 +37,14 @@ class Mailer < ActionMailer::Base
:link => url_for(:host => request.host, :controller => "login", :action => "invite", :id => invite.token),
:foodsoftUrl => url_for(:host => request.host, :controller => "index")
end
# Notify user of upcoming task.
def notify_upcoming_tasks(user, task)
subject "[#{APP_CONFIG[:name]}] Aufgaben werden fällig!"
recipients user.email
from "FoodSoft <#{APP_CONFIG[:email_sender]}>"
body :user => user, :task => task
end
end

View file

@ -22,6 +22,7 @@ class Task < ActiveRecord::Base
named_scope :non_group, :conditions => { :workgroup_id => nil, :done => false }
named_scope :done, :conditions => {:done => true}, :order => "due_date ASC"
named_scope :upcoming, lambda { |*args| {:conditions => ["done = 0 AND due_date = ?", (args.first || 7.days.from_now)]} }
# form will send user in string. responsibilities will added later
attr_protected :users

View file

@ -53,12 +53,13 @@ class User < ActiveRecord::Base
# returns the User-settings and the translated description
def self.setting_keys
{
"notify.orderFinished" => 'Get message with order result',
"notify.negativeBalance" => 'Get message if negative account balance',
"messages.sendAsEmail" => 'Get messages as emails',
"profile.phoneIsPublic" => 'Phone is visible for foodcoop members',
"profile.emailIsPublic" => 'Email is visible for foodcoop members',
"profile.nameIsPublic" => 'Name is visible for foodcoop members'
"notify.orderFinished" => 'Informier mich über meine Bestellergebnisse (nach Ende der Bestellung).',
"notify.negativeBalance" => 'Informiere mich, falls meine Bestellgruppe ins Minus rutscht.',
"notify.upcoming_tasks" => 'Erinnere mich an anstehende Aufgaben.',
"messages.sendAsEmail" => 'Bekomme Nachrichten als Emails.',
"profile.phoneIsPublic" => 'Telefon ist für Mitglieder sichtbar',
"profile.emailIsPublic" => 'E-Mail ist für Mitglieder sichtbar',
"profile.nameIsPublic" => 'Name ist für Mitglieder sichtbar'
}
end
# retuns the default setting for a NEW user
@ -67,7 +68,8 @@ class User < ActiveRecord::Base
def settings_default(setting)
# define a default for the settings
defaults = {
"messages.sendAsEmail" => true
"messages.sendAsEmail" => true,
"notify.upcoming_tasks" => true
}
return true if self.new_record? && defaults[setting]
end

View file

@ -0,0 +1,17 @@
Liebe(r) <%= @user.name %>,
Du bist für "<%= @task.name -%>" eingetragen. Die Aufgabe ist morgen (<%= @task.due_date.strftime("%d. %b") -%>) fällig!
<% if @user.next_tasks.size > 1 -%>
Aufgaben für die nächste Woche:
<% for next_task in @user.next_tasks -%>
<% unless next_task == @task -%>
* <%= next_task.due_date.strftime("%d.%m.") -%> <%= next_task.name %>
<% end -%>
<% end -%>
<% end -%>
Viele Grüße von <%= APP_CONFIG[:name] %>
--
Meine Aufgaben: <%= APP_CONFIG[:base_url] %>/home/tasks