Improve the structure so users_with_active_accounts is available on identity

This commit is contained in:
Jay Ohms
2026-02-27 09:17:12 -05:00
parent 42900cf170
commit 74eac289ee
4 changed files with 7 additions and 12 deletions
@@ -3,9 +3,5 @@ class My::IdentitiesController < ApplicationController
def show
@identity = Current.identity
@active_users = @identity.users.active
.joins(:account)
.merge(Account.active)
.includes(:account)
end
end
+4
View File
@@ -28,6 +28,10 @@ class Identity < ApplicationRecord
end
end
def users_with_active_accounts
users.joins(:account).merge(Account.active).includes(:account)
end
private
def deactivate_users
users.find_each(&:deactivate)
+1 -1
View File
@@ -1,6 +1,6 @@
json.id @identity.id
json.accounts @active_users do |user|
json.accounts @identity.users_with_active_accounts do |user|
json.partial! "my/identities/account", account: user.account
json.user user, partial: "users/user", as: :user
end
@@ -7,7 +7,7 @@ class My::IdentitiesControllerTest < ActionDispatch::IntegrationTest
test "show as JSON" do
identity = identities(:kevin)
expected_count = identity.users.active.joins(:account).merge(Account.active).count
expected_count = identity.users_with_active_accounts.count
untenanted do
get my_identity_path, as: :json
@@ -17,21 +17,17 @@ class My::IdentitiesControllerTest < ActionDispatch::IntegrationTest
end
end
test "show as JSON includes active users from active accounts only" do
test "show as JSON includes 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
@@ -40,7 +36,6 @@ class My::IdentitiesControllerTest < ActionDispatch::IntegrationTest
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