Rework the default denied access handler to give different responses to tokens, logge...
authorAndy Allan <git@gravitystorm.co.uk>
Wed, 24 Oct 2018 07:39:02 +0000 (09:39 +0200)
committerAndy Allan <git@gravitystorm.co.uk>
Wed, 24 Oct 2018 07:39:02 +0000 (09:39 +0200)
app/controllers/application_controller.rb
config/locales/en.yml

index 0d43393..690bdf5 100644 (file)
@@ -477,11 +477,16 @@ class ApplicationController < ActionController::Base
   end
 
   def deny_access(_exception)
-    if current_user
+    if current_token
       set_locale
       report_error t("oauth.permissions.missing"), :forbidden
+    elsif current_user
+      set_locale
+      report_error t("application.permission_denied"), :forbidden
+    elsif request.get?
+      redirect_to :controller => "users", :action => "login", :referer => request.fullpath
     else
-      require_user
+      head :forbidden
     end
   end
 
index 6e126e2..6942c17 100644 (file)
@@ -1793,6 +1793,7 @@ en:
         other: "GPX file with %{count} points from %{user}"
       description_without_count: "GPX file from %{user}"
   application:
+    permission_denied: You do not have permission to access that action
     require_cookies:
       cookies_needed: "You appear to have cookies disabled - please enable cookies in your browser before continuing."
     require_admin: