]> git.openstreetmap.org Git - rails.git/commitdiff
Merge remote-tracking branch 'upstream/pull/2177'
authorTom Hughes <tom@compton.nu>
Sat, 16 Mar 2019 15:39:03 +0000 (15:39 +0000)
committerTom Hughes <tom@compton.nu>
Sat, 16 Mar 2019 15:39:03 +0000 (15:39 +0000)
12 files changed:
Gemfile
Gemfile.lock
app/controllers/api/changeset_comments_controller.rb
app/controllers/api/changesets_controller.rb
app/models/changeset.rb
app/views/api/changesets/_changeset.builder [new file with mode: 0644]
app/views/api/changesets/changeset.builder [new file with mode: 0644]
app/views/api/changesets/changesets.builder [new file with mode: 0644]
app/views/site/copyright.html.erb
config/locales/en.yml
config/locales/es.yml
test/controllers/api/changesets_controller_test.rb

diff --git a/Gemfile b/Gemfile
index 96d696561129b4a13ede9d13635791b07dab79b6..372b7d021740b2cecc5949a33d7122b42d0c532f 100644 (file)
--- a/Gemfile
+++ b/Gemfile
@@ -1,7 +1,7 @@
 source "https://rubygems.org"
 
 # Require rails
-gem "rails", "5.2.2"
+gem "rails", "5.2.2.1"
 
 # Require things which have moved to gems in ruby 1.9
 gem "bigdecimal", "~> 1.1.0", :platforms => :ruby_19
index 702ee49a1858afd4b998afbcffc5f94ac48c4d49..2b5cc1dd5a6538be1095af7342c0d86e6436dfdb 100644 (file)
@@ -2,49 +2,49 @@ GEM
   remote: https://rubygems.org/
   specs:
     SystemTimer (1.2.3)
-    aasm (5.0.1)
+    aasm (5.0.2)
       concurrent-ruby (~> 1.0)
-    actioncable (5.2.2)
-      actionpack (= 5.2.2)
+    actioncable (5.2.2.1)
+      actionpack (= 5.2.2.1)
       nio4r (~> 2.0)
       websocket-driver (>= 0.6.1)
-    actionmailer (5.2.2)
-      actionpack (= 5.2.2)
-      actionview (= 5.2.2)
-      activejob (= 5.2.2)
+    actionmailer (5.2.2.1)
+      actionpack (= 5.2.2.1)
+      actionview (= 5.2.2.1)
+      activejob (= 5.2.2.1)
       mail (~> 2.5, >= 2.5.4)
       rails-dom-testing (~> 2.0)
-    actionpack (5.2.2)
-      actionview (= 5.2.2)
-      activesupport (= 5.2.2)
+    actionpack (5.2.2.1)
+      actionview (= 5.2.2.1)
+      activesupport (= 5.2.2.1)
       rack (~> 2.0)
       rack-test (>= 0.6.3)
       rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.0.2)
     actionpack-page_caching (1.1.1)
       actionpack (>= 4.0.0, < 6)
-    actionview (5.2.2)
-      activesupport (= 5.2.2)
+    actionview (5.2.2.1)
+      activesupport (= 5.2.2.1)
       builder (~> 3.1)
       erubi (~> 1.4)
       rails-dom-testing (~> 2.0)
       rails-html-sanitizer (~> 1.0, >= 1.0.3)
     active_record_union (1.3.0)
       activerecord (>= 4.0)
-    activejob (5.2.2)
-      activesupport (= 5.2.2)
+    activejob (5.2.2.1)
+      activesupport (= 5.2.2.1)
       globalid (>= 0.3.6)
-    activemodel (5.2.2)
-      activesupport (= 5.2.2)
-    activerecord (5.2.2)
-      activemodel (= 5.2.2)
-      activesupport (= 5.2.2)
+    activemodel (5.2.2.1)
+      activesupport (= 5.2.2.1)
+    activerecord (5.2.2.1)
+      activemodel (= 5.2.2.1)
+      activesupport (= 5.2.2.1)
       arel (>= 9.0)
