From: Tom Hughes Date: Thu, 7 Oct 2021 16:45:07 +0000 (+0100) Subject: Merge remote-tracking branch 'upstream/pull/3300' X-Git-Tag: live~2137 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/5966acc207874f3196a43700cb9306411c77fe47?hp=350ac303f167002a4edc0853259e8793e879c91d Merge remote-tracking branch 'upstream/pull/3300' --- diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 000000000..44b38323d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,14 @@ +# EditorConfig is awesome: http://EditorConfig.org + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file + +[*] +indent_style = space +indent_size = 2 +end_of_line = lf +charset = utf-8 +trim_trailing_whitespace = true +insert_final_newline = true diff --git a/.gitattributes b/.gitattributes new file mode 100644 index 000000000..6313b56c5 --- /dev/null +++ b/.gitattributes @@ -0,0 +1 @@ +* text=auto eol=lf diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 32514771c..90bfaa8f9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2021-06-29 17:25:37 UTC using RuboCop version 1.18.0. +# on 2021-09-14 19:29:59 UTC using RuboCop version 1.21.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -14,13 +14,26 @@ require: - rubocop-rails - rubocop-rake -# Offense count: 510 +# Offense count: 524 # Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Layout/LineLength: Max: 270 +# Offense count: 62 +# Cop supports --auto-correct. +Lint/AmbiguousOperatorPrecedence: + Exclude: + - 'app/controllers/geocoder_controller.rb' + - 'app/models/user.rb' + - 'lib/bounding_box.rb' + - 'lib/osm.rb' + - 'lib/rich_text.rb' + - 'lib/short_link.rb' + - 'test/controllers/api/old_nodes_controller_test.rb' + - 'test/lib/short_link_test.rb' + # Offense count: 34 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: @@ -50,12 +63,12 @@ Lint/DuplicateBranch: - 'app/helpers/browse_tags_helper.rb' - 'lib/password_hash.rb' -# Offense count: 631 +# Offense count: 643 # Configuration parameters: IgnoredMethods, CountRepeatedAttributes. Metrics/AbcSize: - Max: 235 + Max: 189 -# Offense count: 68 +# Offense count: 69 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. # IgnoredMethods: refine Metrics/BlockLength: @@ -69,14 +82,14 @@ Metrics/BlockNesting: # Offense count: 25 # Configuration parameters: CountComments, CountAsOne. Metrics/ClassLength: - Max: 361 + Max: 337 -# Offense count: 56 +# Offense count: 58 # Configuration parameters: IgnoredMethods. Metrics/CyclomaticComplexity: Max: 25 -# Offense count: 703 +# Offense count: 716 # Configuration parameters: CountComments, CountAsOne, ExcludedMethods, IgnoredMethods. Metrics/MethodLength: Max: 179 @@ -86,37 +99,22 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -# Offense count: 60 +# Offense count: 62 # Configuration parameters: IgnoredMethods. Metrics/PerceivedComplexity: Max: 26 -# Offense count: 519 +# Offense count: 528 Minitest/MultipleAssertions: - Max: 88 + Max: 54 -# Offense count: 4 +# Offense count: 3 Naming/AccessorMethodName: Exclude: - 'app/controllers/application_controller.rb' - 'app/helpers/title_helper.rb' - 'lib/osm.rb' -# Offense count: 21 -# Configuration parameters: CheckIdentifiers, CheckConstants, CheckVariables, CheckStrings, CheckSymbols, CheckComments, CheckFilepaths, FlaggedTerms. -Naming/InclusiveLanguage: - Exclude: - - 'app/controllers/sessions_controller.rb' - - 'app/controllers/users_controller.rb' - - 'app/helpers/browse_tags_helper.rb' - - 'app/views/api/capabilities/show.builder' - - 'app/views/confirmations/_resend_success_flash.html.erb' - - 'app/views/users/suspended.html.erb' - - 'config/environments/production.rb' - - 'config/initializers/canonical_rails.rb' - - 'config/initializers/config.rb' - - 'config/initializers/doorkeeper.rb' - # Offense count: 8 # Configuration parameters: NamePrefix, ForbiddenPrefixes, AllowedMethods, MethodDefinitionMacros. # NamePrefix: is_, has_, have_ @@ -200,7 +198,7 @@ Rake/Desc: - 'lib/tasks/subscribe_diary_authors.rake' - 'lib/tasks/subscribe_old_changesets.rake' -# Offense count: 597 +# Offense count: 602 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle. # SupportedStyles: always, always_true, never diff --git a/Gemfile b/Gemfile index 6b1049ec7..75cb1054b 100644 --- a/Gemfile +++ b/Gemfile @@ -145,7 +145,7 @@ group :test do gem "rubocop" gem "rubocop-minitest" gem "rubocop-performance" - gem "rubocop-rails" + gem "rubocop-rails", "~> 2.11.3" # Bug in 2.12.0, fixed in master after 2.12.2 gem "rubocop-rake" gem "selenium-webdriver" gem "simplecov", :require => false diff --git a/Gemfile.lock b/Gemfile.lock index 624d03d0b..2d679a751 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -74,23 +74,23 @@ GEM activerecord (>= 3.2, < 7.0) rake (>= 10.4, < 14.0) ast (2.4.2) - autoprefixer-rails (10.3.1.0) + autoprefixer-rails (10.3.3.0) execjs (~> 2) - aws-eventstream (1.1.1) - aws-partitions (1.490.0) - aws-sdk-core (3.119.1) + aws-eventstream (1.2.0) + aws-partitions (1.510.0) + aws-sdk-core (3.121.1) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.239.0) aws-sigv4 (~> 1.1) jmespath (~> 1.0) - aws-sdk-kms (1.46.0) - aws-sdk-core (~> 3, >= 3.119.0) + aws-sdk-kms (1.49.0) + aws-sdk-core (~> 3, >= 3.120.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.99.0) - aws-sdk-core (~> 3, >= 3.119.0) + aws-sdk-s3 (1.103.0) + aws-sdk-core (~> 3, >= 3.120.0) aws-sdk-kms (~> 1) - aws-sigv4 (~> 1.1) - aws-sigv4 (1.2.4) + aws-sigv4 (~> 1.4) + aws-sigv4 (1.4.0) aws-eventstream (~> 1, >= 1.0.2) better_errors (2.9.1) coderay (>= 1.0.0) @@ -106,7 +106,7 @@ GEM smart_properties binding_of_caller (1.0.0) debug_inspector (>= 0.0.1) - bootsnap (1.7.7) + bootsnap (1.9.1) msgpack (~> 1.0) bootstrap (4.5.3) autoprefixer-rails (>= 9.1.0) @@ -121,7 +121,7 @@ GEM bzip2-ffi (1.1.0) ffi (~> 1.0) cancancan (3.3.0) - canonical-rails (0.2.11) + canonical-rails (0.2.12) rails (>= 4.1, < 6.2) capybara (3.35.3) addressable @@ -151,27 +151,26 @@ GEM activerecord (>= 3.0, < 6.2) delayed_job (>= 3.0, < 5) docile (1.4.0) - doorkeeper (5.5.2) + doorkeeper (5.5.4) railties (>= 5) - doorkeeper-i18n (5.2.2) + doorkeeper-i18n (5.2.3) doorkeeper (>= 5.2) - dry-configurable (0.12.1) + dry-configurable (0.13.0) concurrent-ruby (~> 1.0) - dry-core (~> 0.5, >= 0.5.0) - dry-container (0.8.0) + dry-core (~> 0.6) + dry-container (0.9.0) concurrent-ruby (~> 1.0) - dry-configurable (~> 0.1, >= 0.1.3) + dry-configurable (~> 0.13, >= 0.13.0) dry-core (0.7.1) concurrent-ruby (~> 1.0) - dry-equalizer (0.3.0) dry-inflector (0.2.1) dry-initializer (3.0.4) dry-logic (1.2.0) concurrent-ruby (~> 1.0) dry-core (~> 0.5, >= 0.5) - dry-schema (1.7.0) + dry-schema (1.8.0) concurrent-ruby (~> 1.0) - dry-configurable (~> 0.8, >= 0.8.3) + dry-configurable (~> 0.13, >= 0.13.0) dry-core (~> 0.5, >= 0.5) dry-initializer (~> 3.0) dry-logic (~> 1.0) @@ -182,13 +181,12 @@ GEM dry-core (~> 0.5, >= 0.5) dry-inflector (~> 0.1, >= 0.1.2) dry-logic (~> 1.0, >= 1.0.2) - dry-validation (1.6.0) + dry-validation (1.7.0) concurrent-ruby (~> 1.0) dry-container (~> 0.7, >= 0.7.1) - dry-core (~> 0.4) - dry-equalizer (~> 0.2) + dry-core (~> 0.5, >= 0.5) dry-initializer (~> 3.0) - dry-schema (~> 1.5, >= 1.5.2) + dry-schema (~> 1.8, >= 1.8.0) erb_lint (0.1.1) activesupport better_html (~> 1.0.7) @@ -205,7 +203,7 @@ GEM factory_bot_rails (6.2.0) factory_bot (~> 6.2.0) railties (>= 5.0.0) - faraday (1.7.0) + faraday (1.8.0) faraday-em_http (~> 1.0) faraday-em_synchrony (~> 1.0) faraday-excon (~> 1.1) @@ -224,8 +222,8 @@ GEM faraday-net_http_persistent (1.2.0) faraday-patron (1.0.0) faraday-rack (1.0.0) - ffi (1.15.3) - ffi-libarchive (1.0.17) + ffi (1.15.4) + ffi-libarchive (1.1.3) ffi (~> 1.0) fspath (3.1.2) gd2-ffij (0.4.0) @@ -241,7 +239,7 @@ GEM concurrent-ruby (~> 1.0) i18n-js (3.9.0) i18n (>= 0.6.6) - image_optim (0.30.0) + image_optim (0.31.0) exifr (~> 1.2, >= 1.2.2) fspath (~> 3.0) image_size (>= 1.5, < 3) @@ -264,7 +262,7 @@ GEM railties (>= 4.2.0) thor (>= 0.14, < 2.0) json (2.5.1) - jwt (2.2.3) + jwt (2.3.0) kgio (2.11.4) kramdown (2.3.1) rexml @@ -280,7 +278,7 @@ GEM nokogiri (>= 1.5.9) mail (2.7.1) mini_mime (>= 0.1.1) - marcel (1.0.1) + marcel (1.0.2) maxminddb (0.1.22) method_source (1.0.0) mini_magick (4.11.0) @@ -292,7 +290,7 @@ GEM multi_xml (0.6.0) multipart-post (2.1.1) nio4r (2.5.8) - nokogiri (1.12.3) + nokogiri (1.12.5) mini_portile2 (~> 2.6.1) racc (~> 1.4) oauth (0.4.7) @@ -340,14 +338,14 @@ GEM multi_json (~> 1.12) omniauth-oauth2 (~> 1.4) openstreetmap-deadlock_retry (1.3.1) - parallel (1.20.1) + parallel (1.21.0) parser (3.0.2.0) ast (~> 2.4.1) pg (1.2.3) popper_js (1.16.0) progress (3.6.0) public_suffix (4.0.6) - puma (5.4.0) + puma (5.5.0) nio4r (~> 2.0) quad_tile (1.0.1) r2 (0.2.7) @@ -407,18 +405,18 @@ GEM rexml (3.2.5) rinku (2.0.6) rotp (6.2.0) - rubocop (1.19.1) + rubocop (1.22.1) parallel (~> 1.10) parser (>= 3.0.0.0) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 1.8, < 3.0) rexml - rubocop-ast (>= 1.9.1, < 2.0) + rubocop-ast (>= 1.12.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 1.4.0, < 3.0) - rubocop-ast (1.11.0) + rubocop-ast (1.12.0) parser (>= 3.0.1.1) - rubocop-minitest (0.15.0) + rubocop-minitest (0.15.1) rubocop (>= 0.90, < 2.0) rubocop-performance (1.11.5) rubocop (>= 1.7.0, < 2.0) @@ -446,7 +444,7 @@ GEM sprockets (> 3.0) sprockets-rails tilt - secure_headers (6.3.2) + secure_headers (6.3.3) selenium-webdriver (3.142.7) childprocess (>= 0.5, < 4.0) rubyzip (>= 1.2.2) @@ -457,7 +455,7 @@ GEM simplecov-html (0.12.3) simplecov-lcov (0.8.0) simplecov_json_formatter (0.1.3) - smart_properties (1.16.0) + smart_properties (1.16.3) sprockets (4.0.2) concurrent-ruby (~> 1.0) rack (> 1, < 3) @@ -467,13 +465,13 @@ GEM sprockets (>= 3.0.0) strong_migrations (0.7.8) activerecord (>= 5) - terser (1.1.5) + terser (1.1.7) execjs (>= 0.3.0, < 3) thor (1.1.0) tilt (2.0.10) tzinfo (2.0.4) concurrent-ruby (~> 1.0) - unicode-display_width (2.0.0) + unicode-display_width (2.1.0) validates_email_format_of (1.6.3) i18n vendorer (0.2.0) @@ -562,7 +560,7 @@ DEPENDENCIES rubocop rubocop-minitest rubocop-performance - rubocop-rails + rubocop-rails (~> 2.11.3) rubocop-rake sanitize sassc-rails diff --git a/README.md b/README.md index b96a77671..8eb26bf27 100644 --- a/README.md +++ b/README.md @@ -35,7 +35,6 @@ number of dependencies for installation. For full details please see [INSTALL.md We're always keen to have more developers! Pull requests are very welcome. * Bugs are recorded in the [issue tracker](https://github.com/openstreetmap/openstreetmap-website/issues). -* Some bug reports are also found on the [OpenStreetMap trac](https://trac.openstreetmap.org/) system, in the "[website](https://trac.openstreetmap.org/query?status=new&status=assigned&status=reopened&component=website&order=priority)" and "[api](https://trac.openstreetmap.org/query?status=new&status=assigned&status=reopened&component=api&order=priority)" components. * Translation is managed by [Translatewiki](https://translatewiki.net/wiki/Translating:OpenStreetMap). * There is a [rails-dev@openstreetmap.org](https://lists.openstreetmap.org/listinfo/rails-dev) mailing list for development discussion. * IRC - there is the #osm-dev channel on irc.oftc.net. diff --git a/app/abilities/ability.rb b/app/abilities/ability.rb index 018ce0096..769fbca47 100644 --- a/app/abilities/ability.rb +++ b/app/abilities/ability.rb @@ -42,6 +42,7 @@ class Ability can [:index, :new, :create, :show, :edit, :update, :destroy], :oauth2_application can [:index, :destroy], :oauth2_authorized_application can [:new, :show, :create, :destroy], :oauth2_authorization + can [:show], :dashboard can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry can [:make_friend, :remove_friend], Friendship can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message diff --git a/app/assets/stylesheets/common.scss b/app/assets/stylesheets/common.scss index 0023286bf..e0eec7bda 100644 --- a/app/assets/stylesheets/common.scss +++ b/app/assets/stylesheets/common.scss @@ -1096,47 +1096,11 @@ tr.turn:hover { /* Rules for the user profile page */ -#userinformation { - min-height: 100px; - .userinformation-inner { - float: left; - } - .user-description { - width: 100%; - clear: both; - } -} - -.admin-user-info small { - margin-bottom: $lineheight/2; - display: inline; - margin-right: $lineheight; -} - .contact-activity { margin-top: $lineheight; width: 100%; } -.activity-details p { - margin-left: 70px; - margin-bottom: 0; -} - -.users-show { - // Silly exception; remove when user page is redesigned. - .content-inner { - max-width: none; - } - p#no_home_location { - margin: $lineheight; - } - .user_thumbnail { - margin-top: $lineheight/4; - float: left; - } -} - /* Rules for the user map */ .content_map .leaflet-popup-content { @@ -1466,6 +1430,12 @@ img.user_image { margin-right: $lineheight; } +img.user_image_no_margins { + max-width: 100px; + max-height: 100px; + border: 1px solid $grey; +} + img.user_thumbnail { max-width: 50px; max-height: 50px; @@ -1473,6 +1443,12 @@ img.user_thumbnail { margin-right: $lineheight; } +img.user_thumbnail_no_margins { + max-width: 50px; + max-height: 50px; + border: 1px solid $grey; +} + img.user_thumbnail_tiny { width: auto; height: auto; @@ -1489,28 +1465,28 @@ abbr.geo { /* General styles for action lists / subnavs / pager navs */ -ul.secondary-actions { - font-style: normal; - margin-bottom: 0; - margin-left: 0; - padding: 0; - &.pager { - display: inline-block; - margin-right: 60px; - } - > li { - display: block; - float: left; - list-style: none; - border-left: 1px solid $grey; - padding-left: $lineheight/2; - margin-right: $lineheight/2; - &:first-child { - border-left: 0; - padding-left: 0; + +nav.secondary-actions { + margin-left: -11px; + overflow: hidden; + > ul { + display: flex; + flex-direction: row; + flex-wrap: wrap; + margin-bottom: 0; + margin-left: -1px; + padding: 0; + &.pager { + display: inline-block; + margin-right: 60px; } - &:last-child { - margin-right: 0px; + > li { + flex-basis: auto; + list-style: none; + border-left: 1px solid $grey; + padding-left: $lineheight/2; + margin-right: $lineheight/2; + margin-bottom: $lineheight/8; } } } @@ -1574,6 +1550,17 @@ div.secondary-actions { } } +/* Create a single-line dl */ + +dl.dl-inline { + dt, dd { + display: inline-block; + } + dd { + margin-right: 1em; + } +} + /* Customise the background colour of striped tables */ .table-striped > tbody > tr:nth-child(2n+1) > td, diff --git a/app/controllers/api/changesets_controller.rb b/app/controllers/api/changesets_controller.rb index 34627a118..63fda31bd 100644 --- a/app/controllers/api/changesets_controller.rb +++ b/app/controllers/api/changesets_controller.rb @@ -11,6 +11,8 @@ module Api before_action :require_public_data, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe] before_action :check_api_writable, :only => [:create, :update, :upload, :subscribe, :unsubscribe] before_action :check_api_readable, :except => [:create, :update, :upload, :download, :query, :subscribe, :unsubscribe] + before_action :set_request_formats, :only => [:download] + around_action :api_call_handle_error around_action :api_call_timeout, :except => [:upload] @@ -122,35 +124,29 @@ module Api end end - # create changeset and user caches - changeset_cache = {} - user_display_name_cache = {} - - # create an osmChange document for the output - result = OSM::API.new.get_xml_doc - result.root.name = "osmChange" - # generate an output element for each operation. note: we avoid looking # at the history because it is simpler - but it would be more correct to # check these assertions. + @created = [] + @modified = [] + @deleted = [] + elements.each do |elt| - result.root << - if elt.version == 1 - # first version, so it must be newly-created. - created = XML::Node.new "create" - created << elt.to_xml_node(changeset_cache, user_display_name_cache) - elsif elt.visible - # must be a modify - modified = XML::Node.new "modify" - modified << elt.to_xml_node(changeset_cache, user_display_name_cache) - else - # if the element isn't visible then it must have been deleted - deleted = XML::Node.new "delete" - deleted << elt.to_xml_node(changeset_cache, user_display_name_cache) - end + if elt.version == 1 + # first version, so it must be newly-created. + @created << elt + elsif elt.visible + # must be a modify + @modified << elt + else + # if the element isn't visible then it must have been deleted + @deleted << elt + end end - render :xml => result.to_s + respond_to do |format| + format.xml + end end ## diff --git a/app/controllers/api/tracepoints_controller.rb b/app/controllers/api/tracepoints_controller.rb index b2d755fe6..e758d559f 100644 --- a/app/controllers/api/tracepoints_controller.rb +++ b/app/controllers/api/tracepoints_controller.rb @@ -33,75 +33,11 @@ module Api # get all the points ordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[trackable identifiable] }).order("gpx_id DESC, trackid ASC, timestamp ASC") unordered_points = Tracepoint.bbox(bbox).joins(:trace).where(:gpx_files => { :visibility => %w[public private] }).order("gps_points.latitude", "gps_points.longitude", "gps_points.timestamp") - points = ordered_points.union_all(unordered_points).offset(offset).limit(Settings.tracepoints_per_page).preload(:trace) - - doc = XML::Document.new - doc.encoding = XML::Encoding::UTF_8 - root = XML::Node.new "gpx" - root["version"] = "1.0" - root["creator"] = "OpenStreetMap.org" - root["xmlns"] = "http://www.topografix.com/GPX/1/0" - - doc.root = root - - # initialise these variables outside of the loop so that they - # stay in scope and don't get free'd up by the GC during the - # loop. - gpx_id = -1 - trackid = -1 - track = nil - trkseg = nil - anon_track = nil - anon_trkseg = nil - timestamps = false - - points.each do |point| - if gpx_id != point.gpx_id - gpx_id = point.gpx_id - trackid = -1 - - if point.trace.trackable? - track = XML::Node.new "trk" - doc.root << track - timestamps = true - - if point.trace.identifiable? - track << (XML::Node.new("name") << point.trace.name) - track << (XML::Node.new("desc") << point.trace.description) - track << (XML::Node.new("url") << url_for(:controller => "/traces", :action => "show", :display_name => point.trace.user.display_name, :id => point.trace.id)) - end - else - # use the anonymous track segment if the user hasn't allowed - # their GPX points to be tracked. - timestamps = false - if anon_track.nil? - anon_track = XML::Node.new "trk" - doc.root << anon_track - end - track = anon_track - end - end - - if trackid != point.trackid - if point.trace.trackable? - trkseg = XML::Node.new "trkseg" - track << trkseg - trackid = point.trackid - else - if anon_trkseg.nil? - anon_trkseg = XML::Node.new "trkseg" - anon_track << anon_trkseg - end - trkseg = anon_trkseg - end - end - - trkseg << point.to_xml_node(:print_timestamp => timestamps) - end + @points = ordered_points.union_all(unordered_points).offset(offset).limit(Settings.tracepoints_per_page).preload(:trace) response.headers["Content-Disposition"] = "attachment; filename=\"tracks.gpx\"" - render :xml => doc.to_s + render :formats => [:gpx] end end end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb new file mode 100644 index 000000000..540683d25 --- /dev/null +++ b/app/controllers/dashboards_controller.rb @@ -0,0 +1,14 @@ +class DashboardsController < ApplicationController + layout "site" + + before_action :authorize_web + before_action :set_locale + + authorize_resource :class => false + + before_action :check_database_readable + + def show + @user = current_user + end +end diff --git a/app/helpers/open_graph_helper.rb b/app/helpers/open_graph_helper.rb index 99b8d00a3..a91457645 100644 --- a/app/helpers/open_graph_helper.rb +++ b/app/helpers/open_graph_helper.rb @@ -11,7 +11,7 @@ module OpenGraphHelper } safe_join(tags.map do |property, content| - tag(:meta, :property => property, :content => content) + tag.meta(:property => property, :content => content) end, "\n") end end diff --git a/app/helpers/user_roles_helper.rb b/app/helpers/user_roles_helper.rb index 15231f4d0..c7516a51c 100644 --- a/app/helpers/user_roles_helper.rb +++ b/app/helpers/user_roles_helper.rb @@ -25,7 +25,7 @@ module UserRolesHelper end if image - svg_icon = tag("source", :srcset => image_path("#{image}.svg"), :type => "image/svg+xml") + svg_icon = tag.source(:srcset => image_path("#{image}.svg"), :type => "image/svg+xml") png_icon = image_tag("#{image}.png", :srcset => image_path("#{image}.svg"), :size => "20x20", :border => 0, :alt => alt, :title => title) icon = tag.picture(svg_icon + png_icon) icon = link_to(icon, url, :method => :post, :confirm => confirm) if url diff --git a/app/models/concerns/object_metadata.rb b/app/models/concerns/object_metadata.rb deleted file mode 100644 index dcfde889c..000000000 --- a/app/models/concerns/object_metadata.rb +++ /dev/null @@ -1,43 +0,0 @@ -module ObjectMetadata - extend ActiveSupport::Concern - - def add_metadata_to_xml_node(el, osm, changeset_cache, user_display_name_cache) - el["changeset"] = osm.changeset_id.to_s - el["redacted"] = osm.redaction.id.to_s if osm.redacted? - el["timestamp"] = osm.timestamp.xmlschema - el["version"] = osm.version.to_s - el["visible"] = osm.visible.to_s - - if changeset_cache.key?(osm.changeset_id) - # use the cache if available - else - changeset_cache[osm.changeset_id] = osm.changeset.user_id - end - - user_id = changeset_cache[osm.changeset_id] - - if user_display_name_cache.key?(user_id) - # use the cache if available - elsif osm.changeset.user.data_public? - user_display_name_cache[user_id] = osm.changeset.user.display_name - else - user_display_name_cache[user_id] = nil - end - - unless user_display_name_cache[user_id].nil? - el["user"] = user_display_name_cache[user_id] - el["uid"] = user_id.to_s - end - end - - def add_tags_to_xml_node(el, tags) - tags.each do |tag| - tag_el = XML::Node.new("tag") - - tag_el["k"] = tag.k - tag_el["v"] = tag.v - - el << tag_el - end - end -end diff --git a/app/models/node.rb b/app/models/node.rb index 5e799c8d9..8bfac993b 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -27,7 +27,6 @@ class Node < ApplicationRecord include GeoRecord include ConsistencyValidations include NotRedactable - include ObjectMetadata self.table_name = "current_nodes" diff --git a/app/models/old_node.rb b/app/models/old_node.rb index 620cc24d2..81d8e331f 100644 --- a/app/models/old_node.rb +++ b/app/models/old_node.rb @@ -27,7 +27,6 @@ class OldNode < ApplicationRecord include GeoRecord include ConsistencyValidations - include ObjectMetadata self.table_name = "nodes" self.primary_keys = "node_id", "version" @@ -69,28 +68,6 @@ class OldNode < ApplicationRecord old_node end - def to_xml - doc = OSM::API.new.get_xml_doc - doc.root << to_xml_node - doc - end - - def to_xml_node(changeset_cache = {}, user_display_name_cache = {}) - el = XML::Node.new "node" - el["id"] = node_id.to_s - - add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache) - - if visible? - el["lat"] = lat.to_s - el["lon"] = lon.to_s - end - - add_tags_to_xml_node(el, old_tags) - - el - end - def save_with_dependencies! save! diff --git a/app/models/old_relation.rb b/app/models/old_relation.rb index 51aeb9c4c..d0a03ac25 100644 --- a/app/models/old_relation.rb +++ b/app/models/old_relation.rb @@ -22,7 +22,6 @@ class OldRelation < ApplicationRecord include ConsistencyValidations - include ObjectMetadata self.table_name = "relations" self.primary_keys = "relation_id", "version" @@ -88,31 +87,6 @@ class OldRelation < ApplicationRecord attr_writer :members, :tags - def to_xml - doc = OSM::API.new.get_xml_doc - doc.root << to_xml_node - doc - end - - def to_xml_node(changeset_cache = {}, user_display_name_cache = {}) - el = XML::Node.new "relation" - el["id"] = relation_id.to_s - - add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache) - - old_members.each do |member| - member_el = XML::Node.new "member" - member_el["type"] = member.member_type.to_s.downcase - member_el["ref"] = member.member_id.to_s # "id" is considered uncool here as it should be unique in XML - member_el["role"] = member.member_role.to_s - el << member_el - end - - add_tags_to_xml_node(el, old_tags) - - el - end - # Temporary method to match interface to relations def relation_members old_members diff --git a/app/models/old_way.rb b/app/models/old_way.rb index 3260f2a1f..9acf8665d 100644 --- a/app/models/old_way.rb +++ b/app/models/old_way.rb @@ -22,7 +22,6 @@ class OldWay < ApplicationRecord include ConsistencyValidations - include ObjectMetadata self.table_name = "ways" self.primary_keys = "way_id", "version" @@ -86,23 +85,6 @@ class OldWay < ApplicationRecord attr_writer :nds, :tags - def to_xml_node(changeset_cache = {}, user_display_name_cache = {}) - el = XML::Node.new "way" - el["id"] = way_id.to_s - - add_metadata_to_xml_node(el, self, changeset_cache, user_display_name_cache) - - old_nodes.each do |nd| # FIXME: need to make sure they come back in the right order - node_el = XML::Node.new "nd" - node_el["ref"] = nd.node_id.to_s - el << node_el - end - - add_tags_to_xml_node(el, old_tags) - - el - end - # Temporary method to match interface to ways def way_nodes old_nodes diff --git a/app/models/relation.rb b/app/models/relation.rb index 365ea533e..25564940b 100644 --- a/app/models/relation.rb +++ b/app/models/relation.rb @@ -22,7 +22,6 @@ class Relation < ApplicationRecord include ConsistencyValidations include NotRedactable - include ObjectMetadata self.table_name = "current_relations" diff --git a/app/models/trace.rb b/app/models/trace.rb index 0860d2b31..b3d87fc09 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -53,7 +53,7 @@ class Trace < ApplicationRecord def tagstring=(s) self.tags = if s.include? "," - s.split(/\s*,\s*/).reject { |tag| tag =~ /^\s*$/ }.collect do |tag| + s.split(/\s*,\s*/).grep_v(/^\s*$/).collect do |tag| tt = Tracetag.new tt.tag = tag tt diff --git a/app/models/tracepoint.rb b/app/models/tracepoint.rb index 000f257b4..b3c37430d 100644 --- a/app/models/tracepoint.rb +++ b/app/models/tracepoint.rb @@ -31,12 +31,4 @@ class Tracepoint < ApplicationRecord validates :timestamp, :presence => true belongs_to :trace, :foreign_key => "gpx_id" - - def to_xml_node(print_timestamp: false) - el1 = XML::Node.new "trkpt" - el1["lat"] = lat.to_s - el1["lon"] = lon.to_s - el1 << (XML::Node.new("time") << timestamp.xmlschema) if print_timestamp - el1 - end end diff --git a/app/models/way.rb b/app/models/way.rb index 7bb82b281..724965ddf 100644 --- a/app/models/way.rb +++ b/app/models/way.rb @@ -22,7 +22,6 @@ class Way < ApplicationRecord include ConsistencyValidations include NotRedactable - include ObjectMetadata self.table_name = "current_ways" diff --git a/app/views/api/changesets/download.xml.builder b/app/views/api/changesets/download.xml.builder new file mode 100644 index 000000000..1e400cd9f --- /dev/null +++ b/app/views/api/changesets/download.xml.builder @@ -0,0 +1,19 @@ +xml.instruct! :xml, :version => "1.0" + +xml.osmChange(OSM::API.new.xml_root_attributes) do |osm| + @created.each do |elt| + osm.create do |create| + create << render(elt) + end + end + @modified.each do |elt| + osm.modify do |modify| + modify << render(elt) + end + end + @deleted.each do |elt| + osm.delete do |delete| + delete << render(elt) + end + end +end diff --git a/app/views/api/tracepoints/index.gpx.builder b/app/views/api/tracepoints/index.gpx.builder new file mode 100644 index 000000000..291ef0d45 --- /dev/null +++ b/app/views/api/tracepoints/index.gpx.builder @@ -0,0 +1,79 @@ +xml.instruct! + +xml.gpx("version" => "1.0", + "creator" => "OpenStreetMap.org", + "xmlns" => "http://www.topografix.com/GPX/1/0") do + # initialise these variables outside of the loop so that they + # stay in scope and don't get free'd up by the GC during the + # loop. + gpx_id = -1 + trackid = -1 + tracks = [] + track = nil + trkseg = nil + anon_track = nil + anon_trkseg = nil + + @points.each do |point| + if gpx_id != point.gpx_id + gpx_id = point.gpx_id + trackid = -1 + + if point.trace.trackable? + track = {} + track["trksegs"] = [] + tracks << track + + if point.trace.identifiable? + track["name"] = point.trace.name + track["desc"] = point.trace.description + track["url"] = url_for(:controller => "/traces", :action => "show", :display_name => point.trace.user.display_name, :id => point.trace.id) + end + else + # use the anonymous track segment if the user hasn't allowed + # their GPX points to be tracked. + if anon_track.nil? + anon_track = {} + anon_track["trksegs"] = [] + tracks << anon_track + end + track = anon_track + end + end + + if trackid != point.trackid + if point.trace.trackable? + trkseg = [] + track["trksegs"] << trkseg + trackid = point.trackid + else + if anon_trkseg.nil? + anon_trkseg = [] + anon_track["trksegs"] << anon_trkseg + end + trkseg = anon_trkseg + end + end + + trkseg << point + end + + tracks.each do |trk| + xml.trk do + if trk.key?("name") + xml.name trk["name"] + xml.desc trk["desc"] + xml.url trk["url"] + end + trk["trksegs"].each do |trksg| + xml.trkseg do + trksg.each do |tracepoint| + xml.trkpt("lat" => tracepoint.lat.to_s, "lon" => tracepoint.lon.to_s) do + xml.time tracepoint.timestamp.xmlschema if tracepoint.trace.trackable? + end + end + end + end + end + end +end diff --git a/app/views/users/_contact.html.erb b/app/views/dashboards/_contact.html.erb similarity index 54% rename from app/views/users/_contact.html.erb rename to app/views/dashboards/_contact.html.erb index c7e10c060..7614c0c4d 100644 --- a/app/views/users/_contact.html.erb +++ b/app/views/dashboards/_contact.html.erb @@ -4,21 +4,23 @@ :icon => image_path(type == "friend" ? "marker-blue.png" : "marker-green.png"), :description => render(:partial => "popup", :object => contact, :locals => { :type => type }) } %> -<%= tag.div :class => "contact-activity clearfix", :data => { :user => user_data } do %> - <%= user_thumbnail contact %> -
-

