From: Kai Krueger Date: Wed, 17 Mar 2010 23:39:59 +0000 (+0000) Subject: Fixup some error handling in map bugs X-Git-Tag: live~5064^2~224 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/35bbf82c200eb39eab5e5555e2a440903250769a Fixup some error handling in map bugs --- diff --git a/app/controllers/map_bugs_controller.rb b/app/controllers/map_bugs_controller.rb index 596ec4d5c..16d127641 100644 --- a/app/controllers/map_bugs_controller.rb +++ b/app/controllers/map_bugs_controller.rb @@ -100,6 +100,8 @@ class MapBugsController < ApplicationController id = params['id'].to_i bug = MapBug.find_by_id(id); + raise OSM::APINotFoundError unless bug + raise OSM::APIAlreadyDeletedError unless bug.visible bug_comment = add_comment(bug, params['text'], name); @@ -112,6 +114,9 @@ class MapBugsController < ApplicationController id = params['id'].to_i bug = MapBug.find_by_id(id); + raise OSM::APINotFoundError unless bug + raise OSM::APIAlreadyDeletedError unless bug.visible + bug.close_bug; render_ok @@ -130,9 +135,11 @@ class MapBugsController < ApplicationController def read @bug = MapBug.find(params['id']) - render :text => "", :status => :gone unless @bug.visible + raise OSM::APINotFoundError unless @bug + raise OSM::APIAlreadyDeletedError unless @bug.visible + respond_to do |format| - format.rss + format.rss format.xml format.json { render :json => @bug.to_json(:methods => [:lat, :lon], :only => [:id, :status, :date_created], :include => { :map_bug_comment => { :only => [:commenter_name, :date_created, :comment]}}) } end @@ -140,6 +147,8 @@ class MapBugsController < ApplicationController def delete bug = MapBug.find(params['id']) + raise OSM::APINotFoundError unless @bug + raise OSM::APIAlreadyDeletedError unless @bug.visible bug.status = "hidden" bug.save render :text => "ok\n", :content_type => "text/html" diff --git a/app/views/map_bugs/read.rss.builder b/app/views/map_bugs/read.rss.builder new file mode 100644 index 000000000..f8503b1b0 --- /dev/null +++ b/app/views/map_bugs/read.rss.builder @@ -0,0 +1,32 @@ +xml.instruct! + +xml.rss("version" => "2.0", + "xmlns:geo" => "http://www.w3.org/2003/01/geo/wgs84_pos#", + "xmlns:georss" => "http://www.georss.org/georss") do + xml.channel do + xml.title "OpenStreetBugs" + xml.description t('bugs.rss.description') + xml.link url_for(:controller => "site", :action => "index", :only_path => false) + + xml.item do + if @bug.status == "closed" + xml.title t('bugs.rss.closed', :place => @bug.nearby_place) + else if @bug.map_bug_comment.length > 1 + xml.title t('bugs.rss.comment', :place => @bug.nearby_place) + else + xml.title t('bugs.rss.new', :place => @bug.nearby_place) + end end + + xml.link url_for(:controller => "browse", :action => "bug", :id => @bug.id, :only_path => false) + xml.guid url_for(:controller => "map_bugs", :action => "read", :id => @bug.id, :only_path => false) + xml.description htmlize(@bug.flatten_comment("

")) + if (!@bug.map_bug_comment.empty?) + xml.author @bug.map_bug_comment[-1].commenter_name + end + xml.pubDate @bug.last_changed.to_s(:rfc822) + xml.geo :lat, @bug.lat + xml.geo :long, @bug.lon + xml.georss :point, "#{@bug.lat} #{@bug.lon}" + end + end +end