Implement notification for upcoming tasks via a daily fired rake-task.
This commit is contained in:
parent
053593f718
commit
67743cd014
7 changed files with 54 additions and 9 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
17
app/views/mailer/notify_upcoming_tasks.html.erb
Normal file
17
app/views/mailer/notify_upcoming_tasks.html.erb
Normal 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
|
|
@ -144,7 +144,9 @@ class RoadToVersionThree < ActiveRecord::Migration
|
|||
# t.datetime :created_at
|
||||
# end
|
||||
|
||||
|
||||
# == User
|
||||
# Ativate all Users for notification on upcoming tasks
|
||||
User.all.each { |u| u.settings['notify.upcoming_tasks'] = 1 }
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
#
|
||||
# It's strongly recommended to check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema.define(:version => 20090120184410) do
|
||||
ActiveRecord::Schema.define(:version => 20090119155930) do
|
||||
|
||||
create_table "article_categories", :force => true do |t|
|
||||
t.string "name", :default => "", :null => false
|
||||
|
|
|
@ -24,4 +24,18 @@ namespace :foodsoft do
|
|||
puts "Joining 'admin' user to 'Administrators' group"
|
||||
Membership.create(:group => administrators, :user => admin)
|
||||
end
|
||||
|
||||
desc "Notify users of upcoming tasks"
|
||||
task :notify_upcoming_tasks => :environment do
|
||||
tasks = Task.find :all, :conditions => ["done = ? AND due_date = ?", false, 1.day.from_now.to_date]
|
||||
for task in tasks
|
||||
puts "Send notifications for #{task.name} to .."
|
||||
for user in task.users
|
||||
if user.settings['notify.upcoming_tasks'] == 1
|
||||
puts "#{user.email}.."
|
||||
Mailer.deliver_notify_upcoming_tasks(user,task)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue