1 class OldRelationController < ApplicationController
4 skip_before_filter :verify_authenticity_token
5 before_filter :setup_user_auth, :only => [ :history, :version ]
6 before_filter :authorize, :only => [ :redact ]
7 before_filter :authorize_moderator, :only => [ :redact ]
8 before_filter :require_allow_write_api, :only => [ :redact ]
9 before_filter :check_api_readable
10 before_filter :check_api_writable, :only => [ :redact ]
11 before_filter :lookup_old_relation, :except => [ :history ]
12 after_filter :compress_output
13 around_filter :api_call_handle_error, :api_call_timeout
16 relation = Relation.find(params[:id].to_i)
18 doc = OSM::API.new.get_xml_doc
20 visible_relations = if @user and @user.moderator? and params[:show_redactions] == "true"
21 relation.old_relations
23 relation.old_relations.unredacted
26 visible_relations.each do |old_relation|
27 doc.root << old_relation.to_xml_node
30 render :text => doc.to_s, :content_type => "text/xml"
34 if @old_relation.redacted? and not (@user and @user.moderator? and params[:show_redactions] == "true")
35 render :nothing => true, :status => :forbidden
38 response.last_modified = @old_relation.timestamp
40 doc = OSM::API.new.get_xml_doc
41 doc.root << @old_relation.to_xml_node
43 render :text => doc.to_s, :content_type => "text/xml"
48 redaction_id = params['redaction']
49 unless redaction_id.nil?
50 # if a redaction ID was specified, then set this relation to
51 # be redacted in that redaction. (TODO: check that the
52 # user doing the redaction owns the redaction object too)
53 redaction = Redaction.find(redaction_id.to_i)
54 @old_relation.redact!(redaction)
57 # if no redaction ID was provided, then this is an unredact
59 @old_relation.redact!(nil)
62 # just return an empty 200 OK for success
63 render :nothing => true
68 def lookup_old_relation
69 @old_relation = OldRelation.where(:relation_id => params[:id], :version => params[:version]).first
71 render :nothing => true, :status => :not_found