+<%= tag.div :class => "contact-activity clearfix row", :data => { :user => user_data } do %> +

+ <%= user_thumbnail contact, :class => "user_thumbnail_no_margins" %> +
+
+

<%= link_to contact.display_name, user_path(contact) %> <% if @user.home_lon and @user.home_lat and contact.home_lon and contact.home_lat %> <% distance = @user.distance(contact) %> <% if distance < 1 %> - (<%= t "users.show.m away", :count => (distance * 1000).round %>) + (<%= t ".m away", :count => (distance * 1000).round %>) <% else %> - (<%= t "users.show.km away", :count => distance.round %>) + (<%= t ".km away", :count => distance.round %>) <% end %> <% end %>

-

+

<% changeset = contact.changesets.first %> <% if changeset %> <%= t("users.show.latest edit", :ago => time_ago_in_words(changeset.created_at, :scope => :"datetime.distance_in_words_ago")) %> @@ -31,15 +33,17 @@ <% end %>

-
    -
  • <%= link_to t("users.show.send message"), new_message_path(contact) %>
  • -
  • - <% if current_user.is_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 %> - <% end %> -
  • -
+
<% end %> diff --git a/app/views/users/_popup.html.erb b/app/views/dashboards/_popup.html.erb similarity index 100% rename from app/views/users/_popup.html.erb rename to app/views/dashboards/_popup.html.erb diff --git a/app/views/dashboards/show.html.erb b/app/views/dashboards/show.html.erb new file mode 100644 index 000000000..9aa4abed4 --- /dev/null +++ b/app/views/dashboards/show.html.erb @@ -0,0 +1,65 @@ +<% content_for :heading do %> +

