The personal finance app for everyone (by everyone)
Ruby
Demo warning in `/chat` UI (#466)
Juan José Mata94e87a8b852f
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rbindex 260579d177..d63adfa8a5 100644--- a/app/controllers/application_controller.rb+++ b/app/controllers/application_controller.rb@@ -9,6 +9,8 @@ class ApplicationController < ActionController::Basebefore_action :set_default_chatbefore_action :set_active_storage_url_options+ helper_method :demo_config, :demo_host_match?, :show_demo_warning?+privatedef detect_osuser_agent = request.user_agent@@ -35,4 +37,20 @@ class ApplicationController < ActionController::Baseport: 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?+ endenddiff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rbindex fed96b56e7..c9904ea6b9 100644--- a/app/controllers/sessions_controller.rb+++ b/app/controllers/sessions_controller.rb@@ -5,19 +5,13 @@ class SessionsController < ApplicationControllerlayout "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 < ApplicationControllerdef 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)- endenddiff --git a/app/views/chats/index.html.erb b/app/views/chats/index.html.erbindex 0f4507483a..1225f3fbca 100644--- a/app/views/chats/index.html.erb+++ b/app/views/chats/index.html.erb@@ -1,6 +1,12 @@<div data-controller="chat hotkey"><%= turbo_frame_tag chat_frame do %><div class="flex flex-col h-full md:p-4">+ <% if show_demo_warning? %>+ <%= render "shared/demo_warning",+ title: t("chats.demo_banner_title"),+ message: t("chats.demo_banner_message") %>+ <% end %>+<% if @chats.any? %><div class="grow flex flex-col"><div class="flex items-center justify-between my-6">diff --git a/app/views/chats/new.html.erb b/app/views/chats/new.html.erbindex 8bee54293d..f1017c2dce 100644--- a/app/views/chats/new.html.erb+++ b/app/views/chats/new.html.erb@@ -2,6 +2,12 @@<div class="flex flex-col h-full md:p-4"><%= render "chats/chat_nav", chat: @chat %>+ <% if show_demo_warning? %>+ <%= render "shared/demo_warning",+ title: t("chats.demo_banner_title"),+ message: t("chats.demo_banner_message") %>+ <% end %>+<div class="mt-auto py-8"><%= render "chats/ai_greeting" %></div>diff --git a/app/views/chats/show.html.erb b/app/views/chats/show.html.erbindex 945507f795..f9b170dbe0 100644--- a/app/views/chats/show.html.erb+++ b/app/views/chats/show.html.erb@@ -7,6 +7,12 @@<div class="flex flex-col h-full"><div class="md:p-4"><%= render "chats/chat_nav", chat: @chat %>++ <% if show_demo_warning? %>+ <%= render "shared/demo_warning",+ title: t("chats.demo_banner_title"),+ message: t("chats.demo_banner_message") %>+ <% end %></div><div id="messages" class="grow overflow-y-auto p-4 space-y-6 pb-24 lg:pb-4" data-chat-target="messages">diff --git a/app/views/shared/_demo_warning.html.erb b/app/views/shared/_demo_warning.html.erbnew file mode 100644index 0000000000..e1d003dac8--- /dev/null+++ b/app/views/shared/_demo_warning.html.erb@@ -0,0 +1,13 @@+<%# locals: title:, message: %>+<div class="mb-4 rounded-lg border bg-blue-50 text-blue-700 border-blue-200 theme-dark:bg-blue-900/20 theme-dark:text-blue-400 theme-dark:border-blue-800 p-4" role="status" aria-live="polite">+ <div class="flex items-start gap-3">+ <div class="shrink-0">+ <%= icon "info", size: "sm", color: "blue-600" %>+ </div>+ <div class="flex-1 text-sm">+ <h3 class="font-semibold mb-1"><%= title %></h3>+ <p><%= message %></p>+ </div>+ </div>+</div>+diff --git a/config/locales/views/chats/en.yml b/config/locales/views/chats/en.ymlnew file mode 100644index 0000000000..26c4c9a7d3--- /dev/null+++ b/config/locales/views/chats/en.yml@@ -0,0 +1,6 @@+---+en:+ chats:+ demo_banner_title: "Demo Mode Active"+ demo_banner_message: "You are using an open-weights Qwen3 LLM with credits provided by Cloudflare Workers AI. Result may vary since the codebase was mostly tested on `gpt-4.1` but your tokens don't go anywhere else to be trained with! 🤖"+