]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/notes_controller.rb
Allow moderators to reopen hidden notes
[rails.git] / app / controllers / notes_controller.rb
index 9c6eb94572488e75e5a99e6ddeb3b8a3c2617491..333597a722724835662c9fd4156946291a4791ed 100644 (file)
@@ -30,7 +30,7 @@ class NotesController < ApplicationController
     end
 
     # Get any conditions that need to be applied
     end
 
     # Get any conditions that need to be applied
-    notes = closed_condition(Note.scoped)
+    notes = closed_condition(Note.all)
 
     # Check that the boundaries are valid
     bbox.check_boundaries
 
     # Check that the boundaries are valid
     bbox.check_boundaries
@@ -59,16 +59,8 @@ class NotesController < ApplicationController
     raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
 
     # Extract the arguments
     raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
 
     # Extract the arguments
-    begin
-      lon = Float(params[:lon])
-    rescue
-      raise OSM::APIBadUserInput.new("lon was not a number")
-    end
-    begin
-      lat = Float(params[:lat])
-    rescue
-      raise OSM::APIBadUserInput.new("lat was not a number")
-    end
+    lon = OSM.parse_float(params[:lon], OSM::APIBadUserInput, "lon was not a number")
+    lat = OSM.parse_float(params[:lat], OSM::APIBadUserInput, "lat was not a number")
     comment = params[:text]
 
     # Include in a transaction to ensure that there is always a note_comment for every note
     comment = params[:text]
 
     # Include in a transaction to ensure that there is always a note_comment for every note
@@ -163,8 +155,8 @@ class NotesController < ApplicationController
     # Find the note and check it is valid
     @note = Note.find_by_id(id)
     raise OSM::APINotFoundError unless @note
     # Find the note and check it is valid
     @note = Note.find_by_id(id)
     raise OSM::APINotFoundError unless @note
-    raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible?
-    raise OSM::APINoteAlreadyOpenError.new(@note) unless @note.closed?
+    raise OSM::APIAlreadyDeletedError.new("note", @note.id) unless @note.visible? or @user.moderator?
+    raise OSM::APINoteAlreadyOpenError.new(@note) unless @note.closed? or not @note.visible?
 
     # Reopen the note and add a comment
     Note.transaction do
 
     # Reopen the note and add a comment
     Note.transaction do
@@ -184,7 +176,7 @@ class NotesController < ApplicationController
   # Get a feed of recent notes and comments
   def feed
     # Get any conditions that need to be applied
   # Get a feed of recent notes and comments
   def feed
     # Get any conditions that need to be applied
-    notes = closed_condition(Note.scoped)
+    notes = closed_condition(Note.all)
 
     # Process any bbox
     if params[:bbox]
 
     # Process any bbox
     if params[:bbox]
@@ -262,7 +254,7 @@ class NotesController < ApplicationController
     raise OSM::APIBadUserInput.new("No query string was given") unless params[:q]
 
     # Get any conditions that need to be applied
     raise OSM::APIBadUserInput.new("No query string was given") unless params[:q]
 
     # Get any conditions that need to be applied
-    @notes = closed_condition(Note.scoped)
+    @notes = closed_condition(Note.all)
     @notes = @notes.joins(:comments).where("note_comments.body ~ ?", params[:q])
 
     # Find the notes we want to return
     @notes = @notes.joins(:comments).where("note_comments.body ~ ?", params[:q])
 
     # Find the notes we want to return
@@ -287,7 +279,7 @@ class NotesController < ApplicationController
         @description = t 'note.mine.subheading', :user => render_to_string(:partial => "user", :object => @this_user)
         @page = (params[:page] || 1).to_i 
         @page_size = 10
         @description = t 'note.mine.subheading', :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, id").uniq.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author).all
+        @notes = @this_user.notes.order("updated_at DESC, id").uniq.offset((@page - 1) * @page_size).limit(@page_size).preload(:comments => :author).to_a
       else
         @title = t 'user.no_such_user.title' 
         @not_found_user = params[:display_name] 
       else
         @title = t 'user.no_such_user.title' 
         @not_found_user = params[:display_name] 
@@ -355,7 +347,7 @@ private
       attributes[:author_ip] = request.remote_ip
     end
 
       attributes[:author_ip] = request.remote_ip
     end
 
-    comment = note.comments.create(attributes, :without_protection => true)
+    comment = note.comments.create(attributes)
 
     note.comments.map { |c| c.author }.uniq.each do |user|
       if notify and user and user != @user
 
     note.comments.map { |c| c.author }.uniq.each do |user|
       if notify and user and user != @user