-    activestorage (5.2.2)
-      actionpack (= 5.2.2)
-      activerecord (= 5.2.2)
+    activestorage (5.2.2.1)
+      actionpack (= 5.2.2.1)
+      activerecord (= 5.2.2.1)
       marcel (~> 0.3.1)
-    activesupport (5.2.2)
+    activesupport (5.2.2.1)
       concurrent-ruby (~> 1.0, >= 1.0.2)
       i18n (>= 0.7, < 2)
       minitest (~> 5.1)
@@ -65,7 +65,7 @@ GEM
     bigdecimal (1.1.0)
     binding_of_caller (0.8.0)
       debug_inspector (>= 0.0.1)
-    bootsnap (1.4.0)
+    bootsnap (1.4.1)
       msgpack (~> 1.0)
     browser (2.5.3)
     builder (3.2.3)
@@ -91,7 +91,7 @@ GEM
     coffee-script-source (1.12.2)
     composite_primary_keys (11.1.0)
       activerecord (~> 5.2.1)
-    concurrent-ruby (1.1.4)
+    concurrent-ruby (1.1.5)
     config (1.7.1)
       activesupport (>= 3.0)
       deep_merge (~> 1.2.1)
@@ -146,15 +146,15 @@ GEM
     erubi (1.8.0)
     execjs (2.7.0)
     exifr (1.3.6)
-    factory_bot (5.0.0)
+    factory_bot (5.0.2)
       activesupport (>= 4.2.0)
     factory_bot_rails (5.0.1)
       factory_bot (~> 5.0.0)
       railties (>= 4.2.0)
-    fakefs (0.19.1)
+    fakefs (0.20.0)
     faraday (0.15.4)
       multipart-post (>= 1.2, < 3)
-    ffi (1.9.25)
+    ffi (1.10.0)
     fspath (3.1.0)
     gd2-ffij (0.3.0)
       ffi (>= 1.0.0)
@@ -190,7 +190,7 @@ GEM
       execjs (>= 1.4.0)
       multi_json (~> 1.0)
       therubyracer (~> 0.12.1)
-    json (2.1.0)
+    json (2.2.0)
     jsonify (0.3.1)
       multi_json (~> 1.0)
     jsonify-rails (0.3.2)
@@ -225,7 +225,7 @@ GEM
     mini_mime (1.0.1)
     mini_portile2 (2.4.0)
     minitest (5.11.3)
-    msgpack (1.2.6)
+    msgpack (1.2.9)
     multi_json (1.13.1)
     multi_xml (0.6.0)
     multipart-post (2.0.0)
@@ -254,7 +254,7 @@ GEM
     omniauth-github (1.3.0)
       omniauth (~> 1.5)
       omniauth-oauth2 (>= 1.4.0, < 2.0)
-    omniauth-google-oauth2 (0.6.0)
+    omniauth-google-oauth2 (0.6.1)
       jwt (>= 2.0)
       omniauth (>= 1.1.1)
       omniauth-oauth2 (>= 1.5)
@@ -280,7 +280,7 @@ GEM
       mime-types
       mimemagic (~> 0.3.0)
       terrapin (~> 0.6.0)
-    parallel (1.13.0)
+    parallel (1.14.0)
     parser (2.6.0.0)
       ast (~> 2.4.0)
     pg (0.21.0)
@@ -303,18 +303,18 @@ GEM
     rack-test (1.1.0)
       rack (>= 1.0, < 3)
     rack-uri_sanitizer (0.0.2)
-    rails (5.2.2)
-      actioncable (= 5.2.2)
-      actionmailer (= 5.2.2)
-      actionpack (= 5.2.2)
-      actionview (= 5.2.2)
-      activejob (= 5.2.2)
-      activemodel (= 5.2.2)
-      activerecord (= 5.2.2)
-      activestorage (= 5.2.2)
-      activesupport (= 5.2.2)
+    rails (5.2.2.1)
+      actioncable (= 5.2.2.1)
+      actionmailer (= 5.2.2.1)
+      actionpack (= 5.2.2.1)
+      actionview (= 5.2.2.1)
+      activejob (= 5.2.2.1)
+      activemodel (= 5.2.2.1)
+      activerecord (= 5.2.2.1)
+      activestorage (= 5.2.2.1)
+      activesupport (= 5.2.2.1)
       bundler (>= 1.3.0)
