Add support for non-html authenticate_user! responses
This commit is contained in:
parent
3d92560e7a
commit
bdd32643db
2 changed files with 13 additions and 3 deletions
|
@ -8,15 +8,15 @@ module Controllers::User::Authorization
|
||||||
included do
|
included do
|
||||||
helper_method :current_role?, :administered_nonprofit
|
helper_method :current_role?, :administered_nonprofit
|
||||||
private
|
private
|
||||||
def authenticate_user!(type= :html)
|
def authenticate_user!(msg=nil, type= :html)
|
||||||
reject_with_sign_in unless current_user
|
reject_with_sign_in(msg, type) unless current_user
|
||||||
end
|
end
|
||||||
|
|
||||||
def reject_with_sign_in(msg=nil, type= :html)
|
def reject_with_sign_in(msg=nil, type= :html)
|
||||||
if type == :html
|
if type == :html
|
||||||
block_with_sign_in(msg)
|
block_with_sign_in(msg)
|
||||||
else
|
else
|
||||||
render text: msg, status: :unauthorized
|
render json: {message:msg}, status: :unauthorized
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
10
app/controllers/direct_uploads_controller.rb
Normal file
10
app/controllers/direct_uploads_controller.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
#
|
||||||
|
class DirectUploadsController < ActiveStorage::DirectUploadsController
|
||||||
|
include Controllers::Nonprofit::Authorization
|
||||||
|
skip_before_action :verify_authenticity_token, only: [:create]
|
||||||
|
before_action do
|
||||||
|
authenticate_user!("You must be logged in to use this", :json)
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue