From 9a930c8d995b0181856a9f2006ddec66670df478 Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Thu, 24 Aug 2023 21:56:41 -0700 Subject: [PATCH] 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 --- app/controllers/api/v1/api_controller.rb | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/api/v1/api_controller.rb b/app/controllers/api/v1/api_controller.rb index fec9ce4..4b94c87 100644 --- a/app/controllers/api/v1/api_controller.rb +++ b/app/controllers/api/v1/api_controller.rb @@ -50,9 +50,17 @@ module Api @current_user 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 @edit_key ||= request.headers['X-Edit-Key'] if request.headers['X-Edit-Key'] - + @edit_key end @@ -96,9 +104,9 @@ module Api def render_not_found_response(object) render json: ErrorBlueprint.render(nil, error: { - message: "#{object.capitalize} could not be found", - code: 'not_found' - }), status: :not_found + message: "#{object.capitalize} could not be found", + code: 'not_found' + }), status: :not_found end def render_unauthorized_response