Add convenience methods to make ACL use simpler
authorTom Hughes <tom@compton.nu>
Wed, 8 Feb 2012 22:38:02 +0000 (22:38 +0000)
committerTom Hughes <tom@compton.nu>
Wed, 8 Feb 2012 22:38:02 +0000 (22:38 +0000)
app/controllers/trace_controller.rb
app/controllers/user_controller.rb
app/models/acl.rb

index dbb8a6f2cb8ef4144e4e8d2eb47863fcb2b0d743..0ab87f6af72ef3b7fae671375aa1872b7022a3d9 100644 (file)
@@ -163,7 +163,7 @@ class TraceController < ApplicationController
     trace = Trace.find(params[:id])
 
     if trace.visible? and (trace.public? or (@user and @user == trace.user))
-      if Acl.match(request.remote_ip).where(:k => "no_trace_download").exists?
+      if Acl.no_trace_download(request.remote_ip)
         render :nothing => true, :status => :forbidden
       elsif request.format == Mime::XML
         send_file(trace.xml_file, :filename => "#{trace.id}.xml", :type => Mime::XML.to_s, :disposition => 'attachment')
index 1d86c0524de727d0d9a7b27c727a87de78458a88..7b3b596df2b5f60957989b3816ae53470ccf6241 100644 (file)
@@ -38,7 +38,7 @@ class UserController < ApplicationController
       else
         render :action => 'terms'
       end
-    elsif params[:user] and Acl.match(request.remote_ip, params[:user][:email].split("@").last).where(:k => "no_account_creation").exists?
+    elsif params[:user] and Acl.no_account_creation(request.remote_ip, params[:user][:email].split("@").last)
       render :action => 'blocked'
     else
       session[:referer] = params[:referer]
@@ -112,7 +112,7 @@ class UserController < ApplicationController
       else
         redirect_to :action => :account, :display_name => @user.display_name
       end
-    elsif Acl.match(request.remote_ip, params[:user][:email].split("@").last).where(:k => "no_account_creation").exists?
+    elsif Acl.no_account_creation(request.remote_ip, params[:user][:email].split("@").last)
       render :action => 'blocked'
     else
       @user = User.new(params[:user])
@@ -271,7 +271,7 @@ class UserController < ApplicationController
                        :openid_url => params[:openid])
 
       flash.now[:notice] = t 'user.new.openid association'
-    elsif Acl.match(request.remote_ip).where(:k => "no_account_creation").exists?
+    elsif Acl.no_account_creation(request.remote_ip)
       render :action => 'blocked'
     end
   end
index e19c6988b4100e59f61e5a5c5a503c9e4c97b4f0..9938984aa89a3d83cef907430c6288fed3aabe07 100644 (file)
@@ -6,4 +6,12 @@ class Acl < ActiveRecord::Base
       condition = Acl.where("address >> ?", address)
     end
   end
+
+  def self.no_account_creation(address, domain = nil)
+    self.match(address, domain).where(:k => "no_account_creation").exists?
+  end
+
+  def self.no_trace_download(address, domain = nil)
+    self.match(address, domain).where(:k => "no_trace_download").exists?
+  end
 end