]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Simplify deny_access handling
[rails.git] / app / controllers / application_controller.rb
index 0e77a398d6f5d702c83921589ad29da28707d9fe..485c30b21a65de7016d0e9f08067ee916b46e1d4 100644 (file)
@@ -126,7 +126,7 @@ class ApplicationController < ActionController::Base
   end
 
   def check_database_readable(need_api = false)
-    if STATUS == :database_offline || (need_api && STATUS == :api_offline)
+    if Settings.status == "database_offline" || (need_api && Settings.status == "api_offline")
       if request.xhr?
         report_error "Database offline for maintenance", :service_unavailable
       else
@@ -136,8 +136,8 @@ class ApplicationController < ActionController::Base
   end
 
   def check_database_writable(need_api = false)
-    if STATUS == :database_offline || STATUS == :database_readonly ||
-       (need_api && (STATUS == :api_offline || STATUS == :api_readonly))
+    if Settings.status == "database_offline" || Settings.status == "database_readonly" ||
+       (need_api && (Settings.status == "api_offline" || Settings.status == "api_readonly"))
       if request.xhr?
         report_error "Database offline for maintenance", :service_unavailable
       else
@@ -161,9 +161,9 @@ class ApplicationController < ActionController::Base
   end
 
   def database_status
-    if STATUS == :database_offline
+    if Settings.status == "database_offline"
       :offline
-    elsif STATUS == :database_readonly
+    elsif Settings.status == "database_readonly"
       :readonly
     else
       :online
@@ -173,9 +173,9 @@ class ApplicationController < ActionController::Base
   def api_status
     status = database_status
     if status == :online
-      if STATUS == :api_offline
+      if Settings.status == "api_offline"
         status = :offline
-      elsif STATUS == :api_readonly
+      elsif Settings.status == "api_readonly"
         status = :readonly
       end
     end
@@ -184,7 +184,7 @@ class ApplicationController < ActionController::Base
 
   def gpx_status
     status = database_status
-    status = :offline if status == :online && STATUS == :gpx_offline
+    status = :offline if status == :online && Settings.status == "gpx_offline"
     status
   end
 
@@ -338,9 +338,9 @@ class ApplicationController < ActionController::Base
       :style_src => %w['unsafe-inline']
     )
 
-    if STATUS == :database_offline || STATUS == :api_offline
+    if Settings.status == "database_offline" || Settings.status == "api_offline"
       flash.now[:warning] = t("layouts.osm_offline")
-    elsif STATUS == :database_readonly || STATUS == :api_readonly
+    elsif Settings.status == "database_readonly" || Settings.status == "api_readonly"
       flash.now[:warning] = t("layouts.osm_read_only")
     end
 
@@ -395,15 +395,7 @@ class ApplicationController < ActionController::Base
     end
   end
 
-  def deny_access(exception)
-    if @api_deny_access_handling
-      api_deny_access(exception)
-    else
-      web_deny_access(exception)
-    end
-  end
-
-  def web_deny_access(_exception)
+  def deny_access(_exception)
     if current_token
       set_locale
       report_error t("oauth.permissions.missing"), :forbidden
@@ -423,26 +415,6 @@ class ApplicationController < ActionController::Base
     end
   end
 
-  def api_deny_access(_exception)
-    if current_token
-      set_locale
-      report_error t("oauth.permissions.missing"), :forbidden
-    elsif current_user
-      head :forbidden
-    else
-      realm = "Web Password"
-      errormessage = "Couldn't authenticate you"
-      response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
-      render :plain => errormessage, :status => :unauthorized
-    end
-  end
-
-  attr_accessor :api_access_handling
-
-  def api_deny_access_handler
-    @api_deny_access_handling = true
-  end
-
   private
 
   # extract authorisation credentials from headers, returns user = nil if none