X-Git-Url: https://git.openstreetmap.org/rails.git/blobdiff_plain/25f27a753f6a79bc1ae494e42cf03b9880d0bdcd..b7baa2c10ac493271a26a89deede2869927f84ec:/app/controllers/application_controller.rb diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index bd1995014..0d43393fd 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,23 @@ 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_user + set_locale + report_error t("oauth.permissions.missing"), :forbidden + else + require_user + end + end + private # extract authorisation credentials from headers, returns user = nil if none