Skip to content

Commit e7e8574

Browse files
authored
Allow disabling AI assistant (#146)
* Test disabling AI assistant * Leave "Maybe" out of it * It's "sure" now
1 parent 4cd737b commit e7e8574

File tree

4 files changed

+38
-1
lines changed

4 files changed

+38
-1
lines changed

app/controllers/users_controller.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ def update
2121
@user.update!(user_params.except(:redirect_to, :delete_profile_image))
2222
@user.profile_image.purge if should_purge_profile_image?
2323

24-
# Add a special notice if AI was just enabled
24+
# Add a special notice if AI was just enabled or disabled
2525
notice = if !was_ai_enabled && @user.ai_enabled
2626
"AI Assistant has been enabled successfully."
27+
elsif was_ai_enabled && !@user.ai_enabled
28+
"AI Assistant has been disabled."
2729
else
2830
t(".success")
2931
end
@@ -72,6 +74,8 @@ def handle_redirect(notice)
7274
redirect_to goals_onboarding_path
7375
when "trial"
7476
redirect_to trial_onboarding_path
77+
when "ai_prompts"
78+
redirect_to settings_ai_prompts_path, notice: notice
7579
else
7680
redirect_to settings_profile_path, notice: notice
7781
end

app/views/settings/ai_prompts/show.html.erb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
<%= content_for :page_title, t(".page_title") %>
22

3+
<% if Current.user.ai_enabled? %>
4+
<div class="mb-4 flex justify-end">
5+
<%= render DS::Button.new(
6+
text: t(".disable_ai"),
7+
href: user_path(Current.user),
8+
method: :patch,
9+
params: { user: { ai_enabled: false, redirect_to: "ai_prompts" } },
10+
data: { turbo: false },
11+
variant: :destructive
12+
) %>
13+
</div>
14+
<% end %>
15+
316
<div class="bg-container rounded-xl shadow-border-xs p-4">
417
<div class="rounded-xl bg-container-inset space-y-1 p-1">
518
<div class="flex items-center gap-1.5 px-4 py-2 text-xs font-medium text-secondary">

config/locales/views/settings/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ en:
55
show:
66
page_title: AI Prompts
77
openai_label: OpenAI
8+
disable_ai: Disable AI Assistant
89
prompt_instructions: Prompt Instructions
910
main_system_prompt:
1011
title: Main System Prompt
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "application_system_test_case"
2+
3+
class Settings::AiPromptsTest < ApplicationSystemTestCase
4+
setup do
5+
@user = users(:family_admin)
6+
@user.update!(ai_enabled: true)
7+
login_as @user
8+
end
9+
10+
test "user can disable ai assistant" do
11+
visit settings_ai_prompts_path
12+
13+
click_button "Disable AI Assistant"
14+
15+
assert_current_path settings_ai_prompts_path
16+
@user.reload
17+
assert_not @user.ai_enabled?
18+
end
19+
end

0 commit comments

Comments
 (0)