Add telegram bot configuration views and policy methods

- Add telegram_config.html.erb view to display current bot token (masked)
- Add edit_telegram_config.html.erb view for editing configuration
- Update index.html.erb to include 'Manage Telegram Config' navigation
- Add missing edit_telegram_config? and update_telegram_config? policy methods

All views follow established patterns from FA/IB cookie management.
Tests pass: 1011 examples, 0 failures.
This commit is contained in:
Dylan Knutson
2025-08-05 06:44:25 +00:00
parent e78baa6594
commit fe2f6e8b90
4 changed files with 128 additions and 1 deletions

View File

@@ -62,6 +62,16 @@ class GlobalStatePolicy < ApplicationPolicy
is_real_user? && is_role_admin?
end
sig { returns(T::Boolean) }
def edit_telegram_config?
is_real_user? && is_role_admin?
end
sig { returns(T::Boolean) }
def update_telegram_config?
is_real_user? && is_role_admin?
end
class Scope < ApplicationPolicy::Scope
extend T::Sig

View File

@@ -0,0 +1,60 @@
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-2xl font-semibold text-slate-900">
Edit Telegram Bot Configuration
</h1>
<p class="mt-2 text-sm text-slate-700">
Update the configuration values used for Telegram bot authentication.
</p>
</div>
<div class="mt-4 sm:ml-16 sm:mt-0 sm:flex-none">
<%= link_to "Back to Configuration",
telegram_config_global_states_path,
class:
"bg-slate-500 hover:bg-slate-700 text-white font-bold py-2 px-4 rounded" %>
</div>
</div>
<div class="mt-6 overflow-hidden bg-white shadow sm:rounded-lg">
<div class="p-3 sm:p-4">
<%= form_tag telegram_config_global_states_path, method: :patch do %>
<table class="min-w-full divide-y divide-slate-300">
<thead>
<tr>
<th class="pb-2 text-left text-sm font-semibold text-slate-900">
Setting
</th>
<th class="pb-2 text-left text-sm font-semibold text-slate-900">
Value
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-200">
<% @telegram_config.each do |config| %>
<tr>
<td class="py-2 pr-4 text-sm font-medium text-slate-900">
<%= config.key.sub("telegram-", "").titleize %>
</td>
<td class="py-2 pr-4">
<%= text_field_tag "telegram_config[#{config.key}]",
config.value,
class:
"block w-full rounded-md border-slate-300 shadow-sm focus:border-sky-500 focus:ring-sky-500 sm:text-sm" %>
</td>
</tr>
<% end %>
</tbody>
</table>
<div class="mt-4 flex justify-end space-x-3">
<%= link_to "Cancel",
telegram_config_global_states_path,
class:
"rounded-md border border-slate-300 bg-white py-2 px-4 text-sm font-medium text-slate-700 shadow-sm hover:bg-slate-50 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2" %>
<%= submit_tag "Save",
class:
"inline-flex justify-center rounded-md border border-transparent bg-sky-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-sky-700 focus:outline-none focus:ring-2 focus:ring-sky-500 focus:ring-offset-2" %>
</div>
<% end %>
</div>
</div>
</div>

View File

@@ -15,13 +15,16 @@
ib_cookies_global_states_path,
class:
"bg-slate-500 hover:bg-slate-700 text-white font-bold py-2 px-4 rounded" %>
<%= link_to "Manage Telegram Config",
telegram_config_global_states_path,
class:
"bg-slate-500 hover:bg-slate-700 text-white font-bold py-2 px-4 rounded" %>
<%= link_to "New Global State",
new_global_state_path,
class:
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" %>
</div>
</div>
<div class="mt-6 overflow-hidden bg-white shadow sm:rounded-lg">
<div class="p-3 sm:p-4">
<table class="min-w-full divide-y divide-slate-300">

View File

@@ -0,0 +1,54 @@
<div class="mx-auto max-w-7xl px-4 sm:px-6 lg:px-8">
<div class="sm:flex sm:items-center">
<div class="sm:flex-auto">
<h1 class="text-2xl font-semibold text-slate-900">
Telegram Bot Configuration
</h1>
<p class="mt-2 text-sm text-slate-700">
Manage configuration for Telegram bot authentication.
</p>
</div>
<div class="mt-4 space-x-4 sm:ml-16 sm:mt-0 sm:flex-none">
<%= link_to "Back to Global States",
global_states_path,
class:
"bg-slate-500 hover:bg-slate-700 text-white font-bold py-2 px-4 rounded mr-3" %>
<%= link_to "Edit Configuration",
telegram_config_edit_global_states_path,
class:
"bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 rounded" %>
</div>
</div>
<div class="mt-6 overflow-hidden bg-white shadow sm:rounded-lg">
<div class="p-3 sm:p-4">
<table class="min-w-full divide-y divide-slate-300">
<thead>
<tr>
<th class="pb-2 text-left text-sm font-semibold text-slate-900">
Setting
</th>
<th class="pb-2 text-left text-sm font-semibold text-slate-900">
Value
</th>
</tr>
</thead>
<tbody class="divide-y divide-slate-200">
<% @telegram_config.each do |config| %>
<tr>
<td class="py-2 pr-4 text-sm font-medium text-slate-900">
<%= config.key.sub("telegram-", "").titleize %>
</td>
<td class="py-2 pr-4 text-sm text-slate-500">
<% if config.key == "telegram-bot-token" && config.value.present? %>
••••••••
<% else %>
<%= config.value.present? ? config.value : "(not set)" %>
<% end %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>