]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Merge branch 'authz' of https://github.com/rubyforgood/openstreetmap-website into...
[rails.git] / app / controllers / application_controller.rb
index bd1995014882452fab08990432203104f5701381..2c5fbe51d0f95315c34cfd3c97e3911d5e6b67c0 100644 (file)
@@ -1,8 +1,11 @@
 class ApplicationController < ActionController::Base
   include SessionPersistence
+  # check_authorization
 
   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 +469,23 @@ class ApplicationController < ActionController::Base
     raise
   end
 
+  def current_ability
+    Ability.new(current_user).merge(granted_capabily)
+  end
+
+  def granted_capabily
+    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