1 # The ChangesetController is the RESTful interface to Changeset objects
3 class ChangesetController < ApplicationController
7 before_filter :authorize, :only => [:create, :update, :delete, :upload]
8 before_filter :check_write_availability, :only => [:create, :update, :delete, :upload]
9 before_filter :check_read_availability, :except => [:create, :update, :delete, :upload]
10 after_filter :compress_output
12 # Create a changeset from XML.
15 cs = Changeset.from_xml(request.raw_post, true)
20 render :text => cs.id.to_s, :content_type => "text/plain"
22 render :nothing => true, :status => :bad_request
25 render :nothing => true, :status => :method_not_allowed
29 def create_prim(ids, prim, nd)
31 prim.user_id = @user.id
33 prim.save_with_history!
35 ids[nd['id'].to_i] = prim.id
38 def fix_way(w, node_ids)
39 w.nds = w.instance_eval { @nds }.
40 map { |nd| node_ids[nd] || nd }
45 r.members = r.instance_eval { @members }.
46 map { |memb| [memb[0], ids[memb[0]][memb[1].to_i] || memb[1], memb[2]] }
52 changeset = Changeset.find(params[:id])
53 render :text => changeset.to_xml.to_s, :content_type => "text/xml"
54 rescue ActiveRecord::RecordNotFound
55 render :nothing => true, :status => :not_found
62 render :nothing => true, :status => :method_not_allowed
65 changeset = Changeset.find(params[:id])
66 changeset.open = false
68 render :nothing => true
69 rescue ActiveRecord::RecordNotFound
70 render :nothing => true, :status => :not_found
75 # Upload a diff in a single transaction.
77 # This means that each change within the diff must succeed, i.e: that
78 # each version number mentioned is still current. Otherwise the entire
79 # transaction *must* be rolled back.
81 # Furthermore, each element in the diff can only reference the current
84 # Returns: a diffResult document, as described in
85 # http://wiki.openstreetmap.org/index.php/OSM_Protocol_Version_0.6
87 # only allow POST requests, as the upload method is most definitely
88 # not idempotent, as several uploads with placeholder IDs will have
89 # different side-effects.
90 # see http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.1.2
92 render :nothing => true, :status => :method_not_allowed
96 changeset = Changeset.find(params[:id])
98 diff_reader = DiffReader.new(request.raw_post, changeset)
99 Changeset.transaction do
100 result = diff_reader.commit
101 render :text => result.to_s, :content_type => "text/xml"
104 rescue ActiveRecord::RecordNotFound
105 render :nothing => true, :status => :not_found
106 rescue OSM::APIError => ex
107 render ex.render_opts