Remove the internal API

* Bind sessions to identities
* Remove references to the identity token
* Move email changes to identity
* Move account menu into a turbo-frame
* Create tenants from a tenanted route
This commit is contained in:
Stanko Krtalić
2025-10-29 13:02:29 +01:00
committed by Stanko K.R.
parent 440631c790
commit 98755844a1
108 changed files with 1096 additions and 1796 deletions
+16 -35
View File
@@ -3,51 +3,40 @@ module SessionTestHelper
ActionDispatch::Cookies::CookieJar.build(request, cookies.to_hash)
end
def sign_in_as(user)
def sign_in_as(identity)
cookies.delete :session_token
user = users(user) unless user.is_a? User
identify_as user
tenanted do
post session_start_url
assert_response :redirect, "Login should succeed"
cookie = cookies.get_cookie "session_token"
assert_not_nil cookie, "Expected session_token cookie to be set after sign in"
assert_equal Account.sole.slug, cookie.path, "Expected session_token cookie to be scoped to account slug"
end
end
def identify_as(user_or_identity)
user = if user_or_identity.is_a?(User)
user_or_identity
else
users(user_or_identity)
if identity.is_a?(User)
user = identity
identity = user.identity
raise "User #{user.name} (#{user.id}) doesn't have an associated identity" unless identity
elsif !identity.is_a?(Identity)
identity = identities(identity)
end
identity = Identity.find_by(email_address: user.email_address)
identity.send_magic_link
magic_link = identity.magic_links.order(id: :desc).first
untenanted do
post session_magic_link_url, params: { code: magic_link.code }
assert_response :redirect, "Magic link should succeed"
cookie = cookies.get_cookie "identity_token"
assert_not_nil cookie, "Expected identity_token cookie to be set after magic link consumption"
end
assert_response :redirect, "Posting the Magic Link code should grant access"
cookie = cookies.get_cookie "session_token"
assert_not_nil cookie, "Expected session_token cookie to be set after sign in"
end
def sign_out
delete session_path
untenanted do
delete session_path
end
assert_not cookies[:session_token].present?
end
def with_current_user(user)
user = users(user) unless user.is_a? User
Current.session = Session.new(user: user)
Current.session = Session.new(identity: user.identity)
yield
ensure
Current.clear_all
@@ -60,12 +49,4 @@ module SessionTestHelper
ensure
integration_session.default_url_options[:script_name] = original_script_name
end
def tenanted(tenant = ApplicationRecord.current_tenant, &block)
original_script_name = integration_session.default_url_options[:script_name]
integration_session.default_url_options[:script_name] = "/#{tenant}"
yield
ensure
integration_session.default_url_options[:script_name] = original_script_name
end
end