Simplify deny_access handling
Now that we have all api controllers inheriting from a common base, it's easier to override the deny_access handler without having to switch between both. Fixes #2064
This commit is contained in:
parent
3bb07e29ec
commit
742291a840
16 changed files with 15 additions and 48 deletions
|
@ -1,7 +1,5 @@
|
|||
module Api
|
||||
class CapabilitiesController < ApiController
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource :class => false
|
||||
|
||||
around_action :api_call_handle_error, :api_call_timeout
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Api
|
||||
class ChangesController < ApiController
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource :class => false
|
||||
|
||||
before_action :check_api_readable
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
module Api
|
||||
class ChangesetCommentsController < ApiController
|
||||
before_action :authorize
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ module Api
|
|||
require "xml/libxml"
|
||||
|
||||
before_action :authorize, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe]
|
||||
before_action :api_deny_access_handler, :only => [:create, :update, :upload, :close, :subscribe, :unsubscribe, :expand_bbox]
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Api
|
||||
class MapController < ApiController
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource :class => false
|
||||
|
||||
before_action :check_api_readable
|
||||
|
|
|
@ -5,7 +5,6 @@ module Api
|
|||
require "xml/libxml"
|
||||
|
||||
before_action :authorize, :only => [:create, :update, :delete]
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ module Api
|
|||
before_action :check_api_readable
|
||||
before_action :setup_user_auth, :only => [:create, :comment, :show]
|
||||
before_action :authorize, :only => [:close, :reopen, :destroy]
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -6,7 +6,6 @@ module Api
|
|||
require "xml/libxml"
|
||||
|
||||
before_action :setup_user_auth, :only => [:history, :version]
|
||||
before_action :api_deny_access_handler
|
||||
before_action :authorize, :only => [:redact]
|
||||
|
||||
authorize_resource
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Api
|
||||
class PermissionsController < ApiController
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource :class => false
|
||||
|
||||
before_action :check_api_readable
|
||||
|
|
|
@ -3,7 +3,6 @@ module Api
|
|||
require "xml/libxml"
|
||||
|
||||
before_action :authorize, :only => [:create, :update, :delete]
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
module Api
|
||||
class TracepointsController < ApiController
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
before_action :check_api_readable
|
||||
|
|
|
@ -5,7 +5,6 @@ module Api
|
|||
before_action :authorize_web
|
||||
before_action :set_locale
|
||||
before_action :authorize
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -4,7 +4,6 @@ module Api
|
|||
|
||||
before_action :disable_terms_redirect, :only => [:api_details]
|
||||
before_action :authorize, :only => [:api_details, :api_gpx_files]
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -3,7 +3,6 @@ module Api
|
|||
require "xml/libxml"
|
||||
|
||||
before_action :authorize, :only => [:create, :update, :delete]
|
||||
before_action :api_deny_access_handler
|
||||
|
||||
authorize_resource
|
||||
|
||||
|
|
|
@ -1,3 +1,17 @@
|
|||
class ApiController < ApplicationController
|
||||
skip_before_action :verify_authenticity_token
|
||||
|
||||
def deny_access(_exception)
|
||||
if current_token
|
||||
set_locale
|
||||
report_error t("oauth.permissions.missing"), :forbidden
|
||||
elsif current_user
|
||||
head :forbidden
|
||||
else
|
||||
realm = "Web Password"
|
||||
errormessage = "Couldn't authenticate you"
|
||||
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
|
||||
render :plain => errormessage, :status => :unauthorized
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -395,15 +395,7 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def deny_access(exception)
|
||||
if @api_deny_access_handling
|
||||
api_deny_access(exception)
|
||||
else
|
||||
web_deny_access(exception)
|
||||
end
|
||||
end
|
||||
|
||||
def web_deny_access(_exception)
|
||||
def deny_access(_exception)
|
||||
if current_token
|
||||
set_locale
|
||||
report_error t("oauth.permissions.missing"), :forbidden
|
||||
|
@ -423,26 +415,6 @@ class ApplicationController < ActionController::Base
|
|||
end
|
||||
end
|
||||
|
||||
def api_deny_access(_exception)
|
||||
if current_token
|
||||
set_locale
|
||||
report_error t("oauth.permissions.missing"), :forbidden
|
||||
elsif current_user
|
||||
head :forbidden
|
||||
else
|
||||
realm = "Web Password"
|
||||
errormessage = "Couldn't authenticate you"
|
||||
response.headers["WWW-Authenticate"] = "Basic realm=\"#{realm}\""
|
||||
render :plain => errormessage, :status => :unauthorized
|
||||
end
|
||||
end
|
||||
|
||||
attr_accessor :api_access_handling
|
||||
|
||||
def api_deny_access_handler
|
||||
@api_deny_access_handling = true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# extract authorisation credentials from headers, returns user = nil if none
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue