From: Tom Hughes Date: Wed, 9 Mar 2022 18:58:54 +0000 (+0000) Subject: Merge pull request #3486 from tomhughes/vips X-Git-Tag: live~2600 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/99f5d5159542171d5b3549a2cf0f0d801ea5d88b?hp=770b367a131f65b81a74574ccb5c1050a35e6307 Merge pull request #3486 from tomhughes/vips Switch to using vips for image processing --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b8e782553..8c1ce723c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -54,15 +54,6 @@ Lint/AssignmentInCondition: - '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: @@ -108,12 +99,10 @@ Metrics/PerceivedComplexity: 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. @@ -123,12 +112,7 @@ Naming/AccessorMethodName: # MethodDefinitionMacros: define_method, define_singleton_method Naming/PredicateName: Exclude: - - 'app/models/changeset.rb' - - 'app/models/old_node.rb' - - 'app/models/old_relation.rb' - - 'app/models/old_way.rb' - 'app/models/user.rb' - - 'lib/classic_pagination/pagination.rb' # Offense count: 5 # Configuration parameters: Database, Include. diff --git a/CONFIGURE.md b/CONFIGURE.md index 9bf5e16bb..c554ff9c2 100644 --- a/CONFIGURE.md +++ b/CONFIGURE.md @@ -54,21 +54,25 @@ $ bundle exec rails console ## OAuth Consumer Keys -Three of the built-in applications communicate via the API, and therefore need OAuth consumer keys configured. These are: +There are two built-in applications which communicate via the API, and therefore need OAuth consumer keys configured. These are: * iD * The website itself (for the Notes functionality) -For example, to use the iD editor you need to register it as an OAuth application. +To use the iD editor you need to register it as an OAuth 1 application. Do the following: * Log into your Rails Port instance - e.g. http://localhost:3000 * Click on your user name to go to your user page * Click on "my settings" on the user page -* Click on "oauth settings" on the My settings page +* Click on "OAuth 1 settings" on the My settings page * Click on 'Register your application'. -* Unless you have set up alternatives, use Name: "Local iD" and URL: "http://localhost:3000" -* Check the 'modify the map' box. +* Unless you have set up alternatives, use Name: "Local iD" and Main Application URL: "http://localhost:3000" +* Check boxes for the following Permissions + * 'read their user preferences' + * 'modify the map' + * 'read their private GPS traces' + * 'modify notes' * Everything else can be left with the default blank values. * Click the "Register" button * On the next page, copy the "consumer key" @@ -81,11 +85,32 @@ An example excerpt from settings.local.yml: ``` # Default editor default_editor: "id" -# OAuth consumer key for iD +# OAuth 1 consumer key for iD id_key: "8lFmZPsagHV4l3rkAHq0hWY5vV3Ctl3oEFY1aXth" ``` -Follow the same process for registering and configuring the website/Notes (`oauth_key`), or to save time, simply reuse the same consumer key for each. +To allow [Notes](https://wiki.openstreetmap.org/wiki/Notes) and changeset discussions to work, follow a similar process, this time registering an OAuth 2 application for the web site: + +* Go to "[OAuth 2 applications](http://localhost:3000/oauth2/applications)" on the My settings page. +* Click on "Register new application". +* Use Name: "OpenStreetMap Web Site" and Redirect URIs: "http://localhost:3000" +* Check boxes for the following Permissions + * 'Modify the map' + * 'Modify notes' +* On the next page, copy the "Client Secret" and "Client ID" +* Edit config/settings.local.yml in your rails tree +* Add the "oauth_application" configuration with the "Client ID" as the value +* Add the "oauth_key" configuration with the "Client Secret" as the value +* Restart your rails server + +An example excerpt from settings.local.yml: + +``` +# OAuth 2 Client ID for the web site +oauth_application: "SGm8QJ6tmoPXEaUPIZzLUmm1iujltYZVWCp9hvGsqXg" +# OAuth 2 Client Secret for the web site +oauth_key: "eRHPm4GtEnw9ovB1Iw7EcCLGtUb66bXbAAspv3aJxlI" +``` ## Troubleshooting diff --git a/Gemfile b/Gemfile index 8782fdfef..02e5e309f 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,7 @@ 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" diff --git a/Gemfile.lock b/Gemfile.lock index 57896dfbc..579654604 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -3,73 +3,73 @@ GEM 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) @@ -86,8 +86,8 @@ GEM 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) @@ -115,7 +115,7 @@ GEM 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) @@ -258,7 +258,7 @@ GEM 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) @@ -378,20 +378,20 @@ GEM 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) @@ -401,12 +401,12 @@ GEM 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) @@ -435,7 +435,7 @@ GEM 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) @@ -474,7 +474,7 @@ GEM 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) @@ -574,7 +574,7 @@ DEPENDENCIES 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) diff --git a/app/controllers/api/changeset_comments_controller.rb b/app/controllers/api/changeset_comments_controller.rb index a3a13b926..4cd33a92b 100644 --- a/app/controllers/api/changeset_comments_controller.rb +++ b/app/controllers/api/changeset_comments_controller.rb @@ -23,7 +23,7 @@ module Api # Find the changeset and check it is valid changeset = Changeset.find(id) - raise OSM::APIChangesetNotYetClosedError, changeset if changeset.is_open? + raise OSM::APIChangesetNotYetClosedError, changeset if changeset.open? # Add a comment to the changeset comment = changeset.comments.create(:changeset => changeset, diff --git a/app/controllers/api/permissions_controller.rb b/app/controllers/api/permissions_controller.rb index 73b84f8ed..07685ed68 100644 --- a/app/controllers/api/permissions_controller.rb +++ b/app/controllers/api/permissions_controller.rb @@ -4,6 +4,7 @@ module Api 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 @@ -21,6 +22,11 @@ module Api else [] end + + respond_to do |format| + format.xml + format.json + end end end end diff --git a/app/controllers/api_controller.rb b/app/controllers/api_controller.rb index a13897640..050c455cd 100644 --- a/app/controllers/api_controller.rb +++ b/app/controllers/api_controller.rb @@ -31,9 +31,8 @@ class ApiController < ApplicationController # 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 @@ -101,7 +100,7 @@ class ApiController < ApplicationController 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) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bb32e7e6e..1d6865405 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -161,7 +161,7 @@ class ApplicationController < ActionController::Base 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) @@ -363,7 +363,7 @@ class ApplicationController < ActionController::Base 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 diff --git a/app/controllers/diary_entries_controller.rb b/app/controllers/diary_entries_controller.rb index 312e1e54c..467c4a38f 100644 --- a/app/controllers/diary_entries_controller.rb +++ b/app/controllers/diary_entries_controller.rb @@ -60,9 +60,8 @@ class DiaryEntriesController < ApplicationController @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 diff --git a/app/controllers/friendships_controller.rb b/app/controllers/friendships_controller.rb index a08ce0b69..5bfce7f0b 100644 --- a/app/controllers/friendships_controller.rb +++ b/app/controllers/friendships_controller.rb @@ -17,7 +17,7 @@ class FriendshipsController < ApplicationController friendship = Friendship.new friendship.befriender = current_user friendship.befriendee = @new_friend - if current_user.is_friends_with?(@new_friend) + if current_user.friends_with?(@new_friend) flash[:warning] = t "friendships.make_friend.already_a_friend", :name => @new_friend.display_name elsif current_user.friendships.where("created_at >= ?", Time.now.utc - 1.hour).count >= current_user.max_friends_per_hour flash.now[:error] = t "friendships.make_friend.limit_exceeded" @@ -42,7 +42,7 @@ class FriendshipsController < ApplicationController if @friend if request.post? - if current_user.is_friends_with?(@friend) + if current_user.friends_with?(@friend) Friendship.where(:befriender => current_user, :befriendee => @friend).delete_all flash[:notice] = t "friendships.remove_friend.success", :name => @friend.display_name else diff --git a/app/controllers/geocoder_controller.rb b/app/controllers/geocoder_controller.rb index 8d651fe0f..7417cab76 100644 --- a/app/controllers/geocoder_controller.rb +++ b/app/controllers/geocoder_controller.rb @@ -18,9 +18,8 @@ class GeocoderController < ApplicationController @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" @@ -291,19 +290,16 @@ class GeocoderController < ApplicationController 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*)?)$/) diff --git a/app/helpers/browse_tags_helper.rb b/app/helpers/browse_tags_helper.rb index d96bbef64..e7562081d 100644 --- a/app/helpers/browse_tags_helper.rb +++ b/app/helpers/browse_tags_helper.rb @@ -47,11 +47,10 @@ module BrowseTagsHelper # 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 diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 2659eaeea..f23a4e356 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -65,7 +65,7 @@ class Changeset < ApplicationRecord # Use a method like this, so that we can easily change how we # determine whether a changeset is open, without breaking code in at # least 6 controllers - def is_open? + def open? # a changeset is open (that is, it will accept further changes) when # it has not yet run out of time and its capacity is small enough. # note that this may not be a hard limit - due to timing changes and @@ -75,7 +75,7 @@ class Changeset < ApplicationRecord end def set_closed_time_now - self.closed_at = Time.now.utc if is_open? + self.closed_at = Time.now.utc if open? end def self.from_xml(xml, create: false) @@ -120,7 +120,7 @@ class Changeset < ApplicationRecord @bbox ||= BoundingBox.new(min_lon, min_lat, max_lon, max_lat) end - def has_valid_bbox? + def bbox_valid? bbox.complete? end @@ -187,7 +187,7 @@ class Changeset < ApplicationRecord # that would make it more than 24h long, in which case clip to # 24h, as this has been decided is a reasonable time limit. def update_closed_at - if is_open? + if open? self.closed_at = if (closed_at - created_at) > (MAX_TIME_OPEN - IDLE_TIMEOUT) created_at + MAX_TIME_OPEN else @@ -205,7 +205,7 @@ class Changeset < ApplicationRecord raise OSM::APIUserChangesetMismatchError unless user.id == user_id # can't change a closed changeset - raise OSM::APIChangesetAlreadyClosedError, self unless is_open? + raise OSM::APIChangesetAlreadyClosedError, self unless open? # copy the other's tags self.tags = other.tags diff --git a/app/models/concerns/consistency_validations.rb b/app/models/concerns/consistency_validations.rb index 8c89f61de..101fd4310 100644 --- a/app/models/concerns/consistency_validations.rb +++ b/app/models/concerns/consistency_validations.rb @@ -16,7 +16,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif new.changeset.user_id != user.id raise OSM::APIUserChangesetMismatchError - elsif !new.changeset.is_open? + elsif !new.changeset.open? raise OSM::APIChangesetAlreadyClosedError, new.changeset end end @@ -27,7 +27,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif new.changeset.user_id != user.id raise OSM::APIUserChangesetMismatchError - elsif !new.changeset.is_open? + elsif !new.changeset.open? raise OSM::APIChangesetAlreadyClosedError, new.changeset end end @@ -42,7 +42,7 @@ module ConsistencyValidations raise OSM::APIChangesetMissingError elsif user.id != changeset.user_id raise OSM::APIUserChangesetMismatchError - elsif !changeset.is_open? + elsif !changeset.open? raise OSM::APIChangesetAlreadyClosedError, changeset end end diff --git a/app/models/concerns/redactable.rb b/app/models/concerns/redactable.rb index ccf04907f..3a1ccf8b7 100644 --- a/app/models/concerns/redactable.rb +++ b/app/models/concerns/redactable.rb @@ -11,7 +11,7 @@ module Redactable def redact!(redaction) # check that this version isn't the current version - raise OSM::APICannotRedactError if is_latest_version? + raise OSM::APICannotRedactError if latest_version? # make the change self.redaction = redaction diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 4f5f074ab..077039ac3 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -103,7 +103,7 @@ class OldNode < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_node.version == version end end diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 7f9a747e6..c36d64572 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -99,7 +99,7 @@ class OldRelation < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_relation.version == version end end diff --git a/app/models/old_way.rb b/app/models/old_way.rb index acf88ddcf..fcff84ede 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -97,7 +97,7 @@ class OldWay < ApplicationRecord # check whether this element is the latest version - that is, # has the same version as its "current" counterpart. - def is_latest_version? + def latest_version? current_way.version == version end end diff --git a/app/models/trace.rb b/app/models/trace.rb index f2d81e31a..957bea8bc 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -49,7 +49,6 @@ class Trace < ApplicationRecord validates :timestamp, :presence => true validates :visibility, :inclusion => %w[private public trackable identifiable] - after_destroy :remove_files after_save :set_filename def tagstring @@ -98,47 +97,15 @@ class Trace < ApplicationRecord end def large_picture - if image.attached? - data = image.blob.download - else - f = File.new(large_picture_name, "rb") - data = f.sysread(File.size(f.path)) - f.close - end - - data + image.blob.download end def icon_picture - if icon.attached? - data = icon.blob.download - else - f = File.new(icon_picture_name, "rb") - data = f.sysread(File.size(f.path)) - f.close - end - - data - end - - def large_picture_name - "#{Settings.gpx_image_dir}/#{id}.gif" - end - - def icon_picture_name - "#{Settings.gpx_image_dir}/#{id}_icon.gif" - end - - def trace_name - "#{Settings.gpx_trace_dir}/#{id}.gpx" + icon.blob.download end def mime_type - if file.attached? - file.content_type - else - content_type(trace_name) - end + file.content_type end def extension_name @@ -198,8 +165,8 @@ class Trace < ApplicationRecord end def xml_file - with_trace_file do |trace_name| - filetype = Open3.capture2("/usr/bin/file", "-Lbz", trace_name).first.chomp + file.open do |tracefile| + filetype = Open3.capture2("/usr/bin/file", "-Lbz", tracefile.path).first.chomp gzipped = filetype.include?("gzip compressed") bzipped = filetype.include?("bzip2 compressed") zipped = filetype.include?("Zip archive") @@ -209,22 +176,22 @@ class Trace < ApplicationRecord file = Tempfile.new("trace.#{id}") if tarred && gzipped - system("tar", "-zxOf", trace_name, :out => file.path) + system("tar", "-zxOf", tracefile.path, :out => file.path) elsif tarred && bzipped - system("tar", "-jxOf", trace_name, :out => file.path) + system("tar", "-jxOf", tracefile.path, :out => file.path) elsif tarred - system("tar", "-xOf", trace_name, :out => file.path) + system("tar", "-xOf", tracefile.path, :out => file.path) elsif gzipped - system("gunzip", "-c", trace_name, :out => file.path) + system("gunzip", "-c", tracefile.path, :out => file.path) elsif bzipped - system("bunzip2", "-c", trace_name, :out => file.path) + system("bunzip2", "-c", tracefile.path, :out => file.path) elsif zipped - system("unzip", "-p", trace_name, "-x", "__MACOSX/*", :out => file.path, :err => "/dev/null") + system("unzip", "-p", tracefile.path, "-x", "__MACOSX/*", :out => file.path, :err => "/dev/null") end file.unlink else - file = File.open(trace_name) + file = File.open(tracefile.path) end file @@ -234,8 +201,8 @@ class Trace < ApplicationRecord def import logger.info("GPX Import importing #{name} (#{id}) from #{user.email}") - with_trace_file do |trace_name| - gpx = GPX::File.new(trace_name) + file.open do |file| + gpx = GPX::File.new(file.path) f_lat = 0 f_lon = 0 @@ -300,26 +267,6 @@ class Trace < ApplicationRecord end end - def migrate_to_storage! - file.attach(:io => File.open(trace_name), - :filename => name, - :content_type => content_type(trace_name), - :identify => false) - - if inserted - image.attach(:io => File.open(large_picture_name), - :filename => "#{id}.gif", - :content_type => "image/gif") - icon.attach(:io => File.open(icon_picture_name), - :filename => "#{id}_icon.gif", - :content_type => "image/gif") - end - - save! - - remove_files - end - private def content_type(file) @@ -334,23 +281,7 @@ class Trace < ApplicationRecord end end - def with_trace_file - if file.attached? - file.open do |file| - yield file.path - end - else - yield trace_name - end - end - def set_filename file.blob.update(:filename => "#{id}#{extension_name}") if file.attached? end - - def remove_files - FileUtils.rm_f(trace_name) - FileUtils.rm_f(icon_picture_name) - FileUtils.rm_f(large_picture_name) - end end diff --git a/app/models/user.rb b/app/models/user.rb index e7e077a9b..d357dc4f5 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -258,7 +258,7 @@ class User < ApplicationRecord OSM::GreatCircle.new(home_lat, home_lon).distance(nearby_user.home_lat, nearby_user.home_lon) end - def is_friends_with?(new_friend) + def friends_with?(new_friend) friendships.exists?(:befriendee => new_friend) end diff --git a/app/views/api/changesets/_changeset.builder b/app/views/api/changesets/_changeset.builder index 292184196..e0188a10e 100644 --- a/app/views/api/changesets/_changeset.builder +++ b/app/views/api/changesets/_changeset.builder @@ -3,11 +3,11 @@ attrs = { "id" => changeset.id, "created_at" => changeset.created_at.xmlschema, - "open" => changeset.is_open?, + "open" => changeset.open?, "comments_count" => changeset.comments.length, "changes_count" => changeset.num_changes } -attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.is_open? +attrs["closed_at"] = changeset.closed_at.xmlschema unless changeset.open? changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete? # user attributes diff --git a/app/views/api/permissions/show.json.jbuilder b/app/views/api/permissions/show.json.jbuilder new file mode 100644 index 000000000..ae048bf22 --- /dev/null +++ b/app/views/api/permissions/show.json.jbuilder @@ -0,0 +1,3 @@ +json.partial! "api/root_attributes" + +json.permissions @permissions diff --git a/app/views/api/permissions/show.builder b/app/views/api/permissions/show.xml.builder similarity index 100% rename from app/views/api/permissions/show.builder rename to app/views/api/permissions/show.xml.builder diff --git a/app/views/browse/changeset.html.erb b/app/views/browse/changeset.html.erb index 6aa0f11fb..ca27862c8 100644 --- a/app/views/browse/changeset.html.erb +++ b/app/views/browse/changeset.html.erb @@ -73,7 +73,7 @@ <% end %> <% if current_user %> - <% unless @changeset.is_open? %> + <% unless @changeset.open? %>
diff --git a/app/views/changesets/_changeset.html.erb b/app/views/changesets/_changeset.html.erb index 714cd14b5..a47a99d33 100644 --- a/app/views/changesets/_changeset.html.erb +++ b/app/views/changesets/_changeset.html.erb @@ -1,6 +1,6 @@ <% changeset_data = { :id => changeset.id } - if changeset.has_valid_bbox? + if changeset.bbox_valid? bbox = changeset.bbox.to_unscaled changeset_data[:bbox] = { :minlon => bbox.min_lon, diff --git a/app/views/changesets/index.atom.builder b/app/views/changesets/index.atom.builder index 7fd9b5dd2..3ab438b59 100644 --- a/app/views/changesets/index.atom.builder +++ b/app/views/changesets/index.atom.builder @@ -72,7 +72,7 @@ atom_feed(:language => I18n.locale, :schema_date => 2009, end end - if changeset.has_valid_bbox? + if changeset.bbox_valid? bbox = changeset.bbox.to_unscaled # See http://georss.org/Encodings#Geometry diff --git a/app/views/dashboards/_contact.html.erb b/app/views/dashboards/_contact.html.erb index 77363dbdb..7785c0552 100644 --- a/app/views/dashboards/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -37,7 +37,7 @@
  • <%= link_to t("users.show.send message"), new_message_path(contact) %>
  • - <% if current_user.is_friends_with?(contact) %> + <% if current_user.friends_with?(contact) %> <%= link_to t("users.show.remove as friend"), remove_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> <% else %> <%= link_to t("users.show.add as friend"), make_friend_path(:display_name => contact.display_name, :referer => request.fullpath), :method => :post %> diff --git a/app/views/oauth2_applications/index.html.erb b/app/views/oauth2_applications/index.html.erb index 119bf5878..4ed849f98 100644 --- a/app/views/oauth2_applications/index.html.erb +++ b/app/views/oauth2_applications/index.html.erb @@ -7,10 +7,12 @@ <% if @applications.length > 0 %> - - - - + + + + + + <%= render :partial => "application", :collection => @applications %> diff --git a/app/views/oauth2_applications/show.html.erb b/app/views/oauth2_applications/show.html.erb index 296705811..8d9c8516d 100644 --- a/app/views/oauth2_applications/show.html.erb +++ b/app/views/oauth2_applications/show.html.erb @@ -48,4 +48,4 @@
    <%= link_to t(".edit"), edit_oauth_application_path(@application), :class => "btn btn-outline-primary" %> <%= link_to t(".delete"), oauth_application_path(@application), { :method => :delete, :class => "btn btn-outline-danger", :data => { :confirm => t(".confirm_delete") } } %> - +
    diff --git a/app/views/oauth2_authorized_applications/index.html.erb b/app/views/oauth2_authorized_applications/index.html.erb index b9599a919..2d3ad00bd 100644 --- a/app/views/oauth2_authorized_applications/index.html.erb +++ b/app/views/oauth2_authorized_applications/index.html.erb @@ -7,9 +7,11 @@ <% if @applications.length > 0 %>
    <%= t ".name" %><%= t ".permissions" %>
    <%= t ".name" %><%= t ".permissions" %>
    - - - + + + + + <%= render :partial => "application", :collection => @applications %> diff --git a/app/views/oauth_clients/index.html.erb b/app/views/oauth_clients/index.html.erb index 7c956d531..a08b3c0ff 100644 --- a/app/views/oauth_clients/index.html.erb +++ b/app/views/oauth_clients/index.html.erb @@ -34,10 +34,12 @@

    <%= t(".no_apps_html", :oauth => link_to(t(".oauth"), "https://oauth.net")) %>

    <% else %>

    <%= t ".registered_apps" %>

    -<% @client_applications.each do |client| %> -
    - <%= link_to client.name, :action => :show, :id => client.id %> -
    -<% end %> +
      + <% @client_applications.each do |client| %> +
    • + <%= link_to client.name, :action => :show, :id => client.id %> +
    • + <% end %> +
    <% end %> -

    <%= link_to t(".register_new"), :action => :new %>

    +<%= link_to t(".register_new"), { :action => :new }, :class => "btn btn-outline-primary" %> diff --git a/app/views/site/_id.html.erb b/app/views/site/_id.html.erb index f1f48c1e1..1a3807e4a 100644 --- a/app/views/site/_id.html.erb +++ b/app/views/site/_id.html.erb @@ -1,10 +1,10 @@ <%= javascript_include_tag "edit/id" %>
    - <% data = { :key => Settings.id_key } -%> - <% data[:lat] = @lat if @lat -%> - <% data[:lon] = @lon if @lon -%> - <% data[:gpx] = trace_data_url(params[:gpx], :format => :xml) if params[:gpx] -%> - <% data[:url] = id_url(:locale => params[:locale]) -%> + <% data = { :key => Settings.id_key } + data[:lat] = @lat if @lat + data[:lon] = @lon if @lon + data[:gpx] = trace_data_url(params[:gpx], :format => :xml) if params[:gpx] + data[:url] = id_url(:locale => params[:locale]) %> <%= tag.iframe "", :frameBorder => 0, :id => "id-embed", :class => "id-embed", :allowfullscreen => "", :data => data %>
    diff --git a/app/views/site/help.html.erb b/app/views/site/help.html.erb index e6c65a992..c82893e9d 100644 --- a/app/views/site/help.html.erb +++ b/app/views/site/help.html.erb @@ -16,7 +16,7 @@ <%= t ".#{site}.title" %> - +

    <%= t ".#{site}.description" %>

    <%= t ".application" %><%= t ".permissions" %>
    <%= t ".application" %><%= t ".permissions" %>