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:
parent
7b4ef39014
commit
9a930c8d99
1 changed files with 12 additions and 4 deletions
|
|
@ -50,6 +50,14 @@ 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']
|
||||
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue