]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/old_elements_controller.rb
Add frozen_string_literal comments to ruby files
[rails.git] / app / controllers / api / old_elements_controller.rb
1 # frozen_string_literal: true
2
3 # this class pulls together the logic for all the old_* controllers
4 # into one place. as it turns out, the API methods for historical
5 # nodes, ways and relations are basically identical.
6 module Api
7   class OldElementsController < ApiController
8     before_action :setup_user_auth
9
10     authorize_resource
11
12     before_action :lookup_old_element, :except => [:index]
13     before_action :lookup_old_element_versions, :only => [:index]
14
15     before_action :set_request_formats
16
17     def index
18       # the .where() method used in the lookup_old_element_versions
19       # call won't throw an error if no records are found, so we have
20       # to do that ourselves.
21       raise OSM::APINotFoundError if @elements.empty?
22
23       # determine visible elements
24       @elements = @elements.unredacted unless show_redactions?
25
26       # Render the result
27       respond_to do |format|
28         format.xml
29         format.json
30       end
31     end
32
33     def show
34       if @old_element.redacted? && !show_redactions?
35         head :forbidden
36
37       else
38         response.last_modified = @old_element.timestamp
39
40         # Render the result
41         respond_to do |format|
42           format.xml
43           format.json
44         end
45       end
46     end
47
48     private
49
50     def show_redactions?
51       current_user&.moderator? && params[:show_redactions] == "true"
52     end
53   end
54 end