]> git.openstreetmap.org Git - rails.git/commitdiff
Add base old element redactions controller
authorAnton Khorev <tony29@yandex.ru>
Tue, 11 Feb 2025 01:30:35 +0000 (04:30 +0300)
committerAnton Khorev <tony29@yandex.ru>
Mon, 17 Feb 2025 00:51:05 +0000 (03:51 +0300)
app/abilities/api_ability.rb
app/controllers/api/old_elements/redactions_controller.rb [new file with mode: 0644]

index acacec049af1f20f6372c3a008945961fdda6c29..179c2531a35f875638833d6d1b12976b597adff4 100644 (file)
@@ -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 (file)
index 0000000..0213158
--- /dev/null
@@ -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