]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/amf_controller.rb
Merge remote-tracking branch 'upstream/pull/1580'
[rails.git] / app / controllers / amf_controller.rb
index ac6da0566aab5e88fdcee41f1c58b68370ee7027..679e137d9ad776f0297f1919acea6f1994ccafb6 100644 (file)
@@ -46,7 +46,7 @@ class AmfController < ApplicationController
 
   def amf_read
     self.status = :ok
-    self.content_type = Mime::AMF
+    self.content_type = Mime[:amf]
     self.response_body = Dispatcher.new(request.raw_post) do |message, *args|
       logger.info("Executing AMF #{message}(#{args.join(',')})")
 
@@ -74,7 +74,7 @@ class AmfController < ApplicationController
     err = false                       # Abort batch on error
 
     self.status = :ok
-    self.content_type = Mime::AMF
+    self.content_type = Mime[:amf]
     self.response_body = Dispatcher.new(request.raw_post) do |message, *args|
       logger.info("Executing AMF #{message}")
 
@@ -151,7 +151,7 @@ class AmfController < ApplicationController
         cs = Changeset.find(closeid.to_i)
         cs.set_closed_time_now
         if cs.user_id != user.id
-          raise OSM::APIUserChangesetMismatchError.new
+          raise OSM::APIUserChangesetMismatchError
         elsif closecomment.empty?
           cs.save!
         else
@@ -220,16 +220,16 @@ class AmfController < ApplicationController
     loaded_lang = "en"
 
     # Load English defaults
-    en = YAML.load(File.open("#{Rails.root}/config/potlatch/locales/en.yml"))["en"]
+    en = YAML.safe_load(File.open(Rails.root.join("config", "potlatch", "locales", "en.yml")))["en"]
 
     if lang == "en"
       return [loaded_lang, en]
     else
       # Use English as a fallback
       begin
-        other = YAML.load(File.open("#{Rails.root}/config/potlatch/locales/#{lang}.yml"))[lang]
+        other = YAML.safe_load(File.open(Rails.root.join("config", "potlatch", "locales", "#{lang}.yml")))[lang]
         loaded_lang = lang
-      rescue
+      rescue StandardError
         other = en
       end
 
@@ -868,14 +868,14 @@ class AmfController < ApplicationController
 
   def getuser(token) #:doc:
     if token =~ /^(.+)\:(.+)$/
-      User.authenticate(:username => $1, :password => $2)
+      User.authenticate(:username => Regexp.last_match(1), :password => Regexp.last_match(2))
     else
       User.authenticate(:token => token)
     end
   end
 
   def getlocales
-    @locales ||= Locale.list(Dir.glob("#{Rails.root}/config/potlatch/locales/*").collect { |f| File.basename(f, ".yml") })
+    @locales ||= Locale.list(Dir.glob(Rails.root.join("config", "potlatch", "locales", "*")).collect { |f| File.basename(f, ".yml") })
   end
 
   ##
@@ -907,28 +907,28 @@ class AmfController < ApplicationController
   # Alternative SQL queries for getway/whichways
 
   def sql_find_ways_in_area(bbox)
-    sql = <<-EOF
+    sql = <<-SQL
     SELECT DISTINCT current_ways.id AS wayid,current_ways.version AS version
       FROM current_way_nodes
     INNER JOIN current_nodes ON current_nodes.id=current_way_nodes.node_id
     INNER JOIN current_ways  ON current_ways.id =current_way_nodes.id
        WHERE current_nodes.visible=TRUE
        AND current_ways.visible=TRUE
-       AND #{OSM.sql_for_area(bbox, "current_nodes.")}
-    EOF
+       AND #{OSM.sql_for_area(bbox, 'current_nodes.')}
+    SQL
     ActiveRecord::Base.connection.select_all(sql).collect { |a| [a["wayid"].to_i, a["version"].to_i] }
   end
 
   def sql_find_pois_in_area(bbox)
     pois = []
-    sql = <<-EOF
+    sql = <<-SQL
       SELECT current_nodes.id,current_nodes.latitude*0.0000001 AS lat,current_nodes.longitude*0.0000001 AS lon,current_nodes.version
       FROM current_nodes
        LEFT OUTER JOIN current_way_nodes cwn ON cwn.node_id=current_nodes.id
        WHERE current_nodes.visible=TRUE
        AND cwn.id IS NULL
-       AND #{OSM.sql_for_area(bbox, "current_nodes.")}
-    EOF
+       AND #{OSM.sql_for_area(bbox, 'current_nodes.')}
+    SQL
     ActiveRecord::Base.connection.select_all(sql).each do |row|
       poitags = {}
       ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|
@@ -942,36 +942,36 @@ class AmfController < ApplicationController
   def sql_find_relations_in_area_and_ways(bbox, way_ids)
     # ** It would be more Potlatchy to get relations for nodes within ways
     #    during 'getway', not here
-    sql = <<-EOF
+    sql = <<-SQL
       SELECT DISTINCT cr.id AS relid,cr.version AS version
       FROM current_relations cr
       INNER JOIN current_relation_members crm ON crm.id=cr.id
       INNER JOIN current_nodes cn ON crm.member_id=cn.id AND crm.member_type='Node'
-       WHERE #{OSM.sql_for_area(bbox, "cn.")}
-      EOF
+       WHERE #{OSM.sql_for_area(bbox, 'cn.')}
+      SQL
     unless way_ids.empty?
-      sql += <<-EOF
+      sql += <<-SQL
        UNION
         SELECT DISTINCT cr.id AS relid,cr.version AS version
         FROM current_relations cr
         INNER JOIN current_relation_members crm ON crm.id=cr.id
          WHERE crm.member_type='Way'
          AND crm.member_id IN (#{way_ids.join(',')})
-        EOF
+        SQL
     end
     ActiveRecord::Base.connection.select_all(sql).collect { |a| [a["relid"].to_i, a["version"].to_i] }
   end
 
   def sql_get_nodes_in_way(wayid)
     points = []
-    sql = <<-EOF
+    sql = <<-SQL
       SELECT latitude*0.0000001 AS lat,longitude*0.0000001 AS lon,current_nodes.id,current_nodes.version
       FROM current_way_nodes,current_nodes
        WHERE current_way_nodes.id=#{wayid.to_i}
        AND current_way_nodes.node_id=current_nodes.id
        AND current_nodes.visible=TRUE
       ORDER BY sequence_id
-    EOF
+    SQL
     ActiveRecord::Base.connection.select_all(sql).each do |row|
       nodetags = {}
       ActiveRecord::Base.connection.select_all("SELECT k,v FROM current_node_tags WHERE id=#{row['id']}").each do |n|