- name: Run javascript tests
run: bundle exec teaspoon
- name: Report completion to Coveralls
- uses: coverallsapp/github-action@v2.3.4
+ uses: coverallsapp/github-action@v2.3.5
with:
github-token: ${{ secrets.github_token }}
flag-name: ubuntu-${{ matrix.ubuntu }}-ruby-${{ matrix.ruby }}
runs-on: ubuntu-latest
steps:
- name: Report completion to Coveralls
- uses: coverallsapp/github-action@v2.3.4
+ uses: coverallsapp/github-action@v2.3.5
with:
github-token: ${{ secrets.github_token }}
parallel-finished: true
var params = {};
if (mapParams.object) {
- params.id = mapParams.object.type + '/' + mapParams.object.id;
+ params.id = mapParams.object.type + "/" + mapParams.object.id;
mapParams = OSM.parseHash(location.hash);
if (mapParams.center) {
- params.map = mapParams.zoom + '/' + mapParams.center.lat + '/' + mapParams.center.lng;
+ params.map = mapParams.zoom + "/" + mapParams.center.lat + "/" + mapParams.center.lng;
}
} else if (id.data("lat") && id.data("lon")) {
params.map = "16/" + id.data("lat") + "/" + id.data("lon");
} else {
- params.map = (mapParams.zoom || 17) + '/' + mapParams.lat + '/' + mapParams.lon;
+ params.map = (mapParams.zoom || 17) + "/" + mapParams.lat + "/" + mapParams.lon;
}
if (hashParams.background) params.background = hashParams.background;
I18n.fallbacks = true;
window.onload = function () {
- var query = (window.location.search || '?').slice(1),
- args = {};
+ var query = (window.location.search || "?").slice(1),
+ args = {};
- var pairs = query.split('&');
+ var pairs = query.split("&");
for (var i = 0; i < pairs.length; i++) {
- var parts = pairs[i].split('=');
- args[parts[0]] = decodeURIComponent(parts[1] || '');
+ var parts = pairs[i].split("=");
+ args[parts[0]] = decodeURIComponent(parts[1] || "");
}
var mapnikOptions = {
};
var map = L.map("map");
- map.attributionControl.setPrefix('');
+ map.attributionControl.setPrefix("");
map.removeControl(map.attributionControl);
if (args.layer === "cyclosm") {
}
if (args.marker) {
- L.marker(args.marker.split(','), {icon: L.icon({
+ L.marker(args.marker.split(","), { icon: L.icon({
iconUrl: <%= asset_path('leaflet/dist/images/marker-icon.png').to_json %>,
iconSize: new L.Point(25, 41),
iconAnchor: new L.Point(12, 41),
shadowUrl: <%= asset_path('leaflet/dist/images/marker-shadow.png').to_json %>,
shadowSize: new L.Point(41, 41)
- })}).addTo(map);
+ }) }).addTo(map);
}
if (args.bbox) {
- var bbox = args.bbox.split(',');
- map.fitBounds([L.latLng(bbox[1], bbox[0]),
- L.latLng(bbox[3], bbox[2])]);
+ var bbox = args.bbox.split(",");
+ map.fitBounds([
+ L.latLng(bbox[1], bbox[0]),
+ L.latLng(bbox[3], bbox[2])
+ ]);
} else {
map.fitWorld();
}
L.Control.OSMReportAProblem = L.Control.Attribution.extend({
options: {
- position: 'bottomright',
- prefix: '<a href="https://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}" target="_blank">'+I18n.t('javascripts.embed.report_problem')+'</a>'
+ position: "bottomright",
+ prefix: "<a href=\"https://www.openstreetmap.org/fixthemap?lat={x}&lon={y}&zoom={z}\" target=\"_blank\">" + I18n.t("javascripts.embed.report_problem") + "</a>"
},
onAdd: function (map) {
var container = L.Control.Attribution.prototype.onAdd.call(this, map);
- map.on('moveend', this._update, this);
+ map.on("moveend", this._update, this);
return container;
},
this._container.innerHTML =
this._container.innerHTML
- .replace('{x}', this._map.getCenter().lat)
- .replace('{y}', this._map.getCenter().lng)
- .replace('{z}', this._map.getZoom());
+ .replace("{x}", this._map.getCenter().lat)
+ .replace("{y}", this._map.getCenter().lng)
+ .replace("{z}", this._map.getZoom());
}
});
return url;
},
- params: function(search) {
+ params: function (search) {
var params = {};
- search = (search || window.location.search).replace('?', '').split(/&|;/);
+ search = (search || window.location.search).replace("?", "").split(/&|;/);
for (var i = 0; i < search.length; ++i) {
var pair = search[i],
- j = pair.indexOf('='),
- key = pair.slice(0, j),
- val = pair.slice(++j);
+ j = pair.indexOf("="),
+ key = pair.slice(0, j),
+ val = pair.slice(++j);
try {
params[key] = decodeURIComponent(val);
// Old-style object parameters; still in use for edit links e.g. /edit?way=1234
if (params.node) {
- mapParams.object = {type: 'node', id: parseInt(params.node)};
+ mapParams.object = { type: "node", id: parseInt(params.node, 10) };
} else if (params.way) {
- mapParams.object = {type: 'way', id: parseInt(params.way)};
+ mapParams.object = { type: "way", id: parseInt(params.way, 10) };
} else if (params.relation) {
- mapParams.object = {type: 'relation', id: parseInt(params.relation)};
+ mapParams.object = { type: "relation", id: parseInt(params.relation, 10) };
} else if (params.note) {
- mapParams.object = {type: 'note', id: parseInt(params.note)};
+ mapParams.object = { type: "note", id: parseInt(params.note, 10) };
}
var hash = OSM.parseHash(location.hash);
- const loc = Cookies.get('_osm_location')?.split("|");
+ const loc = Cookies.get("_osm_location")?.split("|");
// Decide on a map starting position. Various ways of doing this.
if (hash.center) {
mapParams.lat = hash.center.lat;
mapParams.zoom = hash.zoom;
} else if (params.bbox) {
- var bbox = params.bbox.split(',');
+ var bbox = params.bbox.split(",");
mapParams.bounds = L.latLngBounds(
[parseFloat(bbox[1]), parseFloat(bbox[0])],
[parseFloat(bbox[3]), parseFloat(bbox[2])]);
} else if (params.mlon && params.mlat) {
mapParams.lon = parseFloat(params.mlon);
mapParams.lat = parseFloat(params.mlat);
- mapParams.zoom = parseInt(params.zoom || 12);
+ mapParams.zoom = parseInt(params.zoom || 12, 10);
} else if (loc) {
mapParams.lon = parseFloat(loc[0]);
mapParams.lat = parseFloat(loc[1]);
- mapParams.zoom = parseInt(loc[2]);
+ mapParams.zoom = parseInt(loc[2], 10);
} else if (OSM.home) {
mapParams.lon = OSM.home.lon;
mapParams.lat = OSM.home.lat;
mapParams.zoom = 10;
} else if (OSM.location) {
mapParams.bounds = L.latLngBounds(
- [OSM.location.minlat,
- OSM.location.minlon],
- [OSM.location.maxlat,
- OSM.location.maxlon]);
+ [OSM.location.minlat, OSM.location.minlon],
+ [OSM.location.maxlat, OSM.location.maxlon]
+ );
} else {
mapParams.lon = -0.1;
mapParams.lat = 51.5;
- mapParams.zoom = parseInt(params.zoom || 5);
+ mapParams.zoom = parseInt(params.zoom || 5, 10);
}
- mapParams.layers = hash.layers || (loc && loc[3]) || '';
+ mapParams.layers = hash.layers || (loc && loc[3]) || "";
var scale = parseFloat(params.scale);
if (scale > 0) {
return mapParams;
},
- parseHash: function(hash) {
+ parseHash: function (hash) {
var args = {};
- var i = hash.indexOf('#');
+ var i = hash.indexOf("#");
if (i < 0) {
return args;
}
hash = Qs.parse(hash.slice(i + 1));
- var map = (hash.map || '').split('/'),
- zoom = parseInt(map[0], 10),
- lat = parseFloat(map[1]),
- lon = parseFloat(map[2]);
+ var map = (hash.map || "").split("/"),
+ zoom = parseInt(map[0], 10),
+ lat = parseFloat(map[1]),
+ lon = parseFloat(map[2]);
if (!isNaN(zoom) && !isNaN(lat) && !isNaN(lon)) {
args.center = new L.LatLng(lat, lon);
return args;
},
- formatHash: function(args) {
+ formatHash: function (args) {
var center, zoom, layers;
if (args instanceof L.Map) {
} else {
center = args.center || L.latLng(args.lat, args.lon);
zoom = args.zoom;
- layers = args.layers || '';
+ layers = args.layers || "";
}
center = center.wrap();
- layers = layers.replace('M', '');
+ layers = layers.replace("M", "");
var precision = OSM.zoomPrecision(zoom),
- hash = '#map=' + zoom +
- '/' + center.lat.toFixed(precision) +
- '/' + center.lng.toFixed(precision);
+ hash = "#map=" + zoom +
+ "/" + center.lat.toFixed(precision) +
+ "/" + center.lng.toFixed(precision);
if (layers) {
- hash += '&layers=' + layers;
+ hash += "&layers=" + layers;
}
return hash;
},
- zoomPrecision: function(zoom) {
+ zoomPrecision: function (zoom) {
var pixels = Math.pow(2, 8 + zoom);
var degrees = 180;
return Math.ceil(Math.log10(pixels / degrees));
},
- locationCookie: function(map) {
+ locationCookie: function (map) {
var center = map.getCenter().wrap(),
- zoom = map.getZoom(),
- precision = OSM.zoomPrecision(zoom);
- return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join('|');
+ zoom = map.getZoom(),
+ precision = OSM.zoomPrecision(zoom);
+ return [center.lng.toFixed(precision), center.lat.toFixed(precision), zoom, map.getLayersCode()].join("|");
},
- distance: function(latlng1, latlng2) {
+ distance: function (latlng1, latlng2) {
var lat1 = latlng1.lat * Math.PI / 180,
- lng1 = latlng1.lng * Math.PI / 180,
- lat2 = latlng2.lat * Math.PI / 180,
- lng2 = latlng2.lng * Math.PI / 180,
- latdiff = lat2 - lat1,
- lngdiff = lng2 - lng1;
+ lng1 = latlng1.lng * Math.PI / 180,
+ lat2 = latlng2.lat * Math.PI / 180,
+ lng2 = latlng2.lng * Math.PI / 180,
+ latdiff = lat2 - lat1,
+ lngdiff = lng2 - lng1;
return 6372795 * 2 * Math.asin(
Math.sqrt(
module Api
- class MapController < ApiController
+ class MapsController < ApiController
authorize_resource :class => false
before_action :set_request_formats
# Then all the relations that reference the already found nodes and ways are
# fetched. All the nodes and ways that are referenced by those ways are then
# fetched. Finally all the xml is returned.
- def index
+ def show
# Figure out the bbox
# check boundary is sane and area within defined
# see /config/application.yml
def add_comment(note, text, event, notify: true)
attributes = { :visible => true, :event => event, :body => text }
- if doorkeeper_token
- author = current_user if scope_enabled?(:write_notes)
- else
- author = current_user
- end
+ author = current_user if scope_enabled?(:write_notes)
if author
attributes[:author_id] = author.id
raise OSM::APIRateLimitExceeded if new_changes > max_changes
end
+
+ def scope_enabled?(scope)
+ doorkeeper_token&.includes_scope?(scope)
+ end
+
+ helper_method :scope_enabled?
end
end
def deny_access(_exception)
- if doorkeeper_token
- set_locale
- report_error t("oauth.permissions.missing"), :forbidden
- elsif current_user
+ if current_user
set_locale
respond_to do |format|
format.html { redirect_to :controller => "/errors", :action => "forbidden" }
referer&.to_s
end
-
- def scope_enabled?(scope)
- doorkeeper_token&.includes_scope?(scope)
- end
-
- helper_method :scope_enabled?
end
case style
when "osm"
# redirect to API map get
- redirect_to :controller => "api/map", :action => "index", :bbox => bbox
+ redirect_to api_map_path(:bbox => bbox)
when "mapnik"
# redirect to a special 'export' cgi script
put "relation/:id" => "relations#update", :id => /\d+/
delete "relation/:id" => "relations#delete", :id => /\d+/
get "relations" => "relations#index"
-
- get "map" => "map#index"
end
namespace :api, :path => "api/0.6" do
+ resource :map, :only => :show
+
resources :tracepoints, :path => "trackpoints", :only => :index
resources :users, :only => :index
require "test_helper"
module Api
- class MapControllerTest < ActionDispatch::IntegrationTest
+ class MapsControllerTest < ActionDispatch::IntegrationTest
def setup
super
@badbigbbox = %w[-0.1,-0.1,1.1,1.1 10,10,11,11]
def test_routes
assert_routing(
{ :path => "/api/0.6/map", :method => :get },
- { :controller => "api/map", :action => "index" }
+ { :controller => "api/maps", :action => "show" }
)
assert_routing(
{ :path => "/api/0.6/map.json", :method => :get },
- { :controller => "api/map", :action => "index", :format => "json" }
+ { :controller => "api/maps", :action => "show", :format => "json" }
)
end
# Accept: XML format -> use XML
accept_header = accept_format_header("text/xml")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: Any format -> use XML
accept_header = accept_format_header("*/*")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: Any format, .json URL suffix -> use json
accept_header = accept_format_header("*/*")
- get map_path(:bbox => bbox, :format => "json"), :headers => accept_header
+ get api_map_path(:bbox => bbox, :format => "json"), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
# Accept: Firefox header -> use XML
accept_header = accept_format_header("text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: JOSM header text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2 -> use XML
# Note: JOSM's header does not comply with RFC 7231, section 5.3.1
accept_header = accept_format_header("text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: text/plain, */* -> use XML
accept_header = accept_format_header("text/plain, */*")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: text/* -> use XML
accept_header = accept_format_header("text/*")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/xml; charset=utf-8", @response.header["Content-Type"]
# Accept: json, */* format -> use json
accept_header = accept_format_header("application/json, */*")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
# Accept: json format -> use json
accept_header = accept_format_header("application/json")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :success, "Expected success with the map call"
assert_equal "application/json; charset=utf-8", @response.header["Content-Type"]
# text/json is in invalid format, return HTTP 406 Not acceptable
accept_header = accept_format_header("text/json")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :not_acceptable, "text/json should fail"
# image/jpeg is a format which we don't support, return HTTP 406 Not acceptable
accept_header = accept_format_header("image/jpeg")
- get map_path(:bbox => bbox), :headers => accept_header
+ get api_map_path(:bbox => bbox), :headers => accept_header
assert_response :not_acceptable, "text/json should fail"
end
maxlon = node.lon + 0.1
maxlat = node.lat + 0.1
bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
if $VERBOSE
print @request.to_yaml
print @response.body
maxlon = node.lon + 0.1
maxlat = node.lat + 0.1
bbox = "#{minlon},#{minlat},#{maxlon},#{maxlat}"
- get map_path(:bbox => bbox, :format => "json")
+ get api_map_path(:bbox => bbox, :format => "json")
if $VERBOSE
print @request.to_yaml
print @response.body
relation = create(:relation_member, :member => node).relation
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}']" \
relation = create(:relation_member, :member => way1).relation
bbox = "#{node.lon},#{node.lat},#{node.lon},#{node.lat}"
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='#{node.lon}'][minlat='#{node.lat}'][maxlon='#{node.lon}'][maxlat='#{node.lat}']", :count => 1
end
def test_map_empty
- get map_path(:bbox => "179.998,89.998,179.999.1,89.999")
+ get api_map_path(:bbox => "179.998,89.998,179.999.1,89.999")
assert_response :success, "The map call should have succeeded"
assert_select "osm[version='#{Settings.api_version}'][generator='#{Settings.generator}']", :count => 1 do
assert_select "bounds[minlon='179.9980000'][minlat='89.9980000'][maxlon='179.9990000'][maxlat='89.9990000']", :count => 1
end
def test_map_without_bbox
- get map_path
+ get api_map_path
assert_response :bad_request
assert_equal "The parameter bbox is required", @response.body, "A bbox param was expected"
end
def test_bbox_too_big
@badbigbbox.each do |bbox|
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :bad_request, "The bbox:#{bbox} was expected to be too big"
assert_equal "The maximum bbox size is #{Settings.max_request_area}, and your request was too large. Either request a smaller area, or use planet.osm", @response.body, "bbox: #{bbox}"
end
def test_bbox_malformed
@badmalformedbbox.each do |bbox|
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :bad_request, "The bbox:#{bbox} was expected to be malformed"
assert_equal "The parameter bbox must be of the form min_lon,min_lat,max_lon,max_lat", @response.body, "bbox: #{bbox}"
end
def test_bbox_lon_mixedup
@badlonmixedbbox.each do |bbox|
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :bad_request, "The bbox:#{bbox} was expected to have the longitude mixed up"
assert_equal "The minimum longitude must be less than the maximum longitude, but it wasn't", @response.body, "bbox: #{bbox}"
end
def test_bbox_lat_mixedup
@badlatmixedbbox.each do |bbox|
- get map_path(:bbox => bbox)
+ get api_map_path(:bbox => bbox)
assert_response :bad_request, "The bbox:#{bbox} was expected to have the latitude mixed up"
assert_equal "The minimum latitude must be less than the maximum latitude, but it wasn't", @response.body, "bbox: #{bbox}"
end
assert_equal note, subscription.note
end
+ def test_create_no_scope_fail
+ user = create(:user)
+ auth_header = bearer_authorization_header user, :scopes => %w[read_prefs]
+
+ assert_no_difference "Note.count" do
+ post api_notes_path(:lat => -1.0, :lon => -1.0, :text => "This is a description", :format => "json"), :headers => auth_header
+
+ assert_response :forbidden
+ end
+ end
+
def test_comment_success
open_note_with_comment = create(:note_with_comments)
user = create(:user)
# test the finish action for raw OSM data
def test_finish_osm
post export_finish_path(:minlon => 0, :minlat => 50, :maxlon => 1, :maxlat => 51, :format => "osm")
- assert_redirected_to "controller" => "api/map", "action" => "index", "bbox" => "0.0,50.0,1.0,51.0"
+ assert_redirected_to api_map_path(:bbox => "0.0,50.0,1.0,51.0")
end
###
minimatch "^3.1.2"
strip-json-comments "^3.1.1"
-"@eslint/js@9.18.0":
- version "9.18.0"
- resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.18.0.tgz#3356f85d18ed3627ab107790b53caf7e1e3d1e84"
- integrity sha512-fK6L7rxcq6/z+AaQMtiFTkvbHkBLNlwyRxHpKawP0x3u9+NC6MQTnFW+AdpwC6gfHTW0051cokQgtTN2FqlxQA==
+"@eslint/js@9.19.0":
+ version "9.19.0"
+ resolved "https://registry.yarnpkg.com/@eslint/js/-/js-9.19.0.tgz#51dbb140ed6b49d05adc0b171c41e1a8713b7789"
+ integrity sha512-rbq9/g38qjfqFLOVPvwjIvFFdNziEC5S65jmjPw5r6A//QH+W91akh9irMwjDN8zKUTak6W9EsAv4m/7Wnw0UQ==
"@eslint/object-schema@^2.1.4":
version "2.1.4"
integrity sha512-UyLnSehNt62FFhSwjZlHmeokpRK59rcz29j+F1/aDgbkbRTk7wIc9XzdoasMUbRNKDM0qQt/+BJ4BrpFeABemw==
eslint@^9.0.0:
- version "9.18.0"
- resolved "https://registry.yarnpkg.com/eslint/-/eslint-9.18.0.tgz#c95b24de1183e865de19f607fda6518b54827850"
- integrity sha512-+waTfRWQlSbpt3KWE+CjrPPYnbq9kfZIYUqapc0uBXyjTp8aYXZDsUH16m39Ryq3NjAVP4tjuF7KaukeqoCoaA==
+ version "9.19.0"
+ resolved "https://registry.yarnpkg.com/eslint/-/eslint-9.19.0.tgz#ffa1d265fc4205e0f8464330d35f09e1d548b1bf"
+ integrity sha512-ug92j0LepKlbbEv6hD911THhoRHmbdXt2gX+VDABAW/Ir7D3nqKdv5Pf5vtlyY6HQMTEP2skXY43ueqTCWssEA==
dependencies:
"@eslint-community/eslint-utils" "^4.2.0"
"@eslint-community/regexpp" "^4.12.1"
"@eslint/config-array" "^0.19.0"
"@eslint/core" "^0.10.0"
"@eslint/eslintrc" "^3.2.0"
- "@eslint/js" "9.18.0"
+ "@eslint/js" "9.19.0"
"@eslint/plugin-kit" "^0.2.5"
"@humanfs/node" "^0.16.6"
"@humanwhocodes/module-importer" "^1.0.1"