]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/application_controller.rb
Remove temporary development code
[rails.git] / app / controllers / application_controller.rb
index bd1995014882452fab08990432203104f5701381..0d43393fd4ff6334c0ed0c929c773d5565dd0333 100644 (file)
@@ -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