-      railties (= 5.2.2)
+      railties (= 5.2.2.1)
       sprockets-rails (>= 2.0.0)
     rails-controller-testing (1.0.4)
       actionpack (>= 5.0.1.x)
@@ -328,9 +328,9 @@ GEM
     rails-i18n (4.0.2)
       i18n (~> 0.6)
       rails (>= 4.0)
-    railties (5.2.2)
-      actionpack (= 5.2.2)
-      activesupport (= 5.2.2)
+    railties (5.2.2.1)
+      actionpack (= 5.2.2.1)
+      activesupport (= 5.2.2.1)
       method_source
       rake (>= 0.8.7)
       thor (>= 0.19.0, < 2.0)
@@ -345,26 +345,27 @@ GEM
     request_store (1.4.1)
       rack (>= 1.4)
     rinku (2.0.4)
-    rotp (4.0.2)
+    rotp (4.1.0)
       addressable (~> 2.5)
-    rubocop (0.64.0)
+    rubocop (0.65.0)
       jaro_winkler (~> 1.5.1)
       parallel (~> 1.10)
       parser (>= 2.5, != 2.5.1.1)
       powerpack (~> 0.1)
+      psych (>= 3.1.0)
       rainbow (>= 2.2.2, < 4.0)
       ruby-progressbar (~> 1.7)
       unicode-display_width (~> 1.4.0)
     ruby-openid (2.7.0)
     ruby-progressbar (1.10.0)
     ruby_dep (1.5.0)
-    safe_yaml (1.0.4)
+    safe_yaml (1.0.5)
     sanitize (5.0.0)
       crass (~> 1.0.2)
       nokogiri (>= 1.8.0)
       nokogumbo (~> 2.0)
-    sassc (2.0.0)
-      ffi (~> 1.9.6)
+    sassc (2.0.1)
+      ffi (~> 1.9)
       rake
     sassc-rails (2.1.0)
       railties (>= 4.0.0)
@@ -372,7 +373,7 @@ GEM
       sprockets (> 3.0)
       sprockets-rails
       tilt
-    secure_headers (6.0.0)
+    secure_headers (6.1.0)
     simplecov (0.16.1)
       docile (~> 1.1)
       json (>= 1.8, < 3)
@@ -476,7 +477,7 @@ DEPENDENCIES
   r2 (~> 0.2.7)
   rack-cors
   rack-uri_sanitizer
-  rails (= 5.2.2)
+  rails (= 5.2.2.1)
   rails-controller-testing
   rails-i18n (~> 4.0.0)
   record_tag_helper
index 6093f529e6039e92b10b3b330e785de4de4baba7..0bebce433666f5d7d0fbbfa4854517c3b281efdf 100644 (file)
@@ -41,7 +41,8 @@ module Api
       changeset.subscribers << current_user unless changeset.subscribers.exists?(current_user.id)
 
       # Return a copy of the updated changeset
-      render :xml => changeset.to_xml.to_s
+      @changeset = changeset
+      render "api/changesets/changeset"
     end
 
     ##
@@ -60,7 +61,8 @@ module Api
       comment.update(:visible => false)
 
       # Return a copy of the updated changeset
-      render :xml => comment.changeset.to_xml.to_s
+      @changeset = comment.changeset
+      render "api/changesets/changeset"
     end
 
     ##
@@ -79,7 +81,8 @@ module Api
       comment.update(:visible => true)
 
       # Return a copy of the updated changeset
-      render :xml => comment.changeset.to_xml.to_s
+      @changeset = comment.changeset
+      render "api/changesets/changeset"
     end
   end
 end
index 853ee389f087a24a2ef8fdde3ddd1c38662344c9..dd43f7ed0943e59829d3902ee2142717eb200bb8 100644 (file)
@@ -41,9 +41,9 @@ module Api
     # Return XML giving the basic info about the changeset. Does not
     # return anything about the nodes, ways and relations in the changeset.
     def show
