refactor: account_id is not optional

This commit is contained in:
Shivam Mishra
2025-08-28 16:50:40 +05:30
parent cbe5936b7b
commit 35b09fd8b8
3 changed files with 5 additions and 15 deletions
+3 -3
View File
@@ -1,13 +1,13 @@
class SamlUserBuilder
def initialize(auth_hash, account_id: nil)
def initialize(auth_hash, account_id)
@auth_hash = auth_hash
@account_id = account_id
@saml_settings = AccountSamlSettings.find_by(account_id: account_id) if account_id
@saml_settings = AccountSamlSettings.find_by(account_id: account_id)
end
def perform
@user = find_or_create_user
add_user_to_account if @user.persisted? && @account_id
add_user_to_account if @user.persisted?
@user
end
@@ -41,7 +41,7 @@ module Enterprise::DeviseOverrides::OmniauthCallbacksController
account_id = extract_saml_account_id
return redirect_to login_page_url(error: 'saml-not-enabled') unless saml_enabled_for_account?(account_id)
@resource = SamlUserBuilder.new(auth_hash, account_id: account_id).perform
@resource = SamlUserBuilder.new(auth_hash, account_id).perform
if @resource.persisted?
sign_in_user
@@ -20,7 +20,7 @@ RSpec.describe SamlUserBuilder do
}
end
let(:account) { create(:account) }
let(:builder) { described_class.new(auth_hash, account_id: account.id) }
let(:builder) { described_class.new(auth_hash, account.id) }
describe '#perform' do
context 'when user does not exist' do
@@ -111,16 +111,6 @@ RSpec.describe SamlUserBuilder do
end
end
context 'without account_id' do
let(:builder) { described_class.new(auth_hash) }
it 'creates user without account association' do
user = builder.perform
expect(user.persisted?).to be true
expect(user.accounts).to be_empty
end
end
context 'with role mappings' do
let!(:saml_settings) do
create(:account_saml_settings,