Add admin mode

The API Controller checks if the user is logged in and whether they are an admin, and checks for the X-Admin-Mode header
This commit is contained in:
Justin Edmund 2023-08-24 21:56:41 -07:00
parent 7b4ef39014
commit 9a930c8d99

View file

@ -50,9 +50,17 @@ module Api
@current_user @current_user
end end
def admin_mode
if current_user && current_user.admin? && request.headers['X-Admin-Mode']
@admin_mode ||= request.headers['X-Admin-Mode'] == 'true'
end
@admin_mode
end
def edit_key def edit_key
@edit_key ||= request.headers['X-Edit-Key'] if request.headers['X-Edit-Key'] @edit_key ||= request.headers['X-Edit-Key'] if request.headers['X-Edit-Key']
@edit_key @edit_key
end end
@ -96,9 +104,9 @@ module Api
def render_not_found_response(object) def render_not_found_response(object)
render json: ErrorBlueprint.render(nil, error: { render json: ErrorBlueprint.render(nil, error: {
message: "#{object.capitalize} could not be found", message: "#{object.capitalize} could not be found",
code: 'not_found' code: 'not_found'
}), status: :not_found }), status: :not_found
end end
def render_unauthorized_response def render_unauthorized_response