Skip to content

Commit 3c8f862

Browse files
bolmstenyoganandaness
authored andcommitted
Merge branch 'develop' into SWAP-5056-user-office-one-identity-synchronisation
2 parents 946c6a2 + acff9d3 commit 3c8f862

29 files changed

Lines changed: 209 additions & 233 deletions

apps/backend/src/auth/OAuthAuthorization.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ describe('OAuthAuthorization', () => {
204204

205205
describe('upsertUser->create: INITIAL_USER_OFFICER_EMAIL', () => {
206206
it('should assign USER_OFFICER role if the email is the INITIAL_USER_OFFICER_EMAIL', async () => {
207-
process.env.INITIAL_USER_OFFICER_EMAIL = dummyUser.email!;
207+
process.env.INITIAL_USER_OFFICER_EMAIL = dummyUser.email;
208208

209209
jest.spyOn(mockUserDataSource, 'addUserRole').mockResolvedValue(true);
210210
jest.spyOn(mockUserDataSource, 'getByOIDCSub').mockResolvedValue(null);

apps/backend/src/auth/OAuthAuthorization.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,7 @@ export class OAuthAuthorization extends UserAuthorization {
179179
''
180180
);
181181

182-
const roleID = this.getUserRole({
183-
id: newUser.id,
184-
email: newUser.email,
185-
});
182+
const roleID = this.getUserRole(newUser);
186183

187184
await this.userDataSource.addUserRole({
188185
userID: newUser.id,
@@ -192,15 +189,14 @@ export class OAuthAuthorization extends UserAuthorization {
192189
if (roleID === UserRole.USER_OFFICER) {
193190
logger.logInfo('Initial User Officer created', {
194191
email: newUser.email,
195-
userID: newUser.id,
196192
});
197193
}
198194

199195
return newUser;
200196
}
201197
}
202198

203-
private getUserRole(newUser: { id: number; email: string | null }): UserRole {
199+
private getUserRole(newUser: { id: number; email: string }): UserRole {
204200
const roleID =
205201
env.INITIAL_USER_OFFICER_EMAIL &&
206202
newUser.email === env.INITIAL_USER_OFFICER_EMAIL

apps/backend/src/datasources/DataAccessUsersDataSource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import { BasicUserDetails, User } from '../models/User';
55

66
export type UserWithInstitution = {
77
user: User;
8-
institution: Institution | null;
9-
country: Country | null;
8+
institution: Institution;
9+
country: Country;
1010
};
1111

1212
export interface DataAccessUsersDataSource {

apps/backend/src/datasources/UserDataSource.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ export interface UserDataSource {
2828
getUsersByUserNumbers(id: readonly number[]): Promise<User[]>;
2929
getUserWithInstitution(id: number): Promise<{
3030
user: User;
31-
institution: Institution | null;
32-
country: Country | null;
31+
institution: Institution;
32+
country: Country;
3333
} | null>;
3434
getByUsername(username: string): Promise<User | null>;
3535
getByEmail(email: string): Promise<User | null>;
@@ -58,20 +58,20 @@ export interface UserDataSource {
5858
>;
5959
// Write
6060
create(
61-
user_title: string | null,
61+
user_title: string | undefined,
6262
firstname: string,
6363
lastname: string,
64-
username: string | null,
65-
preferredname: string | null,
66-
oidc_sub: string | null,
67-
oauth_refresh_token: string | null,
68-
oauth_issuer: string | null,
64+
username: string,
65+
preferredname: string | undefined,
66+
oidc_sub: string,
67+
oauth_refreshtoken: string,
68+
oauth_issuer: string,
6969
gender: string,
7070
birthdate: Date,
71-
institution_id: number | null,
71+
institution: number,
7272
department: string,
7373
position: string,
74-
email: string | null,
74+
email: string,
7575
telephone: string
7676
): Promise<User>;
7777
ensureDummyUserExists(userId: number): Promise<User>;

apps/backend/src/datasources/mockups/UserDataSource.ts

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -412,8 +412,8 @@ export class UserDataSourceMock implements UserDataSource {
412412

413413
async getUserWithInstitution(id: number): Promise<{
414414
user: User;
415-
institution: Institution | null;
416-
country: Country | null;
415+
institution: Institution;
416+
country: Country;
417417
} | null> {
418418
return null;
419419
}
@@ -487,20 +487,20 @@ export class UserDataSourceMock implements UserDataSource {
487487
}
488488

489489
async create(
490-
user_title: string | null,
490+
user_title: string | undefined,
491491
firstname: string,
492492
lastname: string,
493-
username: string | null,
494-
preferredname: string | null,
495-
oidc_sub: string | null,
496-
oauth_refresh_token: string | null,
497-
oauth_issuer: string | null,
493+
username: string,
494+
preferredname: string | undefined,
495+
oidc_sub: string,
496+
oauth_refresh_token: string,
497+
oauth_issuer: string,
498498
gender: string,
499499
birthdate: Date,
500-
institution_id: number | null,
500+
institution_id: number,
501501
department: string,
502502
position: string,
503-
email: string | null,
503+
email: string,
504504
telephone: string
505505
) {
506506
return new User(

apps/backend/src/datasources/postgres/DataAccessUsersDataSource.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ export default class PostgresDataAccessUsersDataSource
2222
return database
2323
.select()
2424
.from('users as u')
25-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
26-
.leftJoin('countries as c', { 'i.country_id': 'c.country_id' })
25+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
26+
.join('countries as c', { 'i.country_id': 'c.country_id' })
2727
.join('data_access_user_has_proposal as dauhp', {
2828
'u.user_id': 'dauhp.user_id',
2929
})

apps/backend/src/datasources/postgres/InstrumentDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -636,7 +636,7 @@ export default class PostgresInstrumentDataSource
636636
.join('instrument_has_scientists as ihs', {
637637
'u.user_id': 'ihs.user_id',
638638
})
639-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
639+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
640640
.where('ihs.instrument_id', instrumentId)
641641
.then(
642642
(

apps/backend/src/datasources/postgres/TechniqueDataSource.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ export default class PostgresTechniqueDataSource
123123
.join('technique_has_scientists as ths', {
124124
'u.user_id': 'ths.user_id',
125125
})
126-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
126+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
127127
.where('ths.technique_id', techniqueId)
128128
.then(
129129
(

apps/backend/src/datasources/postgres/UserDataSource.ts

Lines changed: 22 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export default class PostgresUserDataSource implements UserDataSource {
272272
return database
273273
.select()
274274
.from('users as u')
275-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
275+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
276276
.where('user_id', id)
277277
.first()
278278
.then((user: UserRecord) => {
@@ -282,25 +282,23 @@ export default class PostgresUserDataSource implements UserDataSource {
282282

283283
async getUserWithInstitution(id: number): Promise<{
284284
user: User;
285-
institution: Institution | null;
286-
country: Country | null;
285+
institution: Institution;
286+
country: Country;
287287
} | null> {
288288
return database
289289
.select('i.*', 'c.*', 'u.*')
290290
.from('users as u')
291-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
292-
.leftJoin('countries as c', { 'c.country_id': 'i.country_id' })
291+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
292+
.join('countries as c', { 'c.country_id': 'i.country_id' })
293293
.where('user_id', id)
294294
.first()
295295
.then((user: UserRecord & InstitutionRecord & CountryRecord) => {
296296
return !user
297297
? null
298298
: {
299299
user: createUserObject(user),
300-
institution: user.institution_id
301-
? createInstitutionObject(user)
302-
: null,
303-
country: user.country_id ? createCountryObject(user) : null,
300+
institution: createInstitutionObject(user),
301+
country: createCountryObject(user),
304302
};
305303
});
306304
}
@@ -309,21 +307,21 @@ export default class PostgresUserDataSource implements UserDataSource {
309307
return database
310308
.select()
311309
.from('users as u')
312-
.leftJoin('institutions as i', {
310+
.join('institutions as i', {
313311
'u.institution_id': 'i.institution_id',
314312
})
315313
.where('user_id', id)
316314
.first()
317315
.then((user: UserRecord & InstitutionRecord & CountryRecord) =>
318-
user ? createBasicUserObject(user) : null
316+
createBasicUserObject(user)
319317
);
320318
}
321319

322320
async getBasicUsersInfo(ids: readonly number[]): Promise<BasicUserDetails[]> {
323321
return database
324322
.select()
325323
.from('users as u')
326-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
324+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
327325
.whereIn('u.user_id', ids)
328326
.then(
329327
(usersRecord: Array<UserRecord & InstitutionRecord & CountryRecord>) =>
@@ -338,7 +336,7 @@ export default class PostgresUserDataSource implements UserDataSource {
338336
return database
339337
.select()
340338
.from('users as u')
341-
.leftJoin('institutions as i', {
339+
.join('institutions as i', {
342340
'u.institution_id': 'i.institution_id',
343341
})
344342
.whereILikeEscaped('email', '?', email)
@@ -387,20 +385,20 @@ export default class PostgresUserDataSource implements UserDataSource {
387385
}
388386

389387
async create(
390-
user_title: string | null,
388+
user_title: string | undefined,
391389
firstname: string,
392390
lastname: string,
393-
username: string | null,
394-
preferredname: string | null,
395-
oidc_sub: string | null,
396-
oauth_refresh_token: string | null,
397-
oauth_issuer: string | null,
391+
username: string,
392+
preferredname: string | undefined,
393+
oidc_sub: string,
394+
oauth_refresh_token: string,
395+
oauth_issuer: string,
398396
gender: string,
399397
birthdate: Date,
400-
institution_id: number | null,
398+
institution_id: number,
401399
department: string,
402400
position: string,
403-
email: string | null,
401+
email: string,
404402
telephone: string
405403
): Promise<User> {
406404
return database
@@ -511,7 +509,7 @@ export default class PostgresUserDataSource implements UserDataSource {
511509
return database
512510
.select(['*', database.raw('count(*) OVER() AS full_count')])
513511
.from('users')
514-
.leftJoin('institutions as i', {
512+
.join('institutions as i', {
515513
'users.institution_id': 'i.institution_id',
516514
})
517515
.orderBy('users.user_id', orderDirection)
@@ -579,7 +577,7 @@ export default class PostgresUserDataSource implements UserDataSource {
579577
return database
580578
.select(['*', database.raw('count(*) OVER() AS full_count')])
581579
.from('users')
582-
.leftJoin('institutions as i', {
580+
.join('institutions as i', {
583581
'users.institution_id': 'i.institution_id',
584582
})
585583
.whereIn('users.user_id', userIds)
@@ -741,7 +739,7 @@ export default class PostgresUserDataSource implements UserDataSource {
741739
return database
742740
.select()
743741
.from('users as u')
744-
.leftJoin('institutions as i', { 'u.institution_id': 'i.institution_id' })
742+
.join('institutions as i', { 'u.institution_id': 'i.institution_id' })
745743
.join('proposal_user as pc', { 'u.user_id': 'pc.user_id' })
746744
.join('proposals as p', { 'p.proposal_pk': 'pc.proposal_pk' })
747745
.where('p.proposal_pk', id)

apps/backend/src/datasources/postgres/records.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -245,26 +245,26 @@ export interface TemplateRecord {
245245

246246
export interface UserRecord {
247247
readonly user_id: number;
248-
readonly user_title: string | null;
248+
readonly user_title: string;
249249
readonly firstname: string;
250250
readonly lastname: string;
251-
readonly username: string | null;
252-
readonly preferredname: string | null;
251+
readonly username: string;
252+
readonly preferredname: string;
253253
readonly oidc_sub: string | null;
254254
readonly oauth_refresh_token: string | null;
255255
readonly oauth_issuer: string | null;
256256
readonly gender: string;
257257
readonly birthdate: Date;
258258
readonly department: string;
259259
readonly position: string;
260-
readonly email: string | null;
260+
readonly email: string;
261261
readonly telephone: string;
262262
readonly created_at: Date;
263263
readonly updated_at: Date;
264264
readonly full_count: number;
265-
readonly institution_id: number | null;
266-
readonly institution: string | null;
267-
readonly placeholder: boolean | null;
265+
readonly institution_id: number;
266+
readonly institution: string;
267+
readonly placeholder: boolean;
268268
}
269269

270270
export interface VisitRegistrationRecord {

0 commit comments

Comments
 (0)