-      changeset = Changeset.find(params[:id])
-
-      render :xml => changeset.to_xml(params[:include_discussion].presence).to_s
+      @changeset = Changeset.find(params[:id])
+      @include_discussion = params[:include_discussion].presence
+      render "changeset"
     end
 
     ##
@@ -104,7 +104,8 @@ module Api
       # save the larger bounding box and return the changeset, which
       # will include the bigger bounding box.
       cs.save!
-      render :xml => cs.to_xml.to_s
+      @changeset = cs
+      render "changeset"
     end
 
     ##
@@ -219,18 +220,9 @@ module Api
       # sort and limit the changesets
       changesets = changesets.order("created_at DESC").limit(100)
 
-      # preload users, tags and comments
-      changesets = changesets.preload(:user, :changeset_tags, :comments)
-
-      # create the results document
-      results = OSM::API.new.get_xml_doc
-
-      # add all matching changesets to the XML results document
-      changesets.order("created_at DESC").limit(100).each do |cs|
-        results.root << cs.to_xml_node
-      end
-
-      render :xml => results.to_s
+      # preload users, tags and comments, and render result
+      @changesets = changesets.preload(:user, :changeset_tags, :comments)
+      render "changesets"
     end
 
     ##
@@ -245,12 +237,12 @@ module Api
       # request *must* be a PUT.
       assert_method :put
 
-      changeset = Changeset.find(params[:id])
+      @changeset = Changeset.find(params[:id])
       new_changeset = Changeset.from_xml(request.raw_post)
 
-      check_changeset_consistency(changeset, current_user)
-      changeset.update_from(new_changeset, current_user)
-      render :xml => changeset.to_xml.to_s
+      check_changeset_consistency(@changeset, current_user)
+      @changeset.update_from(new_changeset, current_user)
+      render "changeset"
     end
 
     ##
@@ -270,7 +262,8 @@ module Api
       changeset.subscribers << current_user
 
       # Return a copy of the updated changeset
-      render :xml => changeset.to_xml.to_s
+      @changeset = changeset
+      render "changeset"
     end
 
     ##
@@ -290,7 +283,8 @@ module Api
       changeset.subscribers.delete(current_user)
 
       # Return a copy of the updated changeset
-      render :xml => changeset.to_xml.to_s
+      @changeset = changeset
+      render "changeset"
     end
 
     private
index 5cdfeb994544444f08edb72cc4f8ba42fead569d..3ca719f6cc663dff860a2157817d34966edb172c 100644 (file)
@@ -196,67 +196,6 @@ class Changeset < ActiveRecord::Base
     end
   end
 
-  def to_xml(include_discussion = false)
-    doc = OSM::API.new.get_xml_doc
-    doc.root << to_xml_node(nil, include_discussion)
-    doc
-  end
-
-  def to_xml_node(user_display_name_cache = nil, include_discussion = false)
-    el1 = XML::Node.new "changeset"
-    el1["id"] = id.to_s
-
-    user_display_name_cache = {} if user_display_name_cache.nil?
-
-    if user_display_name_cache&.key?(user_id)
-      # use the cache if available
-    elsif user.data_public?
-      user_display_name_cache[user_id] = user.display_name
-    else
-      user_display_name_cache[user_id] = nil
-    end
-
-    el1["user"] = user_display_name_cache[user_id] unless user_display_name_cache[user_id].nil?
-    el1["uid"] = user_id.to_s if user.data_public?
-
-    tags.each do |k, v|
-      el2 = XML::Node.new("tag")
-      el2["k"] = k.to_s
-      el2["v"] = v.to_s
-      el1 << el2
-    end
-
-    el1["created_at"] = created_at.xmlschema
-    el1["closed_at"] = closed_at.xmlschema unless is_open?
-    el1["open"] = is_open?.to_s
-
-    bbox.to_unscaled.add_bounds_to(el1, "_") if bbox.complete?
-
-    el1["comments_count"] = comments.length.to_s
-    el1["changes_count"] = num_changes.to_s
-
-    if include_discussion
-      el2 = XML::Node.new("discussion")
-      comments.includes(:author).each do |comment|
-        el3 = XML::Node.new("comment")
-        el3["date"] = comment.created_at.xmlschema
-        el3["uid"] = comment.author.id.to_s if comment.author.data_public?
-        el3["user"] = comment.author.display_name.to_s if comment.author.data_public?
-        el4 = XML::Node.new("text")
-        el4.content = comment.body.to_s
-        el3 << el4
-        el2 << el3
-      end
-      el1 << el2
-    end
-
-    # NOTE: changesets don't include the XML of the changes within them,
-    # they are just structures for tagging. to get the osmChange of a
-    # changeset, see the download method of the controller.
-
-    el1
-  end
-
   ##
   # update this instance from another instance given and the user who is
   # doing the updating. note that this method is not for updating the
