From cd674bbb36aa1d9bf35432770430a1bb4c7afb16 Mon Sep 17 00:00:00 2001 From: Jacques Distler Date: Mon, 22 Nov 2010 19:11:21 -0600 Subject: [PATCH] Clean up a few before_filters --- app/controllers/application_controller.rb | 15 +++++---------- app/controllers/file_controller.rb | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 2313a696..0bd1504d 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -41,11 +41,9 @@ class ApplicationController < ActionController::Base s.scan( %r(\w{#{n},#{n}}) ).collect {|a| (a.hex * 2/3).to_s(16).rjust(n,'0')}.join end - def check_authorization - if in_a_web? and authorization_needed? and not authorized? - redirect_to :controller => 'wiki', :action => 'login', :web => @web_name - return false - end + def check_authorization + redirect_to(:controller => 'wiki', :action => 'login', + :web => @web_name) if in_a_web? and authorization_needed? and not authorized? end def connect_to_model @@ -55,10 +53,8 @@ class ApplicationController < ActionController::Base @author = cookies['author'] || 'AnonymousCoward' if @web_name @web = @wiki.webs[@web_name] - if @web.nil? - render(:status => 404, :text => "Unknown web '#{@web_name}'", :layout => 'error') - return false - end + render(:status => 404, :text => "Unknown web '#{@web_name}'", + :layout => 'error') if @web.nil? end end @@ -252,7 +248,6 @@ class ApplicationController < ActionController::Base layout = false if %w(tex tex_list).include?(action_name) headers['Allow'] = 'POST' render(:status => 405, :text => 'You must use an HTTP POST', :layout => layout) - return false end return true end diff --git a/app/controllers/file_controller.rb b/app/controllers/file_controller.rb index b8510b5b..9e76935a 100644 --- a/app/controllers/file_controller.rb +++ b/app/controllers/file_controller.rb @@ -88,23 +88,23 @@ class FileController < ApplicationController protected def check_authorized - if authorized? or @web.published? - return true - else + unless authorized? or @web.published? @hide_navigation = true render(:status => 403, :text => 'This web is private', :layout => true) - return false end end def check_allow_uploads - render(:status => 404, :text => "Web #{params['web'].inspect} not found", :layout => 'error') and return false unless @web - if @web.allow_uploads? and authorized? - return true + if @web + if @web.allow_uploads? and authorized? + return true + else + @hide_navigation = true + render(:status => 403, :text => 'File uploads are blocked by the webmaster', :layout => true) + return false + end else - @hide_navigation = true - render(:status => 403, :text => 'File uploads are blocked by the webmaster', :layout => true) - return false + render(:status => 404, :text => "Web #{params['web'].inspect} not found", :layout => 'error') end end