mirror of
https://github.com/we-promise/sure
synced 2026-04-25 17:15:07 +02:00
Feature: AI sidebar hidden by default for members and guests if AI is disabled (#1510)
* feat: new guest and member has a hidden AI sidebar if AI is disabled * test: show_ai_sidebar state when adding new users * test: covers guests
This commit is contained in:
@@ -379,6 +379,10 @@ class User < ApplicationRecord
|
|||||||
self.show_sidebar = true unless show_sidebar
|
self.show_sidebar = true unless show_sidebar
|
||||||
self.show_ai_sidebar = true unless show_ai_sidebar
|
self.show_ai_sidebar = true unless show_ai_sidebar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if new_record? && member? && !ai_available?
|
||||||
|
self.show_ai_sidebar = false
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def leaving_guest_role?
|
def leaving_guest_role?
|
||||||
|
|||||||
@@ -238,6 +238,89 @@ class UserTest < ActiveSupport::TestCase
|
|||||||
assert user.show_ai_sidebar?
|
assert user.show_ai_sidebar?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "new member defaults show_ai_sidebar to false when AI is not available" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
|
||||||
|
previous = Setting.openai_access_token
|
||||||
|
with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
|
||||||
|
Setting.openai_access_token = nil
|
||||||
|
user = User.new(
|
||||||
|
family: families(:empty),
|
||||||
|
email: "member-no-ai@example.com",
|
||||||
|
password: "Password1!",
|
||||||
|
password_confirmation: "Password1!",
|
||||||
|
role: :member
|
||||||
|
)
|
||||||
|
assert user.save, user.errors.full_messages.to_sentence
|
||||||
|
assert_not user.show_ai_sidebar?
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
Setting.openai_access_token = previous
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new admin defaults show_ai_sidebar to true even when AI is not available" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
|
||||||
|
previous = Setting.openai_access_token
|
||||||
|
with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
|
||||||
|
Setting.openai_access_token = nil
|
||||||
|
user = User.new(
|
||||||
|
family: families(:empty),
|
||||||
|
email: "admin-no-ai@example.com",
|
||||||
|
password: "Password1!",
|
||||||
|
password_confirmation: "Password1!",
|
||||||
|
role: :admin
|
||||||
|
)
|
||||||
|
assert user.save, user.errors.full_messages.to_sentence
|
||||||
|
assert user.show_ai_sidebar?
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
Setting.openai_access_token = previous
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new member defaults show_ai_sidebar to true when AI is available" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(false)
|
||||||
|
user = User.new(
|
||||||
|
family: families(:empty),
|
||||||
|
email: "member-with-ai@example.com",
|
||||||
|
password: "Password1!",
|
||||||
|
password_confirmation: "Password1!",
|
||||||
|
role: :member
|
||||||
|
)
|
||||||
|
assert user.save, user.errors.full_messages.to_sentence
|
||||||
|
assert user.show_ai_sidebar?
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new guest defaults show_ai_sidebar to false when AI is not available" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(true)
|
||||||
|
previous = Setting.openai_access_token
|
||||||
|
with_env_overrides OPENAI_ACCESS_TOKEN: nil, EXTERNAL_ASSISTANT_URL: nil, EXTERNAL_ASSISTANT_TOKEN: nil do
|
||||||
|
Setting.openai_access_token = nil
|
||||||
|
user = User.new(
|
||||||
|
family: families(:empty),
|
||||||
|
email: "guest-no-ai@example.com",
|
||||||
|
password: "Password1!",
|
||||||
|
password_confirmation: "Password1!",
|
||||||
|
role: :guest
|
||||||
|
)
|
||||||
|
assert user.save, user.errors.full_messages.to_sentence
|
||||||
|
assert_not user.show_ai_sidebar?
|
||||||
|
end
|
||||||
|
ensure
|
||||||
|
Setting.openai_access_token = previous
|
||||||
|
end
|
||||||
|
|
||||||
|
test "new guest defaults show_ai_sidebar to false when AI is available" do
|
||||||
|
Rails.application.config.app_mode.stubs(:self_hosted?).returns(false)
|
||||||
|
user = User.new(
|
||||||
|
family: families(:empty),
|
||||||
|
email: "guest-with-ai@example.com",
|
||||||
|
password: "Password1!",
|
||||||
|
password_confirmation: "Password1!",
|
||||||
|
role: :guest
|
||||||
|
)
|
||||||
|
assert user.save, user.errors.full_messages.to_sentence
|
||||||
|
assert_not user.show_ai_sidebar?
|
||||||
|
end
|
||||||
|
|
||||||
test "update_dashboard_preferences handles concurrent updates atomically" do
|
test "update_dashboard_preferences handles concurrent updates atomically" do
|
||||||
@user.update!(preferences: {})
|
@user.update!(preferences: {})
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user