diff --git a/app/views/api/changesets/_changeset.builder b/app/views/api/changesets/_changeset.builder
new file mode 100644 (file)
index 0000000..47c494d
--- /dev/null
@@ -0,0 +1,43 @@
+# basic attributes
+
+attrs = {
+  "id" => changeset.id,
+  "created_at" => changeset.created_at.xmlschema,
+  "open" => changeset.is_open?,
+  "comments_count" => changeset.comments.length,
+  "changes_count" => changeset.num_changes
+}
+attrs["closed_at"] = changeset.closed_at unless changeset.is_open?
+changeset.bbox.to_unscaled.add_bounds_to(attrs, "_") if changeset.bbox.complete?
+
+# user attributes
+
+if changeset.user.data_public?
+  attrs["uid"] = changeset.user_id
+  attrs["user"] = changeset.user.display_name
+end
+
+xml.changeset(attrs) do |changeset_xml_node|
+  changeset.tags.each do |k, v|
+    changeset_xml_node.tag(:k => k, :v => v)
+  end
+
+  # include discussion if requested
+
+  if @include_discussion
+    changeset_xml_node.discussion do |discussion_xml_node|
+      changeset.comments.includes(:author).each do |comment|
+        cattrs = {
+          "date" => comment.created_at.xmlschema
+        }
+        if comment.author.data_public?
+          cattrs["uid"] = comment.author.id
+          cattrs["user"] = comment.author.display_name
+        end
+        discussion_xml_node.comment(cattrs) do |comment_xml_node|
+          comment_xml_node.text(comment.body)
+        end
+      end
+    end
+  end
+end
diff --git a/app/views/api/changesets/changeset.builder b/app/views/api/changesets/changeset.builder
new file mode 100644 (file)
index 0000000..e8da400
--- /dev/null
@@ -0,0 +1,7 @@
+xml.instruct! :xml, :version => "1.0"
+
+# basic attributes
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+  osm << render(:partial => "api/changesets/changeset.builder", :locals => { :changeset => @changeset })
+end
diff --git a/app/views/api/changesets/changesets.builder b/app/views/api/changesets/changesets.builder
new file mode 100644 (file)
index 0000000..da434f1
--- /dev/null
@@ -0,0 +1,9 @@
+xml.instruct! :xml, :version => "1.0"
+
+# basic attributes
+
+xml.osm(OSM::API.new.xml_root_attributes) do |osm|
+  @changesets.each do |changeset|
+    osm << render(:partial => "api/changesets/changeset.builder", :locals => { :changeset => changeset })
+  end
+end
index ce766fe3426d4c677b3e42f1e51d6e239b1017b6..de4ff3cab1cc6304cf02acca9401ff448adbad5c 100644 (file)
@@ -70,6 +70,7 @@
     <li><%= t ".legal_babble.contributors_nl_html", :locale => @locale %></li>
     <li><%= t ".legal_babble.contributors_nz_html", :locale => @locale %></li>
     <li><%= t ".legal_babble.contributors_si_html", :locale => @locale %></li>
+    <li><%= t ".legal_babble.contributors_es_html", :locale => @locale %></li>
     <li><%= t ".legal_babble.contributors_za_html", :locale => @locale %></li>
     <li><%= t ".legal_babble.contributors_gb_html", :locale => @locale %></li>
   </ul>
