Skip to content

Commit 80e3c88

Browse files
committed
Fix User.from_omniauth to provide organisations
We need to call `User.temporarily_add_organisations_until_the_profile_app_is_updated` from `User.from_auth` like we do from `User.from_userinfo` & `User.from_token` so that the `organisations` attribute gets populated.
1 parent 75e87fb commit 80e3c88

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

app/models/user.rb

+3
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ def self.from_auth(auth)
8989
args = auth.extra.raw_info.to_h.slice(*ATTRIBUTES)
9090
args['id'] = auth.uid
9191

92+
# TODO: remove once the OmniAuth info returns the 'organisations' key.
93+
temporarily_add_organisations_until_the_profile_app_is_updated(args)
94+
9295
new(args)
9396
end
9497

spec/models/user_spec.rb

+14-1
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,15 @@
152152
subject(:auth_subject) { described_class.from_omniauth(auth) }
153153

154154
let(:id) { 'f80ba5b2-2eee-457d-9f75-872b5c09be84' }
155-
let(:info) do
155+
let(:info_without_organisations) do
156156
{
157157
'id' => id,
158158
'email' => '[email protected]',
159159
'name' => 'John Doe',
160160
'roles' => 'school-student'
161161
}
162162
end
163+
let(:info) { info_without_organisations }
163164
let(:user) { described_class.new(info) }
164165

165166
let(:auth) do
@@ -190,6 +191,18 @@
190191
expect(user.email).to eq '[email protected]'
191192
end
192193

194+
it 'returns a user with the correct organisations' do
195+
expect(auth_subject.organisations).to eq(organisation_id => 'school-student')
196+
end
197+
198+
context 'when info includes organisations' do
199+
let(:info) { info_without_organisations.merge!('organisations' => { 'c78ab987-5fa8-482e-a9cf-a5e93513349b' => 'school-student' }) }
200+
201+
it 'returns a user with the supplied organisations' do
202+
expect(auth_subject.organisations).to eq('c78ab987-5fa8-482e-a9cf-a5e93513349b' => 'school-student')
203+
end
204+
end
205+
193206
context 'with unusual keys in info' do
194207
let(:info) { { foo: :bar, flibble: :woo } }
195208

0 commit comments

Comments
 (0)