]> git.openstreetmap.org Git - rails.git/blob - app/controllers/api/old_elements/redactions_controller.rb
Merge remote-tracking branch 'upstream/pull/5726'
[rails.git] / app / controllers / api / old_elements / redactions_controller.rb
1 module Api
2   module OldElements
3     class RedactionsController < ApiController
4       before_action :check_api_writable
5       before_action :authorize
6
7       authorize_resource :class => :element_version_redaction
8
9       before_action :lookup_old_element
10
11       def create
12         redaction_id = params["redaction"]
13         if redaction_id
14           redaction = Redaction.find(redaction_id.to_i)
15           @old_element.redact!(redaction)
16           head :ok
17         elsif params["allow_delete"]
18           # legacy unredact if no redaction ID was provided for /api/0.6/:element_type/:id/:version/redact paths mapped here
19           destroy
20         else
21           raise OSM::APIBadUserInput, "No redaction was given" unless redaction_id
22         end
23       end
24
25       def destroy
26         @old_element.redact!(nil)
27         head :ok
28       end
29     end
30   end
31 end