- 'lib/osm.rb'
- 'script/deliver-message'
-# Offense count: 7
-# Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches.
-Lint/DuplicateBranch:
- Exclude:
- - 'app/controllers/api_controller.rb'
- - 'app/controllers/diary_entries_controller.rb'
- - 'app/controllers/geocoder_controller.rb'
- - 'app/helpers/browse_tags_helper.rb'
-
# Offense count: 665
# Configuration parameters: IgnoredMethods, CountRepeatedAttributes.
Metrics/AbcSize:
Minitest/MultipleAssertions:
Max: 52
-# Offense count: 3
+# Offense count: 1
Naming/AccessorMethodName:
Exclude:
- - 'app/controllers/application_controller.rb'
- 'app/helpers/title_helper.rb'
- - 'lib/osm.rb'
# Offense count: 8
# Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros.
source "https://rubygems.org"
# Require rails
-gem "rails", "7.0.2.2"
+gem "rails", "7.0.2.3"
# Require json for multi_json
gem "json"
specs:
aasm (5.2.0)
concurrent-ruby (~> 1.0)
- actioncable (7.0.2.2)
- actionpack (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ actioncable (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
nio4r (~> 2.0)
websocket-driver (>= 0.6.1)
- actionmailbox (7.0.2.2)
- actionpack (= 7.0.2.2)
- activejob (= 7.0.2.2)
- activerecord (= 7.0.2.2)
- activestorage (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ actionmailbox (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ activejob (= 7.0.2.3)
+ activerecord (= 7.0.2.3)
+ activestorage (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
mail (>= 2.7.1)
net-imap
net-pop
net-smtp
- actionmailer (7.0.2.2)
- actionpack (= 7.0.2.2)
- actionview (= 7.0.2.2)
- activejob (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ actionmailer (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ actionview (= 7.0.2.3)
+ activejob (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
mail (~> 2.5, >= 2.5.4)
net-imap
net-pop
net-smtp
rails-dom-testing (~> 2.0)
- actionpack (7.0.2.2)
- actionview (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ actionpack (7.0.2.3)
+ actionview (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
rack (~> 2.0, >= 2.2.0)
rack-test (>= 0.6.3)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.2.0)
actionpack-page_caching (1.2.4)
actionpack (>= 4.0.0)
- actiontext (7.0.2.2)
- actionpack (= 7.0.2.2)
- activerecord (= 7.0.2.2)
- activestorage (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ actiontext (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ activerecord (= 7.0.2.3)
+ activestorage (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
globalid (>= 0.6.0)
nokogiri (>= 1.8.5)
- actionview (7.0.2.2)
- activesupport (= 7.0.2.2)
+ actionview (7.0.2.3)
+ activesupport (= 7.0.2.3)
builder (~> 3.1)
erubi (~> 1.4)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.1, >= 1.2.0)
active_record_union (1.3.0)
activerecord (>= 4.0)
- activejob (7.0.2.2)
- activesupport (= 7.0.2.2)
+ activejob (7.0.2.3)
+ activesupport (= 7.0.2.3)
globalid (>= 0.3.6)
- activemodel (7.0.2.2)
- activesupport (= 7.0.2.2)
- activerecord (7.0.2.2)
- activemodel (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ activemodel (7.0.2.3)
+ activesupport (= 7.0.2.3)
+ activerecord (7.0.2.3)
+ activemodel (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
activerecord-import (1.3.0)
activerecord (>= 4.2)
- activestorage (7.0.2.2)
- actionpack (= 7.0.2.2)
- activejob (= 7.0.2.2)
- activerecord (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ activestorage (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ activejob (= 7.0.2.3)
+ activerecord (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
marcel (~> 1.0)
mini_mime (>= 1.1.0)
- activesupport (7.0.2.2)
+ activesupport (7.0.2.3)
concurrent-ruby (~> 1.0, >= 1.0.2)
i18n (>= 1.6, < 2)
minitest (>= 5.1)
autoprefixer-rails (10.4.2.0)
execjs (~> 2)
aws-eventstream (1.2.0)
- aws-partitions (1.560.0)
- aws-sdk-core (3.127.0)
+ aws-partitions (1.564.0)
+ aws-sdk-core (3.129.0)
aws-eventstream (~> 1, >= 1.0.2)
aws-partitions (~> 1, >= 1.525.0)
aws-sigv4 (~> 1.1)
smart_properties
binding_of_caller (1.0.0)
debug_inspector (>= 0.0.1)
- bootsnap (1.10.3)
+ bootsnap (1.11.1)
msgpack (~> 1.2)
bootstrap (4.5.3)
autoprefixer-rails (>= 9.1.0)
jbuilder (2.11.5)
actionview (>= 5.0.0)
activesupport (>= 5.0.0)
- jmespath (1.6.0)
+ jmespath (1.6.1)
jquery-rails (4.4.0)
rails-dom-testing (>= 1, < 3)
railties (>= 4.2.0)
rack-test (1.1.0)
rack (>= 1.0, < 3)
rack-uri_sanitizer (0.0.2)
- rails (7.0.2.2)
- actioncable (= 7.0.2.2)
- actionmailbox (= 7.0.2.2)
- actionmailer (= 7.0.2.2)
- actionpack (= 7.0.2.2)
- actiontext (= 7.0.2.2)
- actionview (= 7.0.2.2)
- activejob (= 7.0.2.2)
- activemodel (= 7.0.2.2)
- activerecord (= 7.0.2.2)
- activestorage (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ rails (7.0.2.3)
+ actioncable (= 7.0.2.3)
+ actionmailbox (= 7.0.2.3)
+ actionmailer (= 7.0.2.3)
+ actionpack (= 7.0.2.3)
+ actiontext (= 7.0.2.3)
+ actionview (= 7.0.2.3)
+ activejob (= 7.0.2.3)
+ activemodel (= 7.0.2.3)
+ activerecord (= 7.0.2.3)
+ activestorage (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
bundler (>= 1.15.0)
- railties (= 7.0.2.2)
+ railties (= 7.0.2.3)
rails-controller-testing (1.0.5)
actionpack (>= 5.0.1.rc1)
actionview (>= 5.0.1.rc1)
nokogiri (>= 1.6)
rails-html-sanitizer (1.4.2)
loofah (~> 2.3)
- rails-i18n (7.0.2)
+ rails-i18n (7.0.3)
i18n (>= 0.7, < 2)
railties (>= 6.0.0, < 8)
- railties (7.0.2.2)
- actionpack (= 7.0.2.2)
- activesupport (= 7.0.2.2)
+ railties (7.0.2.3)
+ actionpack (= 7.0.2.3)
+ activesupport (= 7.0.2.3)
method_source
rake (>= 12.2)
thor (~> 1.0)
parser (>= 3.1.1.0)
rubocop-minitest (0.17.2)
rubocop (>= 0.90, < 2.0)
- rubocop-performance (1.13.2)
+ rubocop-performance (1.13.3)
rubocop (>= 1.7.0, < 2.0)
rubocop-ast (>= 0.4.0)
rubocop-rails (2.13.2)
simplecov-lcov (0.8.0)
simplecov_json_formatter (0.1.4)
smart_properties (1.17.0)
- sprockets (4.0.2)
+ sprockets (4.0.3)
concurrent-ruby (~> 1.0)
rack (> 1, < 3)
sprockets-rails (3.4.2)
r2 (~> 0.2.7)
rack-cors
rack-uri_sanitizer
- rails (= 7.0.2.2)
+ rails (= 7.0.2.3)
rails-controller-testing
rails-i18n (~> 7.0.0)
rinku (>= 2.0.6)
before_action :check_api_readable
before_action :setup_user_auth
+ before_action :set_request_formats
around_action :api_call_handle_error, :api_call_timeout
# External apps that use the api are able to query which permissions
else
[]
end
+
+ respond_to do |format|
+ format.xml
+ format.json
+ end
end
end
end
# as XML for backwards compatibility - all other formats are discarded
# which will result in a 406 Not Acceptable response being sent
formats = mimetypes.map do |mime|
- if mime.symbol == :xml then :xml
+ if mime.symbol == :xml || mime == "*/*" then :xml
elsif mime.symbol == :json then :json
- elsif mime == "*/*" then :xml
end
end
else
elsif Authenticator.new(self, [:token]).allow?
# self.current_user setup by OAuth
else
- username, passwd = get_auth_data # parse from headers
+ username, passwd = auth_data # parse from headers
# authenticate per-scheme
self.current_user = if username.nil?
nil # no authentication provided - perhaps first connect (client should retry after 401)
response.headers["Error"] = message
if request.headers["X-Error-Format"]&.casecmp("xml")&.zero?
- result = OSM::API.new.get_xml_doc
+ result = OSM::API.new.xml_doc
result.root.name = "osmError"
result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}")
result.root << (XML::Node.new("message") << message)
end
# extract authorisation credentials from headers, returns user = nil if none
- def get_auth_data
+ def auth_data
if request.env.key? "X-HTTP_AUTHORIZATION" # where mod_rewrite might have put it
authdata = request.env["X-HTTP_AUTHORIZATION"].to_s.split
elsif request.env.key? "REDIRECT_X_HTTP_AUTHORIZATION" # mod_fcgi
@title = t "diary_entries.edit.title"
@diary_entry = DiaryEntry.find(params[:id])
- if current_user != @diary_entry.user
- redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
- elsif params[:diary_entry] && @diary_entry.update(entry_params)
+ if current_user != @diary_entry.user ||
+ (params[:diary_entry] && @diary_entry.update(entry_params))
redirect_to diary_entry_path(@diary_entry.user, @diary_entry)
else
set_map_location
@sources.push "geonames_reverse" if Settings.key?(:geonames_username)
elsif @params[:query]
case @params[:query]
- when /^\d{5}(-\d{4})?$/
- @sources.push "osm_nominatim"
- when /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
+ when /^\d{5}(-\d{4})?$/,
+ /^(GIR 0AA|[A-PR-UWYZ]([0-9]{1,2}|([A-HK-Y][0-9]|[A-HK-Y][0-9]([0-9]|[ABEHMNPRV-Y]))|[0-9][A-HJKS-UW])\s*[0-9][ABD-HJLNP-UW-Z]{2})$/i
@sources.push "osm_nominatim"
when /^[A-Z]\d[A-Z]\s*\d[A-Z]\d$/i
@sources.push "ca_postcode"
if query = params[:query]
query.strip!
- if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) # [NSEW] decimal degrees
- params.merge!(nsew_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
+ if latlon = query.match(/^([NS])\s*(\d{1,3}(\.\d*)?)\W*([EW])\s*(\d{1,3}(\.\d*)?)$/).try(:captures) || # [NSEW] decimal degrees
+ query.match(/^(\d{1,3}(\.\d*)?)\s*([NS])\W*(\d{1,3}(\.\d*)?)\s*([EW])$/).try(:captures) # decimal degrees [NSEW]
params.merge!(nsew_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) # [NSEW] degrees, decimal minutes
- params.merge!(ddm_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
+ elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\W*([EW])\s*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?$/).try(:captures) || # [NSEW] degrees, decimal minutes
+ query.match(/^(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([NS])\W*(\d{1,3})°?(?:\s*(\d{1,3}(\.\d*)?)?['′]?)?\s*([EW])$/).try(:captures) # degrees, decimal minutes [NSEW]
params.merge!(ddm_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) # [NSEW] degrees, minutes, decimal seconds
- params.merge!(dms_to_decdeg(latlon)).delete(:query)
- elsif latlon = query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
+ elsif latlon = query.match(/^([NS])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\W*([EW])\s*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?$/).try(:captures) || # [NSEW] degrees, minutes, decimal seconds
+ query.match(/^(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([NS])\W*(\d{1,3})°?\s*(\d{1,2})['′]?(?:\s*(\d{1,3}(\.\d*)?)?["″]?)?\s*([EW])$/).try(:captures) # degrees, minutes, decimal seconds [NSEW]
params.merge!(dms_to_decdeg(latlon)).delete(:query)
elsif latlon = query.match(/^([+-]?\d+(\.\d*)?)(?:\s+|\s*,\s*)([+-]?\d+(\.\d*)?)$/)
# the correct page.
lookup_us = lookup.tr(" ", "_")
- if page = WIKI_PAGES.dig(locale, type, lookup_us)
- url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
- elsif page = WIKI_PAGES.dig("en", type, lookup_us)
- url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}"
- end
+ page = WIKI_PAGES.dig(locale, type, lookup_us) ||
+ WIKI_PAGES.dig("en", type, lookup_us)
+
+ url = "https://wiki.openstreetmap.org/wiki/#{page}?uselang=#{locale}" if page
url
end
--- /dev/null
+json.partial! "api/root_attributes"
+
+json.permissions @permissions
@reader.read
raise OSM::APIBadUserInput, "Document element should be 'osmChange'." if @reader.name != "osmChange"
- result = OSM::API.new.get_xml_doc
+ result = OSM::API.new.xml_doc
result.root.name = "diffResult"
# loop at the top level, within the <osmChange> element
end
class API
- def get_xml_doc
+ def xml_doc
doc = XML::Document.new
doc.encoding = XML::Encoding::UTF_8
root = XML::Node.new "osm"
{ :path => "/api/0.6/permissions", :method => :get },
{ :controller => "api/permissions", :action => "show" }
)
+ assert_routing(
+ { :path => "/api/0.6/permissions.json", :method => :get },
+ { :controller => "api/permissions", :action => "show", :format => "json" }
+ )
end
def test_permissions_anonymous
assert_select "osm > permissions", :count => 1 do
assert_select "permission", :count => 0
end
+
+ # Test json
+ get permissions_path(:format => "json")
+ assert_response :success
+ assert_equal "application/json", @response.media_type
+
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal 0, js["permissions"].count
end
def test_permissions_basic_auth
assert_select "permission[name='#{p}']", :count => 1
end
end
+
+ # Test json
+ get permissions_path(:format => "json"), :headers => auth_header
+ assert_response :success
+ assert_equal "application/json", @response.media_type
+
+ js = ActiveSupport::JSON.decode(@response.body)
+ assert_not_nil js
+ assert_equal ClientApplication.all_permissions.size, js["permissions"].count
+ ClientApplication.all_permissions.each do |p|
+ assert_includes js["permissions"], p.to_s
+ end
end
def test_permissions_oauth1
version = nil
with_controller(Api::ChangesetsController.new) do
- doc = OSM::API.new.get_xml_doc
+ doc = OSM::API.new.xml_doc
change = XML::Node.new "osmChange"
doc.root = change
modify = XML::Node.new "modify"
end
def xml_for_node(node)
- doc = OSM::API.new.get_xml_doc
+ doc = OSM::API.new.xml_doc
doc.root << xml_node_for_node(node)
doc
end
end
def xml_for_way(way)
- doc = OSM::API.new.get_xml_doc
+ doc = OSM::API.new.xml_doc
doc.root << xml_node_for_way(way)
doc
end
end
def xml_for_relation(relation)
- doc = OSM::API.new.get_xml_doc
+ doc = OSM::API.new.xml_doc
doc.root << xml_node_for_relation(relation)
doc
end