]> git.openstreetmap.org Git - rails.git/commitdiff
Send notification emails when someone comments on a map bug report
authorKai Krueger <kakrueger@gmail.com>
Wed, 27 Apr 2011 18:01:52 +0000 (12:01 -0600)
committerKai Krueger <kakrueger@gmail.com>
Wed, 27 Apr 2011 18:01:52 +0000 (12:01 -0600)
app/controllers/map_bugs_controller.rb
app/models/notifier.rb
app/views/notifier/bug_comment_notification.html.erb [new file with mode: 0644]
config/locales/en.yml

index bbde2148f3cfd0fa20972c3642c45651e333e69f..a967384b6ab1da4ef7a1178621178499fcf952c2 100644 (file)
@@ -311,7 +311,18 @@ private
     end
     bug_comment.save; 
     bug.last_changed = t 
-    bug.save 
+    bug.save
+
+       sent_to = Set.new;
+       bug.map_bug_comment.each do | cmt |
+         if cmt.user
+               unless sent_to.include?(cmt.user)
+          Notifier.deliver_bug_comment_notification(bug_comment, cmt.user) unless cmt.user == @user;
+          sent_to.add(cmt.user);
+        end
+      end
+    end
+       
   end
 
 end
index e6058d4b7374e486e51e37ce91e7b1707047c092..d3c975df98255cd6c0a0e8258a12d98bb211f218 100644 (file)
@@ -95,6 +95,24 @@ class Notifier < ActionMailer::Base
     body :friend => friend
   end
 
+  def bug_comment_notification(bug_comment, recipient)
+    common_headers recipient
+    commenter_name = bug_comment.user.display_name if bug_comment.user
+    commenter_name = bug_comment.commenter_name unless bug_comment.user
+       owner = (recipient == bug_comment.map_bug.map_bug_comment[0].user);
+    subject I18n.t('notifier.map_bug_plain.subject_own', :commenter => commenter_name) if owner
+    subject I18n.t('notifier.map_bug_plain.subject_other', :commenter => commenter_name) unless owner
+
+    body :bugurl => url_for(:host => SERVER_URL,
+                            :controller => "browse",
+                            :action => "bug",
+                            :id => bug_comment.bug_id),
+         :place => bug_comment.map_bug.nearby_place,
+         :comment => bug_comment.comment,
+         :owner => owner,
+         :commenter => commenter_name
+  end
+
 private
 
   def common_headers(recipient)
diff --git a/app/views/notifier/bug_comment_notification.html.erb b/app/views/notifier/bug_comment_notification.html.erb
new file mode 100644 (file)
index 0000000..ff8ad42
--- /dev/null
@@ -0,0 +1,15 @@
+<%= t 'notifier.map_bug_plain.greeting' %>
+
+<% if @owner %>
+<%= t 'notifier.map_bug_plain.your_bug', :commenter => @commenter, :place => @place %>
+<% else %>
+<%= t 'notifier.map_bug_plain.commented_bug', :commenter => @commenter, :place => @place %>
+<% end %>
+
+==
+<%= @comment %>
+==
+
+<%= t 'notifier.map_bug_plain.details', :URL => @bugurl %>
+
+
index e57bbd050d944eb645779cc74b3e93a0e49d9e87..667a6faeb76e6a1a659c92eaac170e14ec036b20 100644 (file)
@@ -1176,6 +1176,14 @@ en:
       greeting: "Hi,"
       hopefully_you: "Someone (possibly you) has asked for the password to be reset on this email address's openstreetmap.org account."
       click_the_link: "If this is you, please click the link below to reset your password."
+    map_bug_plain:
+      subject_own: "[OpenStreetMap bugs] {{commenter}} has commented on one of your bugs"
+      subject_other: "[OpenStreetMap bugs] {{commenter}} has commented on a bug you are interested in"
+      greeting: "Hi,"
+      your_bug: "{{commenter}} has left a comment on one of your map bug reports near {{place}}."
+      commented_bug: "{{commenter}} has left a comment on a map bug report you have commented on. The bug is near {{place}}."
+      details: "More details about the bug report can be found at {{URL}}."
+
   message:
     inbox:
       title: "Inbox"