X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/4028f4cdb91f616bc774dc9b9fa8c7183eb1f6dd..cbff014368294747154cd0c6dd30242f876d2daf:/app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9954b775b..0c50276b6 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -62,7 +62,7 @@ class ApplicationController < ActionController::Base unless current_token.nil? unless current_token.read_attribute(cap) report_error "OAuth token doesn't have that capability.", :forbidden - return false + false end end end @@ -74,7 +74,7 @@ class ApplicationController < ActionController::Base if params[:cookie_test].nil? session[:cookie_test] = true redirect_to Hash[params].merge(:cookie_test => "true") - return false + false else flash.now[:warning] = t "application.require_cookies.cookies_needed" end @@ -140,13 +140,13 @@ class ApplicationController < ActionController::Base unless Authenticator.new(self, [:token]).allow? username, passwd = get_auth_data # parse from headers # authenticate per-scheme - if username.nil? - @user = nil # no authentication provided - perhaps first connect (client should retry after 401) - elsif username == "token" - @user = User.authenticate(:token => passwd) # preferred - random token for user from db, passed in basic auth - else - @user = User.authenticate(:username => username, :password => passwd) # basic auth - end + @user = if username.nil? + nil # no authentication provided - perhaps first connect (client should retry after 401) + elsif username == "token" + User.authenticate(:token => passwd) # preferred - random token for user from db, passed in basic auth + else + User.authenticate(:username => username, :password => passwd) # basic auth + end end # have we identified the user? @@ -192,7 +192,7 @@ class ApplicationController < ActionController::Base # check user is a moderator unless @user.moderator? render :text => errormessage, :status => :forbidden - return false + false end end @@ -220,14 +220,14 @@ class ApplicationController < ActionController::Base def check_api_readable if api_status == :offline report_error "Database offline for maintenance", :service_unavailable - return false + false end end def check_api_writable unless api_status == :online report_error "Database offline for maintenance", :service_unavailable - return false + false end end @@ -262,7 +262,7 @@ class ApplicationController < ActionController::Base def require_public_data unless @user.data_public? report_error "You must make your edits public to upload new data", :forbidden - return false + false end end @@ -276,7 +276,7 @@ class ApplicationController < ActionController::Base response.headers["Error"] = message if request.headers["X-Error-Format"] && - request.headers["X-Error-Format"].downcase == "xml" + request.headers["X-Error-Format"].casecmp("xml").zero? result = OSM::API.new.get_xml_doc result.root.name = "osmError" result.root << (XML::Node.new("status") << "#{Rack::Utils.status_code(status)} #{Rack::Utils::HTTP_STATUS_CODES[status]}") @@ -337,7 +337,7 @@ class ApplicationController < ActionController::Base # or raises a suitable error. +method+ should be a symbol, e.g: :put or :get. def assert_method(method) ok = request.send((method.to_s.downcase + "?").to_sym) - fail OSM::APIBadMethodError.new(method) unless ok + raise OSM::APIBadMethodError.new(method) unless ok end ## @@ -375,7 +375,7 @@ class ApplicationController < ActionController::Base ## # ensure that there is a "this_user" instance variable def lookup_this_user - unless @this_user = User.active.find_by_display_name(params[:display_name]) + unless @this_user = User.active.find_by(:display_name => params[:display_name]) render_unknown_user params[:display_name] end end