<%= t ".title" %>

+<% end %> + +
+ <% if current_user and @user.id == current_user.id %> +
+ <% if @user.home_lat.nil? or @user.home_lon.nil? %> +
+

<%= t(".no_home_location_html", :edit_profile_link => link_to(t(".edit_your_profile"), edit_profile_path)) %>

+
+ <% else %> + <% content_for :head do %> + <%= javascript_include_tag "user" %> + <% end %> + <% user_data = { + :lon => current_user.home_lon, + :lat => current_user.home_lat, + :icon => image_path("marker-red.png"), + :description => render(:partial => "popup", :object => current_user, :locals => { :type => "your location" }) + } %> + <%= tag.div "", :id => "map", :class => "content_map", :data => { :user => user_data } %> + <% end %> + + <% friends = @user.friends %> + <% nearby = @user.nearby - friends %> +
+ +
+

<%= t ".my friends" %>

+ + <% if friends.empty? %> + <%= t ".no friends" %> + <% else %> + +
+ <%= render :partial => "contact", :collection => friends, :locals => { :type => "friend" } %> +
+ <% end %> + +
+ +

<%= t ".nearby users" %>

+ + <% if nearby.empty? %> + <%= t ".no nearby users" %> + <% else %> + +
+ <%= render :partial => "contact", :collection => nearby, :locals => { :type => "nearby mapper" } %> +
+ <% end %> +
+ <% end %> +
diff --git a/app/views/diary_entries/_diary_entry.html.erb b/app/views/diary_entries/_diary_entry.html.erb index 946c6ce17..4080b8f95 100644 --- a/app/views/diary_entries/_diary_entry.html.erb +++ b/app/views/diary_entries/_diary_entry.html.erb @@ -23,31 +23,33 @@ <%= render :partial => "location", :object => diary_entry %> <% end %> - +
diff --git a/app/views/diary_entries/index.html.erb b/app/views/diary_entries/index.html.erb index 80561cbbf..6803c761e 100644 --- a/app/views/diary_entries/index.html.erb +++ b/app/views/diary_entries/index.html.erb @@ -6,19 +6,21 @@ <% end %>

<%= @title %>

- + <% end %> diff --git a/app/views/layouts/_header.html.erb b/app/views/layouts/_header.html.erb index a20474b57..192b07614 100644 --- a/app/views/layouts/_header.html.erb +++ b/app/views/layouts/_header.html.erb @@ -90,6 +90,7 @@