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