Skip to content

Commit 8ea968b

Browse files
committed
Merge branch 'develop' into SWAP-4929-user-officer-experiment-table-filter
2 parents 0003da9 + 8e2842a commit 8ea968b

5 files changed

Lines changed: 18 additions & 149 deletions

File tree

apps/backend/package-lock.json

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

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

Lines changed: 5 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,6 @@ const instrumentDataSource = container.resolve(
9696
Tokens.InstrumentDataSource
9797
) as InstrumentDataSource;
9898

99-
const mockRemoveScientistFromInstruments = jest.spyOn(
100-
instrumentDataSource,
101-
'removeScientistFromInstruments'
102-
);
103-
10499
const mockAssignScientistToInstruments = jest.spyOn(
105100
instrumentDataSource,
106101
'assignScientistToInstruments'
@@ -132,7 +127,6 @@ beforeAll(() => {
132127

133128
beforeEach(() => {
134129
mockAssignScientistToInstruments.mockClear();
135-
mockRemoveScientistFromInstruments.mockClear();
136130
mockGetRequiredInstrumentForRole.mockClear();
137131
});
138132

@@ -230,108 +224,23 @@ test('When a user requests multiple instruments, only new existing ones are adde
230224
expect(result).toEqual([lsfInstrument.id]);
231225
});
232226

233-
// getInstrumentsToRemove
234-
test('When a user has an instrument they have not requested, the instrument is removed', async () => {
235-
const requiredInstruments: string[] = [];
236-
const currentInstruments = [isisInstrument];
237-
238-
const result = await userAuthorization.getInstrumentsToRemove(
239-
requiredInstruments,
240-
currentInstruments
241-
);
242-
243-
expect(result).toEqual([isisInstrument.id]);
244-
});
245-
246-
test('When a user has an instrument they have requested, no instrument is removed', async () => {
247-
const requiredInstruments = [isisInstrument.name];
248-
const currentInstruments = [isisInstrument];
249-
250-
const result = await userAuthorization.getInstrumentsToRemove(
251-
requiredInstruments,
252-
currentInstruments
253-
);
254-
255-
expect(result).toEqual([]);
256-
});
257-
258-
test('When a user does not have an instrument they requested, no instrument is removed', async () => {
259-
const requiredInstruments = [isisInstrument.name];
260-
const currentInstruments: Instrument[] = [];
261-
262-
const result = await userAuthorization.getInstrumentsToRemove(
263-
requiredInstruments,
264-
currentInstruments
265-
);
266-
267-
expect(result).toEqual([]);
268-
});
269-
270-
test('When a user requests a nonexisting instrument, all other instruments are removed', async () => {
271-
const requiredInstruments = [nonExistingInstrumentName];
272-
const currentInstruments = [isisInstrument, lsfInstrument];
273-
274-
const result = await userAuthorization.getInstrumentsToRemove(
275-
requiredInstruments,
276-
currentInstruments
277-
);
278-
279-
expect(result).toEqual([isisInstrument.id, lsfInstrument.id]);
280-
});
281-
282-
test('When a user requests multiple instrument, only non requested ones are removed', async () => {
283-
const requiredInstruments = [isisInstrument.name];
284-
const currentInstruments: Instrument[] = [isisInstrument, lsfInstrument];
285-
286-
const result = await userAuthorization.getInstrumentsToRemove(
287-
requiredInstruments,
288-
currentInstruments
289-
);
290-
291-
expect(result).toEqual([lsfInstrument.id]);
292-
});
293-
294227
//autoAssignRemoveInstruments
295-
test('When a user requires an instrument but does not have it, the instrument is assigned and no instrument are removed', async () => {
296-
await userAuthorization.autoAssignRemoveInstruments(
297-
0,
298-
[isisInstrument.name],
299-
[],
300-
true
301-
);
228+
test('When a user requires an instrument but does not have it, the instrument is assigned', async () => {
229+
await userAuthorization.autoAssignInstruments(0, [isisInstrument.name], []);
302230

303231
expect(mockAssignScientistToInstruments).toHaveBeenCalledWith(0, [
304232
isisInstrument.id,
305233
]);
306-
expect(mockRemoveScientistFromInstruments).toHaveBeenCalledTimes(0);
307234
});
308235

309-
test('When a user does not require an instrument but has it, no instrument is assigned and the instrument is removed', async () => {
310-
await userAuthorization.autoAssignRemoveInstruments(
311-
0,
312-
[],
313-
[isisInstrument],
314-
true
315-
);
316-
317-
expect(mockAssignScientistToInstruments).toHaveBeenCalledTimes(0);
318-
expect(mockRemoveScientistFromInstruments).toHaveBeenCalledWith(0, [
319-
isisInstrument.id,
320-
]);
321-
});
322-
323-
test('When a user requires an instrument but has a different one, the requested instrument is assigned and the current instrument is removed', async () => {
324-
await userAuthorization.autoAssignRemoveInstruments(
236+
test('When a user requires an instrument but has a different one, the requested instrument is assigned and the current instrument stays the same', async () => {
237+
await userAuthorization.autoAssignInstruments(
325238
0,
326239
[isisInstrument.name],
327-
[lsfInstrument],
328-
true
240+
[lsfInstrument]
329241
);
330242

331243
expect(mockAssignScientistToInstruments).toHaveBeenCalledWith(0, [
332244
isisInstrument.id,
333245
]);
334-
expect(mockRemoveScientistFromInstruments).toHaveBeenCalledWith(0, [
335-
lsfInstrument.id,
336-
]);
337246
});

apps/backend/src/auth/StfcUserAuthorization.ts

Lines changed: 4 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -102,26 +102,10 @@ export class StfcUserAuthorization extends UserAuthorization {
102102
return instrumentsToAssign.map((instrument) => instrument.id);
103103
}
104104

105-
async getInstrumentsToRemove(
106-
requiredInstrumentNames: string[],
107-
currentInstruments: Instrument[]
108-
) {
109-
// Remove instrument scientist from any instruments they are assigned to,
110-
// but shouldn't be.
111-
// We don't need to check if the instruments exist here,
112-
// because we fetch the list of currently assigned instruments from the DB
113-
return currentInstruments
114-
.filter(
115-
(instrument) => !requiredInstrumentNames.includes(instrument.name)
116-
)
117-
.map((instrument) => instrument.id);
118-
}
119-
120-
async autoAssignRemoveInstruments(
105+
async autoAssignInstruments(
121106
userId: number,
122107
requiredInstrumentNames: string[],
123-
currentInstruments: Instrument[],
124-
removeInstruments: boolean
108+
currentInstruments: Instrument[]
125109
) {
126110
// Assign any instruments which aren't currently assigned
127111
const instrumentsToAdd = await this.getInstrumentsToAdd(
@@ -142,28 +126,6 @@ export class StfcUserAuthorization extends UserAuthorization {
142126
instrumentsToAdd
143127
);
144128
}
145-
146-
if (removeInstruments) {
147-
// Remove any instruments which are currently assigned, but not required
148-
const instrumentsToRemove = await this.getInstrumentsToRemove(
149-
requiredInstrumentNames,
150-
currentInstruments
151-
);
152-
153-
if (instrumentsToRemove.length > 0) {
154-
logger.logInfo(
155-
'Auto-removing STFC instrument scientist from instruments',
156-
{
157-
instruments: instrumentsToRemove,
158-
}
159-
);
160-
161-
this.instrumentDataSource.removeScientistFromInstruments(
162-
userId,
163-
instrumentsToRemove
164-
);
165-
}
166-
}
167129
}
168130

169131
async externalTokenLogin(
@@ -250,16 +212,10 @@ export class StfcUserAuthorization extends UserAuthorization {
250212
await this.instrumentDataSource.getUserInstruments(userNumber);
251213

252214
// Don't remove instruments from ISIS Staff and User officers as these will be manually assigned
253-
this.autoAssignRemoveInstruments(
215+
this.autoAssignInstruments(
254216
userNumber,
255217
requiredInstruments,
256-
currentUserInstruments,
257-
!uniqueRoles.find(
258-
(role) =>
259-
role.name === 'ISIS Instrument Scientist' ||
260-
role.name === 'CLF LSF Link Scientist' ||
261-
role.name === 'User Officer'
262-
)
218+
currentUserInstruments
263219
);
264220
}
265221

apps/frontend/src/components/instrument/CreateUpdateInstrument.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,10 @@ const CreateUpdateInstrument = ({
8282

8383
try {
8484
await api()
85-
.getUsers({ filter: value, userRole: UserRole.INSTRUMENT_SCIENTIST })
85+
.getUsers({
86+
userRole: UserRole.INSTRUMENT_SCIENTIST,
87+
searchText: value,
88+
})
8689
.then((data) => {
8790
if (data.users?.totalCount == 0) {
8891
setFieldError(

apps/frontend/src/components/internalReview/CreateUpdateInternalReview.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ const CreateUpdateInternalReview = ({
8282

8383
try {
8484
await api()
85-
.getUsers({ filter: value, userRole: UserRole.INTERNAL_REVIEWER })
85+
.getUsers({ searchText: value, userRole: UserRole.INTERNAL_REVIEWER })
8686
.then((data) => {
8787
if (data.users?.totalCount == 0) {
8888
setFieldError(

0 commit comments

Comments
 (0)