]> git.openstreetmap.org Git - rails.git/commitdiff
Add methods to get a bug's author details from the first comment
authorTom Hughes <tom@compton.nu>
Sun, 8 May 2011 16:59:41 +0000 (17:59 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 17 May 2011 23:36:01 +0000 (00:36 +0100)
app/controllers/map_bugs_controller.rb
app/models/map_bug.rb
app/models/map_bug_comment.rb
app/models/notifier.rb
app/views/browse/bug.html.erb
app/views/map_bugs/my_bugs.html.erb

index 8bd45bbcdefc3ec571eeb21ac87f972d5dd71ba8..a3984347bd3cc8cd6775a8714cf3832bb66afdb8 100644 (file)
@@ -226,7 +226,7 @@ class MapBugsController < ApplicationController
     @page_size = 10
 
     @bugs = MapBug.find(:all, 
-                        :include => [:comments, {:comments => :user}],
+                        :include => [:comments, {:comments => :author}],
                         :joins => :comments,
                         :order => "updated_at DESC",
                         :conditions => conditions,
@@ -302,10 +302,10 @@ private
 
     sent_to = Set.new
     bug.comments.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)
+      if cmt.author
+        unless sent_to.include?(cmt.author)
+          Notifier.deliver_bug_comment_notification(bug_comment, cmt.author) unless cmt.author == @user
+          sent_to.add(cmt.author)
         end
       end
     end
index 2ae110bf2fcc897c30f56f8dde60f60c5e9641be..7094bfe5e7b983d373f0e8ef66d437d07f46c7c7 100644 (file)
@@ -46,4 +46,20 @@ class MapBug < ActiveRecord::Base
   def visible
     return status != "hidden"
   end
+
+  def author
+    self.comments.first.author
+  end
+
+  def author_ip
+    self.comments.first.author_ip
+  end
+
+  def author_id
+    self.comments.first.author_id
+  end
+
+  def author_name
+    self.comments.first.author_name
+  end
 end
index 28f16a9a99fead3338695658ca0167524fcc349d..9a130dd3469f82caca4c99d8460da27efff0f3ac 100644 (file)
@@ -1,8 +1,8 @@
 class MapBugComment < ActiveRecord::Base
   set_table_name 'map_bug_comment'
 
-  belongs_to :map_bug, :foreign_key => 'bug_id'
-  belongs_to :user, :foreign_key => 'author_id'
+  belongs_to :map_bug, :foreign_key => :bug_id
+  belongs_to :author, :class_name => "User", :foreign_key => :author_id
 
   validates_inclusion_of :event, :in => [ "opened", "closed", "reopened", "commented", "hidden" ]
   validates_presence_of :id, :on => :update
@@ -13,7 +13,7 @@ class MapBugComment < ActiveRecord::Base
     if self.author_id.nil?
       self.read_attribute(:author_name)
     else
-      self.user.display_name
+      self.author.display_name
     end
   end
 end
index b7cb3454d052eefa977f78be593d1384a9db6a74..e8c9259cbe2aa7107c08ff7bc803d8cabf86e3b3 100644 (file)
@@ -97,7 +97,7 @@ class Notifier < ActionMailer::Base
 
   def bug_comment_notification(bug_comment, recipient)
     common_headers recipient
-    owner = (recipient == bug_comment.map_bug.comments.first.user);
+    owner = (recipient == bug_comment.map_bug.author);
     subject I18n.t('notifier.map_bug_plain.subject_own', :commenter => bug_comment.author_name) if owner
     subject I18n.t('notifier.map_bug_plain.subject_other', :commenter => bug_comment.author_name) unless owner
 
index 4364d108880f2920dd04f48fe8c71ccffb64ada9..698532290f1bf8bdc77e5408f3e77f4ccf9def8e 100644 (file)
        <% end %>
        <tr>
          <th><%= t 'browse.bug.opened_by' %></th>
-         <% if @bug.comments.first.user.nil? %>
-           <td> <%= @bug.comments.first.author_name %> </td>
+         <% if @bug.author.nil? %>
+           <td> <%= @bug.author_name %> </td>
          <% else %>
-           <td><%= link_to h(@bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => @bug.comments.first.user.display_name %></td>                                  
+           <td><%= link_to h(@bug.author_name), :controller => "user", :action => "view", :display_name => @bug.author_name %></td>
          <% end %>
        </tr>
        <tr>
index 5e6c7152b23878d48f3bcd96b2673c07ad29cc02..d837c7829b3426409e700327c35656ebe50bb4a9 100644 (file)
@@ -13,7 +13,7 @@
     <th><%= t'bugs.user.last_changed' %></th>
   </tr>
 <% @bugs.each do |bug| %>
-  <tr<% if bug.comments.first.user != @user2 %> bgcolor="#EEEEEE"<% end %>>
+  <tr<% if bug.author != @user2 %> bgcolor="#EEEEEE"<% end %>>
     <td>
       <% if bug.status == "closed" %>
         <%= image_tag("closed_bug_marker.png", :alt => 'closed') %>
       <% end %>
     </td>
     <td><%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %></td>
-    <% if bug.comments.first.user.nil? %> 
-      <td> <%= bug.comments.first.author_name %> </td> 
+    <% if bug.author.nil? %> 
+      <td> <%= bug.author_name %> </td> 
     <% else %> 
-      <td><%= link_to h(bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => bug.comments.first.user.display_name %></td>
+      <td><%= link_to h(bug.author_name), :controller => "user", :action => "view", :display_name => bug.author_name %></td>
     <% end %>
     <td> <%= htmlize bug.comments.first.body  %> </td> 
     <td><%= l bug.created_at %></td>