From: Anton Khorev Date: Tue, 11 Feb 2025 01:30:35 +0000 (+0300) Subject: Add base old element redactions controller X-Git-Tag: live~148^2~5 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/84c4ed3fa8e203aa4c84cbf4d735bfcbe456be8c Add base old element redactions controller --- diff --git a/app/abilities/api_ability.rb b/app/abilities/api_ability.rb index acacec049..179c2531a 100644 --- a/app/abilities/api_ability.rb +++ b/app/abilities/api_ability.rb @@ -45,6 +45,7 @@ class ApiAbility can :destroy, Note if scopes.include?("write_notes") can :redact, [OldNode, OldWay, OldRelation] if user.terms_agreed? && scopes.include?("write_redactions") + can [:create, :destroy], :element_version_redaction if user.terms_agreed? && scopes.include?("write_redactions") can :create, UserBlock if scopes.include?("write_blocks") end diff --git a/app/controllers/api/old_elements/redactions_controller.rb b/app/controllers/api/old_elements/redactions_controller.rb new file mode 100644 index 000000000..021315807 --- /dev/null +++ b/app/controllers/api/old_elements/redactions_controller.rb @@ -0,0 +1,31 @@ +module Api + module OldElements + class RedactionsController < ApiController + before_action :check_api_writable + before_action :authorize + + authorize_resource :class => :element_version_redaction + + before_action :lookup_old_element + + def create + redaction_id = params["redaction"] + if redaction_id + redaction = Redaction.find(redaction_id.to_i) + @old_element.redact!(redaction) + head :ok + elsif params["allow_delete"] + # legacy unredact if no redaction ID was provided for /api/0.6/:element_type/:id/:version/redact paths mapped here + destroy + else + raise OSM::APIBadUserInput, "No redaction was given" unless redaction_id + end + end + + def destroy + @old_element.redact!(nil) + head :ok + end + end + end +end