X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/e756dbae7f3715561de5688e6503b60fdfe0327d..6de8c2e6b30485683a9d3aa3e21c4b256fe399bd:/app/controllers/note_controller.rb diff --git a/app/controllers/note_controller.rb b/app/controllers/note_controller.rb index 4c0c98b63..1eb0350fd 100644 --- a/app/controllers/note_controller.rb +++ b/app/controllers/note_controller.rb @@ -81,7 +81,7 @@ class NoteController < ApplicationController end # Save the note - @note.save + @note.save! # Add a comment to the note add_comment(@note, comment, name, "opened") @@ -160,7 +160,7 @@ class NoteController < ApplicationController end # Find the comments we want to return - @comments = NoteComment.where(:note => notes).order("created_at DESC").limit(result_limit).include(:note) + @comments = NoteComment.where(:note_id => notes).order("created_at DESC").limit(result_limit).preload(:note) # Render the result respond_to do |format| @@ -222,64 +222,39 @@ class NoteController < ApplicationController raise OSM::APIBadUserInput.new("No query string was given") unless params[:q] # Get any conditions that need to be applied - conditions = closed_condition - conditions = cond_merge conditions, ['note_comments.body ~ ?', params[:q]] - + @notes = closed_condition(Note.scoped) + @notes = @notes.joins(:comments).where("note_comments.body ~ ?", params[:q]) + # Find the notes we want to return - @notes = Note.find(:all, - :conditions => conditions, - :order => "updated_at DESC", - :limit => result_limit, - :joins => :comments, - :include => :comments) + @notes = @notes.order("updated_at DESC").limit(result_limit).preload(:comments) # Render the result respond_to do |format| - format.html { render :action => :list, :format => :rjs, :content_type => "text/javascript"} format.rss { render :action => :list } - format.js format.xml { render :action => :list } format.json { render :action => :list } format.gpx { render :action => :list } end end + ## + # Display a list of notes by a specified user def mine if params[:display_name] - @user2 = User.find_by_display_name(params[:display_name], :conditions => { :status => ["active", "confirmed"] }) - - if @user2 - if @user2.data_public? or @user2 == @user - conditions = ['note_comments.author_id = ?', @user2.id] - else - conditions = ['false'] - end - else #if request.format == :html + if @this_user = User.active.find_by_display_name(params[:display_name]) + @title = t 'note.mine.title', :user => @this_user.display_name + @heading = t 'note.mine.heading', :user => @this_user.display_name + @description = t 'note.mine.description', :user => render_to_string(:partial => "user", :object => @this_user) + @page = (params[:page] || 1).to_i + @page_size = 10 + @notes = @this_user.notes.order("updated_at DESC").offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author) + else @title = t 'user.no_such_user.title' @not_found_user = params[:display_name] + render :template => 'user/no_such_user', :status => :not_found - return end end - - if @user2 - user_link = render_to_string :partial => "user", :object => @user2 - end - - @title = t 'note.mine.title', :user => @user2.display_name - @heading = t 'note.mine.heading', :user => @user2.display_name - @description = t 'note.mine.description', :user => user_link - - @page = (params[:page] || 1).to_i - @page_size = 10 - - @notes = Note.find(:all, - :include => [:comments, {:comments => :author}], - :joins => :comments, - :order => "updated_at DESC", - :conditions => conditions, - :offset => (@page - 1) * @page_size, - :limit => @page_size).uniq end private @@ -344,7 +319,7 @@ private attributes[:author_name] = name + " (a)" end - note.comments.create(attributes) + note.comments.create(attributes, :without_protection => true) note.comments.map { |c| c.author }.uniq.each do |user| if user and user != @user