3 class DownloadsController < ApiController
4 authorize_resource :changeset
6 before_action :set_request_formats
9 # download the changeset as an osmChange document.
11 # to make it easier to revert diffs it would be better if the osmChange
12 # format were reversible, i.e: contained both old and new versions of
13 # modified elements. but it doesn't at the moment...
15 # this method cannot order the database changes fully (i.e: timestamp and
16 # version number may be too coarse) so the resulting diff may not apply
17 # to a different database. however since changesets are not atomic this
18 # behaviour cannot be guaranteed anyway and is the result of a design
21 changeset = Changeset.find(params[:changeset_id])
23 # get all the elements in the changeset which haven't been redacted
24 # and stick them in a big array.
25 elements = [changeset.old_nodes.unredacted,
26 changeset.old_ways.unredacted,
27 changeset.old_relations.unredacted].flatten
29 # sort the elements by timestamp and version number, as this is the
30 # almost sensible ordering available. this would be much nicer if
31 # global (SVN-style) versioning were used - then that would be
33 elements.sort_by! { |e| [e.timestamp, e.version] }
35 # generate an output element for each operation. note: we avoid looking
36 # at the history because it is simpler - but it would be more correct to
37 # check these assertions.
42 elements.each do |elt|
44 # first version, so it must be newly-created.
50 # if the element isn't visible then it must have been deleted
55 respond_to do |format|