Skip to content

Commit

Permalink
Format permission denied for JSON requests.
Browse files Browse the repository at this point in the history
  • Loading branch information
toomuchpete committed Sep 15, 2024
1 parent e6a94d6 commit 273d796
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,20 @@ def log_audit(action, details = {})

def permission_denied
if current_user
flash[:error] = "Sorry, you are not allowed to access that page."
redirect_to home_url and return
if request.format.json?
render json: { error: "Sorry, you are not allowed to access that page." }, status: :forbidden
else
flash[:error] = "Sorry, you are not allowed to access that page."
redirect_to home_url and return
end
else
flash[:error] = "Please log in to view that page."
session[:login_redirect_url] = request.original_url
redirect_to auth_path and return
if request.format.json?
render json: { error: "Please log in to view that page." }, status: :unauthorized
else
flash[:error] = "Please log in to view that page."
session[:login_redirect_url] = request.original_url
redirect_to auth_path and return
end
end
end

Expand Down

0 comments on commit 273d796

Please sign in to comment.