mirror of
https://github.com/we-promise/sure.git
synced 2026-04-19 12:04:08 +00:00
Demo warning in /chat UI (#466)
* Add demo warning to /chat * Missed two files! * Function calling works now, update message
This commit is contained in:
@@ -9,6 +9,8 @@ class ApplicationController < ActionController::Base
|
||||
before_action :set_default_chat
|
||||
before_action :set_active_storage_url_options
|
||||
|
||||
helper_method :demo_config, :demo_host_match?, :show_demo_warning?
|
||||
|
||||
private
|
||||
def detect_os
|
||||
user_agent = request.user_agent
|
||||
@@ -35,4 +37,20 @@ class ApplicationController < ActionController::Base
|
||||
port: request.optional_port
|
||||
}
|
||||
end
|
||||
|
||||
def demo_config
|
||||
Rails.application.config_for(:demo)
|
||||
rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError
|
||||
nil
|
||||
end
|
||||
|
||||
def demo_host_match?(demo = demo_config)
|
||||
return false unless demo.is_a?(Hash) && demo["hosts"].present?
|
||||
|
||||
demo["hosts"].include?(request.host)
|
||||
end
|
||||
|
||||
def show_demo_warning?
|
||||
demo_host_match?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -5,19 +5,13 @@ class SessionsController < ApplicationController
|
||||
layout "auth"
|
||||
|
||||
def new
|
||||
begin
|
||||
demo = Rails.application.config_for(:demo)
|
||||
@prefill_demo_credentials = demo_host_match?(demo)
|
||||
if @prefill_demo_credentials
|
||||
@email = params[:email].presence || demo["email"]
|
||||
@password = params[:password].presence || demo["password"]
|
||||
else
|
||||
@email = params[:email]
|
||||
@password = params[:password]
|
||||
end
|
||||
rescue RuntimeError, Errno::ENOENT, Psych::SyntaxError
|
||||
# Demo config file missing or malformed - disable demo credential prefilling
|
||||
@prefill_demo_credentials = false
|
||||
demo = demo_config
|
||||
@prefill_demo_credentials = demo_host_match?(demo)
|
||||
|
||||
if @prefill_demo_credentials
|
||||
@email = params[:email].presence || demo["email"]
|
||||
@password = params[:password].presence || demo["password"]
|
||||
else
|
||||
@email = params[:email]
|
||||
@password = params[:password]
|
||||
end
|
||||
@@ -91,10 +85,4 @@ class SessionsController < ApplicationController
|
||||
def set_session
|
||||
@session = Current.user.sessions.find(params[:id])
|
||||
end
|
||||
|
||||
def demo_host_match?(demo)
|
||||
return false unless demo.present? && demo["hosts"].present?
|
||||
|
||||
demo["hosts"].include?(request.host)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user