mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
First cut of a simplified "intro" UI layout (#265)
* First cut of a simplified "intro" UI layout * Linter * Add guest role and intro-only access * Fix guest role UI defaults (#940) Use enum predicate to avoid missing role helper. * Remove legacy user role mapping (#941) Drop the unused user role references in role normalization and SSO role mapping forms to avoid implying a role that never existed. Refs: #0 * Remove role normalization (#942) Remove role normalization Roles are now stored directly without legacy mappings. * Revert role mapping logic * Remove `normalize_role_settings` * Remove unnecessary migration * Make `member` the default * Broken `.erb` --------- Signed-off-by: Juan José Mata <juanjo.mata@gmail.com>
This commit is contained in:
@@ -9,6 +9,9 @@ class InvitationsControllerTest < ActionDispatch::IntegrationTest
|
||||
test "should get new" do
|
||||
get new_invitation_url
|
||||
assert_response :success
|
||||
assert_select "option[value=?]", "member"
|
||||
assert_select "option[value=?]", "guest"
|
||||
assert_select "option[value=?]", "admin"
|
||||
end
|
||||
|
||||
test "should create invitation for member" do
|
||||
@@ -89,6 +92,49 @@ class InvitationsControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_equal @admin, invitation.inviter
|
||||
end
|
||||
|
||||
test "admin can create guest invitation" do
|
||||
assert_difference("Invitation.count") do
|
||||
post invitations_url, params: {
|
||||
invitation: {
|
||||
email: "intro-invite@example.com",
|
||||
role: "guest"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
invitation = Invitation.order(created_at: :desc).first
|
||||
assert_equal "guest", invitation.role
|
||||
assert_equal @admin.family, invitation.family
|
||||
assert_equal @admin, invitation.inviter
|
||||
end
|
||||
|
||||
test "inviting an existing user as guest applies intro defaults" do
|
||||
existing_user = users(:empty)
|
||||
existing_user.update!(
|
||||
role: :member,
|
||||
ui_layout: :dashboard,
|
||||
show_sidebar: true,
|
||||
show_ai_sidebar: true,
|
||||
ai_enabled: false
|
||||
)
|
||||
|
||||
assert_difference("Invitation.count") do
|
||||
post invitations_url, params: {
|
||||
invitation: {
|
||||
email: existing_user.email,
|
||||
role: "guest"
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
existing_user.reload
|
||||
assert_equal "guest", existing_user.role
|
||||
assert existing_user.ui_layout_intro?
|
||||
assert_not existing_user.show_sidebar?
|
||||
assert_not existing_user.show_ai_sidebar?
|
||||
assert existing_user.ai_enabled?
|
||||
end
|
||||
|
||||
test "should handle invalid invitation creation" do
|
||||
assert_no_difference("Invitation.count") do
|
||||
post invitations_url, params: {
|
||||
|
||||
@@ -5,6 +5,7 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
|
||||
|
||||
setup do
|
||||
sign_in @user = users(:family_admin)
|
||||
@intro_user = users(:intro_user)
|
||||
@family = @user.family
|
||||
end
|
||||
|
||||
@@ -13,6 +14,21 @@ class PagesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
test "intro page requires guest role" do
|
||||
get intro_path
|
||||
|
||||
assert_redirected_to root_path
|
||||
assert_equal "Intro is only available to guest users.", flash[:alert]
|
||||
end
|
||||
|
||||
test "intro page is accessible for guest users" do
|
||||
sign_in @intro_user
|
||||
|
||||
get intro_path
|
||||
|
||||
assert_response :ok
|
||||
end
|
||||
|
||||
test "dashboard renders sankey chart with subcategories" do
|
||||
# Create parent category with subcategory
|
||||
parent_category = @family.categories.create!(name: "Shopping", classification: "expense", color: "#FF5733")
|
||||
|
||||
@@ -67,4 +67,24 @@ class RegistrationsControllerTest < ActionDispatch::IntegrationTest
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
test "creating account from guest invitation assigns guest role and intro layout" do
|
||||
invitation = invitations(:one)
|
||||
invitation.update!(role: "guest", email: "guest-signup@example.com")
|
||||
|
||||
assert_difference "User.count", +1 do
|
||||
post registration_url, params: { user: {
|
||||
email: invitation.email,
|
||||
password: "Password1!",
|
||||
invitation: invitation.token
|
||||
} }
|
||||
end
|
||||
|
||||
created_user = User.find_by(email: invitation.email)
|
||||
assert_equal "guest", created_user.role
|
||||
assert created_user.ui_layout_intro?
|
||||
assert_not created_user.show_sidebar?
|
||||
assert_not created_user.show_ai_sidebar?
|
||||
assert created_user.ai_enabled?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ class Settings::ProfilesControllerTest < ActionDispatch::IntegrationTest
|
||||
setup do
|
||||
@admin = users(:family_admin)
|
||||
@member = users(:family_member)
|
||||
@intro_user = users(:intro_user)
|
||||
end
|
||||
|
||||
test "should get show" do
|
||||
@@ -12,6 +13,19 @@ class Settings::ProfilesControllerTest < ActionDispatch::IntegrationTest
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
test "intro user sees profile without settings navigation" do
|
||||
sign_in @intro_user
|
||||
get settings_profile_path
|
||||
|
||||
assert_response :success
|
||||
assert_select "#mobile-settings-nav", count: 0
|
||||
assert_select "h2", text: I18n.t("settings.profiles.show.household_title"), count: 0
|
||||
assert_select "[data-action='app-layout#openMobileSidebar']", count: 0
|
||||
assert_select "[data-action='app-layout#closeMobileSidebar']", count: 0
|
||||
assert_select "[data-action='app-layout#toggleLeftSidebar']", count: 0
|
||||
assert_select "[data-action='app-layout#toggleRightSidebar']", count: 0
|
||||
end
|
||||
|
||||
test "admin can remove a family member" do
|
||||
sign_in @admin
|
||||
assert_difference("User.count", -1) do
|
||||
|
||||
6
test/fixtures/chats.yml
vendored
6
test/fixtures/chats.yml
vendored
@@ -4,4 +4,8 @@ one:
|
||||
|
||||
two:
|
||||
title: Second Chat
|
||||
user: family_member
|
||||
user: family_member
|
||||
|
||||
intro:
|
||||
title: Intro Chat
|
||||
user: intro_user
|
||||
|
||||
40
test/fixtures/users.yml
vendored
40
test/fixtures/users.yml
vendored
@@ -3,39 +3,52 @@ empty:
|
||||
first_name: User
|
||||
last_name: One
|
||||
email: user1@example.com
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
role: admin
|
||||
ai_enabled: true
|
||||
show_sidebar: true
|
||||
show_ai_sidebar: true
|
||||
ui_layout: dashboard
|
||||
|
||||
sure_support_staff:
|
||||
family: empty
|
||||
first_name: Support
|
||||
last_name: Admin
|
||||
email: support@sure.am
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
role: super_admin
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
show_sidebar: true
|
||||
show_ai_sidebar: true
|
||||
ui_layout: dashboard
|
||||
|
||||
family_admin:
|
||||
family: dylan_family
|
||||
first_name: Bob
|
||||
last_name: Dylan
|
||||
email: bob@bobdylan.com
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
role: admin
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
ai_enabled: true
|
||||
show_sidebar: true
|
||||
show_ai_sidebar: true
|
||||
ui_layout: dashboard
|
||||
|
||||
family_member:
|
||||
family: dylan_family
|
||||
first_name: Jakob
|
||||
last_name: Dylan
|
||||
email: jakobdylan@yahoo.com
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
onboarded_at: <%= 3.days.ago %>
|
||||
role: member
|
||||
ai_enabled: true
|
||||
show_sidebar: true
|
||||
show_ai_sidebar: true
|
||||
ui_layout: dashboard
|
||||
|
||||
new_email:
|
||||
family: empty
|
||||
@@ -45,7 +58,24 @@ new_email:
|
||||
unconfirmed_email: new@example.com
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
onboarded_at: <%= Time.current %>
|
||||
role: member
|
||||
ai_enabled: true
|
||||
show_sidebar: true
|
||||
show_ai_sidebar: true
|
||||
ui_layout: dashboard
|
||||
|
||||
intro_user:
|
||||
family: empty
|
||||
first_name: Intro
|
||||
last_name: User
|
||||
email: intro@example.com
|
||||
password_digest: $2a$12$XoNBo/cMCyzpYtvhrPAhsubG21mELX48RAcjSVCRctW8dG8wrDIla
|
||||
onboarded_at: <%= 1.day.ago %>
|
||||
role: guest
|
||||
ai_enabled: true
|
||||
show_sidebar: false
|
||||
show_ai_sidebar: false
|
||||
ui_layout: intro
|
||||
|
||||
# SSO-only user: created via JIT provisioning, no local password
|
||||
sso_only:
|
||||
@@ -56,4 +86,4 @@ sso_only:
|
||||
password_digest: ~
|
||||
role: admin
|
||||
onboarded_at: <%= 1.day.ago %>
|
||||
ai_enabled: true
|
||||
ai_enabled: true
|
||||
|
||||
21
test/models/assistant/configurable_test.rb
Normal file
21
test/models/assistant/configurable_test.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
require "test_helper"
|
||||
|
||||
class AssistantConfigurableTest < ActiveSupport::TestCase
|
||||
test "returns dashboard configuration by default" do
|
||||
chat = chats(:one)
|
||||
|
||||
config = Assistant.config_for(chat)
|
||||
|
||||
assert_not_empty config[:functions]
|
||||
assert_includes config[:instructions], "You help users understand their financial data"
|
||||
end
|
||||
|
||||
test "returns intro configuration without functions" do
|
||||
chat = chats(:intro)
|
||||
|
||||
config = Assistant.config_for(chat)
|
||||
|
||||
assert_equal [], config[:functions]
|
||||
assert_includes config[:instructions], "stage of life"
|
||||
end
|
||||
end
|
||||
@@ -61,4 +61,27 @@ class InvitationTest < ActiveSupport::TestCase
|
||||
|
||||
assert_not result
|
||||
end
|
||||
|
||||
test "accept_for applies guest role defaults" do
|
||||
user = users(:family_member)
|
||||
user.update!(
|
||||
family_id: @family.id,
|
||||
role: "member",
|
||||
ui_layout: "dashboard",
|
||||
show_sidebar: true,
|
||||
show_ai_sidebar: true,
|
||||
ai_enabled: false
|
||||
)
|
||||
invitation = @family.invitations.create!(email: user.email, role: "guest", inviter: @inviter)
|
||||
|
||||
result = invitation.accept_for(user)
|
||||
|
||||
assert result
|
||||
user.reload
|
||||
assert_equal "guest", user.role
|
||||
assert user.ui_layout_intro?
|
||||
assert_not user.show_sidebar?
|
||||
assert_not user.show_ai_sidebar?
|
||||
assert user.ai_enabled?
|
||||
end
|
||||
end
|
||||
|
||||
@@ -160,6 +160,47 @@ class UserTest < ActiveSupport::TestCase
|
||||
Setting.openai_access_token = previous
|
||||
end
|
||||
|
||||
test "intro layout collapses sidebars and enables ai" do
|
||||
user = User.new(
|
||||
family: families(:empty),
|
||||
email: "intro-new@example.com",
|
||||
password: "Password1!",
|
||||
password_confirmation: "Password1!",
|
||||
role: :guest,
|
||||
ui_layout: :intro
|
||||
)
|
||||
|
||||
assert user.save, user.errors.full_messages.to_sentence
|
||||
assert user.ui_layout_intro?
|
||||
assert_not user.show_sidebar?
|
||||
assert_not user.show_ai_sidebar?
|
||||
assert user.ai_enabled?
|
||||
end
|
||||
|
||||
test "non-guest role cannot persist intro layout" do
|
||||
user = User.new(
|
||||
family: families(:empty),
|
||||
email: "dashboard-only@example.com",
|
||||
password: "Password1!",
|
||||
password_confirmation: "Password1!",
|
||||
role: :member,
|
||||
ui_layout: :intro
|
||||
)
|
||||
|
||||
assert user.save, user.errors.full_messages.to_sentence
|
||||
assert user.ui_layout_dashboard?
|
||||
end
|
||||
|
||||
test "upgrading guest role restores dashboard layout defaults" do
|
||||
user = users(:intro_user)
|
||||
user.update!(role: :member)
|
||||
user.reload
|
||||
|
||||
assert user.ui_layout_dashboard?
|
||||
assert user.show_sidebar?
|
||||
assert user.show_ai_sidebar?
|
||||
end
|
||||
|
||||
test "update_dashboard_preferences handles concurrent updates atomically" do
|
||||
@user.update!(preferences: {})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user