]> git.openstreetmap.org Git - rails.git/commitdiff
Add support for ACL blocks on note commenting
authorTom Hughes <tom@compton.nu>
Tue, 3 Jun 2014 19:59:25 +0000 (20:59 +0100)
committerTom Hughes <tom@compton.nu>
Tue, 3 Jun 2014 19:59:25 +0000 (20:59 +0100)
app/controllers/notes_controller.rb
app/models/acl.rb
lib/osm.rb

index 76c97ba5b3799770c3e3f55fe212efa426b489d3..acd88be04329d7f0760ee0e52b69976df581a4d3 100644 (file)
@@ -53,6 +53,9 @@ class NotesController < ApplicationController
   ##
   # Create a new note
   def create
+    # Check the ACLs
+    raise OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
+
     # Check the arguments are sane
     raise OSM::APIBadUserInput.new("No lat was given") unless params[:lat]
     raise OSM::APIBadUserInput.new("No lon was given") unless params[:lon]
@@ -86,6 +89,9 @@ class NotesController < ApplicationController
   ##
   # Add a comment to an existing note
   def comment
+    # Check the ACLs
+    raise OSM::APIAccessDenied if Acl.no_note_comment(request.remote_ip)
+
     # Check the arguments are sane
     raise OSM::APIBadUserInput.new("No id was given") unless params[:id]
     raise OSM::APIBadUserInput.new("No text was given") if params[:text].blank?
index 2db7fb76522a0342324d235367ae51d0c5932c97..e2f163ea585bf8bd5453208c7da72dc24d360548 100644 (file)
@@ -11,6 +11,10 @@ class Acl < ActiveRecord::Base
     self.match(address, domain).where(:k => "no_account_creation").exists?
   end
 
+  def self.no_note_comment(address, domain = nil)
+    self.match(address, domain).where(:k => "no_note_comment").exists?
+  end
+
   def self.no_trace_download(address, domain = nil)
     self.match(address, domain).where(:k => "no_trace_download").exists?
   end
index 9e819829921f68f0b8b74c5a70f4b407b6cf0570..daef8d3f0edcb27a219c92f0fc35f05a860c1d62 100644 (file)
@@ -24,6 +24,17 @@ module OSM
     end
   end
 
+  # Raised when access is denied.
+  class APIAccessDenied < RuntimeError
+    def status
+      :forbidden
+    end
+
+    def to_s
+      "Access denied"
+    end
+  end
+
   # Raised when an API object is not found.
   class APINotFoundError < APIError
     def status