X-Git-Url: https://git.openstreetmap.org./rails.git/blobdiff_plain/3ec67ea2d395f9ae78f806f8e583e10d691861de..a50ad1c895f2d7ed3dfa4d40f3748ae6fb801256:/app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bd1995014..690bdf5ca 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -3,6 +3,8 @@ class ApplicationController < ActionController::Base protect_from_forgery :with => :exception + rescue_from CanCan::AccessDenied, :with => :deny_access + before_action :fetch_body around_action :better_errors_allow_inline, :if => proc { Rails.env.development? } @@ -466,6 +468,28 @@ class ApplicationController < ActionController::Base raise end + def current_ability + Ability.new(current_user).merge(granted_capability) + end + + def granted_capability + Capability.new(current_user, current_token) + end + + def deny_access(_exception) + 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 + head :forbidden + end + end + private # extract authorisation credentials from headers, returns user = nil if none