index 97e5804d967f9f626056f7ada12ce0971135fa85..71c081f4918b1b285f30da04981b9182d5acfaa4 100644 (file)
@@ -1409,6 +1409,11 @@ en:
           <a href="http://www.gu.gov.si/en/">Surveying and Mapping Authority</a> and
           <a href="http://www.mkgp.gov.si/en/">Ministry of Agriculture, Forestry and Food</a>
           (public information of Slovenia).
+        contributors_es_html: |
+          <strong>Spain</strong>: Contains data sourced from the
+          Spanish National Geographic Institute (<a href="http://www.ign.es/">IGN</a>) and
+          National Cartographic System (<a href="http://www.scne.es/">SCNE</a>)
+          licensed for reuse under <a href="https://creativecommons.org/licenses/by/4.0/">CC BY 4.0</a>.
         contributors_za_html: |
           <strong>South Africa</strong>: Contains data sourced from
           <a href="http://www.ngi.gov.za/">Chief Directorate:
index e5e8f823fba089aeb441e7dd9536e0c8dc7cb5b5..4fb244e5bb9700edcac77ed6f24d43ce76439105 100644 (file)
@@ -1498,7 +1498,7 @@ es:
           Nacional Geoespacial</a>, State copyright reserved.
         contributors_gb_html: |-
           <strong>Reino Unido</strong>: Contiene datos de Ordnance Survey &copy; Crown copyright and database right
-           2010-12.
+           2010-19.
         contributors_footer_1_html: Para obtener más detalles sobre estas y otras
           fuentes que se han utilizado para ayudar a mejorar OpenStreetMap, véase
           la <a href="https://wiki.openstreetmap.org/wiki/Contributors">página de
index 76230deecbaff08e54b0094591b678671cb5ee2f..be4875630caece982a086a8f0d68630cbc6b4ffc 100644 (file)
@@ -1674,7 +1674,7 @@ CHANGESET
       changeset = create(:changeset, :user => user)
 
       ## First try with a non-public user
-      new_changeset = private_changeset.to_xml
+      new_changeset = create_changeset_xml(:user => private_user)
       new_tag = XML::Node.new "tag"
       new_tag["k"] = "tagtesting"
       new_tag["v"] = "valuetesting"
@@ -1695,8 +1695,7 @@ CHANGESET
       assert_require_public_data "user with their data non-public, shouldn't be able to edit their changeset"
 
       ## Now try with the public user
-      create(:changeset_tag, :changeset => changeset)
-      new_changeset = changeset.to_xml
+      new_changeset = create_changeset_xml(:id => 1)
       new_tag = XML::Node.new "tag"
       new_tag["k"] = "tagtesting"
       new_tag["v"] = "valuetesting"
@@ -1718,7 +1717,7 @@ CHANGESET
       assert_response :success
 
       assert_select "osm>changeset[id='#{changeset.id}']", 1
-      assert_select "osm>changeset>tag", 2
+      assert_select "osm>changeset>tag", 1
       assert_select "osm>changeset>tag[k='tagtesting'][v='valuetesting']", 1
     end
 
@@ -1729,7 +1728,7 @@ CHANGESET
       basic_authorization create(:user).email, "test"
 
       changeset = create(:changeset)
-      new_changeset = changeset.to_xml
+      new_changeset = create_changeset_xml(:user => changeset.user, :id => changeset.id)
       new_tag = XML::Node.new "tag"
       new_tag["k"] = "testing"
       new_tag["v"] = "testing"
@@ -1959,5 +1958,20 @@ CHANGESET
       xml.find("//osm/way").first[name] = value.to_s
       xml
     end
+
+    ##
+    # build XML for changesets
+    def create_changeset_xml(user: nil, id: nil)
+      root = XML::Document.new
+      root.root = XML::Node.new "osm"
+      cs = XML::Node.new "changeset"
+      if user
+        cs["user"] = user.display_name
+        cs["uid"] = user.id.to_s
+      end
+      cs["id"] = id.to_s if id
+      root.root << cs
+      root
+    end
   end
 end