Only return identity accounts that are active with an active user

This commit is contained in:
Jay Ohms
2026-02-26 16:45:16 -05:00
parent e7241204eb
commit 42900cf170
3 changed files with 34 additions and 2 deletions
@@ -3,5 +3,9 @@ class My::IdentitiesController < ApplicationController
def show
@identity = Current.identity
@active_users = @identity.users.active
.joins(:account)
.merge(Account.active)
.includes(:account)
end
end
+1 -1
View File
@@ -1,6 +1,6 @@
json.id @identity.id
json.accounts @identity.users do |user|
json.accounts @active_users do |user|
json.partial! "my/identities/account", account: user.account
json.user user, partial: "users/user", as: :user
end
@@ -7,12 +7,40 @@ class My::IdentitiesControllerTest < ActionDispatch::IntegrationTest
test "show as JSON" do
identity = identities(:kevin)
expected_count = identity.users.active.joins(:account).merge(Account.active).count
untenanted do
get my_identity_path, as: :json
assert_response :success
assert_equal identity.id, @response.parsed_body["id"]
assert_equal identity.accounts.count, @response.parsed_body["accounts"].count
assert_equal expected_count, @response.parsed_body["accounts"].count
end
end
test "show as JSON includes active users from active accounts only" do
identity = identities(:kevin)
active_account = Account.create!(external_account_id: 9999981, name: "Active Account")
cancelled_account = Account.create!(external_account_id: 9999982, name: "Cancelled Account")
inactive_user_account = Account.create!(external_account_id: 9999983, name: "Inactive User Account")
identity.users.create!(account: active_account, name: "Kevin", role: :owner)
cancelling_user = identity.users.create!(account: cancelled_account, name: "Kevin", role: :owner)
cancelled_account.cancel(initiated_by: cancelling_user)
inactive_user = identity.users.create!(account: inactive_user_account, name: "Kevin", role: :owner)
inactive_user.update!(active: false)
untenanted do
get my_identity_path, as: :json
assert_response :success
account_ids = @response.parsed_body["accounts"].map { |account| account["id"] }
assert_includes account_ids, active_account.id
assert_not_includes account_ids, cancelled_account.id
assert_not_includes account_ids, inactive_user_account.id
end
end
end