[add] added maximum client and demo client protection

- default demo clients can no longer be modified/deleted when in demo mode
 - increased default demo reset to 60 minutes
This commit is contained in:
2021-02-25 12:52:23 -05:00
parent 472ae4c90f
commit 5868377210
7 changed files with 60 additions and 7 deletions

View File

@@ -9,6 +9,7 @@ class ClientsController < ApplicationController
before_action :authorize_perm_w, only: %i[update_ipv4 destroy_ipv4]
before_action :authorize_perm_x, only: %i[create update index show destroy]
before_action :client_authorized, except: [:show_public_ipv4]
before_action :demo, only: %i[create update destroy] if ENV['RAILS_API_DEMO']
# URL Methods
# POST /admin/client
@@ -22,6 +23,7 @@ class ClientsController < ApplicationController
# create new client or update existing
if client.nil?
client ||= Client.new_client(client_params)
return head(429) if client.nil? # reached max client count
else
# return 406 if request is trying to remove perm_x from last admin account to prevent lockout
# TODO: move this into the model (update)
@@ -217,4 +219,11 @@ class ClientsController < ApplicationController
def client_authorized
return head(403) unless @authorized
end
# TODO: put this into a demo environment
def demo
demo_clients = %w[admin read_client write_client]
request_params = params.key?(:name) ? params[:name] : ''
return head(406) if demo_clients.include? request_params
end
end