From: Tom Hughes Date: Sun, 8 May 2011 16:59:41 +0000 (+0100) Subject: Add methods to get a bug's author details from the first comment X-Git-Tag: live~5068^2~162 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/f77a3c75bee528caaa6fc8e237ee6eaef704efe0 Add methods to get a bug's author details from the first comment --- diff --git a/app/controllers/map_bugs_controller.rb b/app/controllers/map_bugs_controller.rb index 8bd45bbcd..a3984347b 100644 --- a/app/controllers/map_bugs_controller.rb +++ b/app/controllers/map_bugs_controller.rb @@ -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 diff --git a/app/models/map_bug.rb b/app/models/map_bug.rb index 2ae110bf2..7094bfe5e 100644 --- a/app/models/map_bug.rb +++ b/app/models/map_bug.rb @@ -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 diff --git a/app/models/map_bug_comment.rb b/app/models/map_bug_comment.rb index 28f16a9a9..9a130dd34 100644 --- a/app/models/map_bug_comment.rb +++ b/app/models/map_bug_comment.rb @@ -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 diff --git a/app/models/notifier.rb b/app/models/notifier.rb index b7cb3454d..e8c9259cb 100644 --- a/app/models/notifier.rb +++ b/app/models/notifier.rb @@ -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 diff --git a/app/views/browse/bug.html.erb b/app/views/browse/bug.html.erb index 4364d1088..698532290 100644 --- a/app/views/browse/bug.html.erb +++ b/app/views/browse/bug.html.erb @@ -34,10 +34,10 @@ <% end %> <%= t 'browse.bug.opened_by' %> - <% if @bug.comments.first.user.nil? %> - <%= @bug.comments.first.author_name %> + <% if @bug.author.nil? %> + <%= @bug.author_name %> <% else %> - <%= link_to h(@bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => @bug.comments.first.user.display_name %> + <%= link_to h(@bug.author_name), :controller => "user", :action => "view", :display_name => @bug.author_name %> <% end %> diff --git a/app/views/map_bugs/my_bugs.html.erb b/app/views/map_bugs/my_bugs.html.erb index 5e6c7152b..d837c7829 100644 --- a/app/views/map_bugs/my_bugs.html.erb +++ b/app/views/map_bugs/my_bugs.html.erb @@ -13,7 +13,7 @@ <%= t'bugs.user.last_changed' %> <% @bugs.each do |bug| %> - bgcolor="#EEEEEE"<% end %>> + bgcolor="#EEEEEE"<% end %>> <% if bug.status == "closed" %> <%= image_tag("closed_bug_marker.png", :alt => 'closed') %> @@ -22,10 +22,10 @@ <% end %> <%= link_to bug.id.to_s, :controller => "browse", :action => "bug", :id => bug.id %> - <% if bug.comments.first.user.nil? %> - <%= bug.comments.first.author_name %> + <% if bug.author.nil? %> + <%= bug.author_name %> <% else %> - <%= link_to h(bug.comments.first.user.display_name), :controller => "user", :action => "view", :display_name => bug.comments.first.user.display_name %> + <%= link_to h(bug.author_name), :controller => "user", :action => "view", :display_name => bug.author_name %> <% end %> <%= htmlize bug.comments.first.body %> <%= l bug.created_at %>