]> git.openstreetmap.org Git - rails.git/blob - app/controllers/old_relation_controller.rb
Fixed AMF controller methods to hide redacted nodes
[rails.git] / app / controllers / old_relation_controller.rb
1 class OldRelationController < ApplicationController
2   require 'xml/libxml'
3
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
14
15   def history
16     relation = Relation.find(params[:id].to_i)
17     
18     doc = OSM::API.new.get_xml_doc
19     
20     visible_relations = if @user and @user.moderator? and params[:show_redactions] == "true"
21                           relation.old_relations
22                         else
23                           relation.old_relations.unredacted
24                         end
25     
26     visible_relations.each do |old_relation|
27       doc.root << old_relation.to_xml_node
28     end
29     
30     render :text => doc.to_s, :content_type => "text/xml"
31   end
32   
33   def version
34     if @old_relation.redacted? and not (@user and @user.moderator? and params[:show_redactions] == "true")
35       render :nothing => true, :status => :forbidden
36     else
37
38       response.last_modified = @old_relation.timestamp
39       
40       doc = OSM::API.new.get_xml_doc
41       doc.root << @old_relation.to_xml_node
42         
43       render :text => doc.to_s, :content_type => "text/xml"
44     end
45   end
46
47   def redact
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)
55       
56     else
57       # if no redaction ID was provided, then this is an unredact
58       # operation.
59       @old_relation.redact!(nil)
60     end
61     
62     # just return an empty 200 OK for success
63     render :nothing => true
64   end
65
66   private
67   
68   def lookup_old_relation
69     @old_relation = OldRelation.where(:relation_id => params[:id], :version => params[:version]).first
70     if @old_relation.nil?
71       render :nothing => true, :status => :not_found
72       return false
73     end
74   end
75 end