Skip to content

Commit 596b0db

Browse files
author
Kuno Vercammen
committed
113904: Returning unkown when showing process of deleted user
1 parent d1876a8 commit 596b0db

4 files changed

Lines changed: 125 additions & 13 deletions

File tree

src/app/process-page/form/process-form.component.ts

Lines changed: 37 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,11 +100,11 @@ export class ProcessFormComponent implements OnInit {
100100
}
101101

102102
const stringParameters: ProcessParameter[] = this.parameters.map((parameter: ProcessParameter) => {
103-
return {
104-
name: parameter.name,
105-
value: this.checkValue(parameter),
106-
};
107-
},
103+
return {
104+
name: parameter.name,
105+
value: this.checkValue(parameter),
106+
};
107+
},
108108
);
109109
this.scriptService.invoke(this.selectedScript.id, stringParameters, this.files)
110110
.pipe(getFirstCompletedRemoteData())
@@ -177,5 +177,36 @@ export class ProcessFormComponent implements OnInit {
177177
};
178178
void this.router.navigate([getProcessListRoute()], extras);
179179
}
180-
}
181180

181+
updateScript($event: Script) {
182+
this.selectedScript = $event;
183+
this.parameters = undefined;
184+
this.updateName();
185+
}
186+
187+
updateName(): void {
188+
if (isEmpty(this.customName)) {
189+
this.processName = this.generatedProcessName;
190+
} else {
191+
this.processName = this.customName;
192+
}
193+
}
194+
195+
get generatedProcessName() {
196+
const paramsString = this.parameters?.map((p: ProcessParameter) => {
197+
const value = this.parseValue(p.value);
198+
return isEmpty(value) ? p.name : `${p.name} ${value}`;
199+
}).join(' ') || '';
200+
return isEmpty(paramsString) ? this.selectedScript.name : `${this.selectedScript.name} ${paramsString}`;
201+
}
202+
203+
private parseValue(value: any) {
204+
if (typeof value === 'boolean') {
205+
return undefined;
206+
}
207+
if (value instanceof File) {
208+
return value.name;
209+
}
210+
return value?.toString();
211+
}
212+
}

src/app/process-page/overview/table/process-overview-table.component.spec.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ import { AuthService } from '../../../core/auth/auth.service';
1818
import { ProcessDataService } from '../../../core/data/processes/process-data.service';
1919
import { EPersonDataService } from '../../../core/eperson/eperson-data.service';
2020
import { EPerson } from '../../../core/eperson/models/eperson.model';
21+
import { ProcessBulkDeleteService } from '../process-bulk-delete.service';
22+
import { ProcessStatus } from '../../processes/process-status.model';
23+
import { createSuccessfulRemoteDataObject$ } from '../../../shared/remote-data.utils';
24+
import { createPaginatedList } from '../../../shared/testing/utils.test';
25+
import { PaginationServiceStub } from '../../../shared/testing/pagination-service.stub';
26+
import { BehaviorSubject } from 'rxjs';
27+
import { NgbModal, NgbCollapse } from '@ng-bootstrap/ng-bootstrap';
28+
import { VarDirective } from '../../../shared/utils/var.directive';
29+
import { TranslateModule, TranslateService } from '@ngx-translate/core';
30+
import { RouterTestingModule } from '@angular/router/testing';
2131
import { PaginationService } from '../../../core/pagination/pagination.service';
2232
import { RouteService } from '../../../core/services/route.service';
2333
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
@@ -46,6 +56,7 @@ describe('ProcessOverviewTableComponent', () => {
4656
let modalService: NgbModal;
4757
let authService; // : AuthService; Not typed as the mock does not fully implement AuthService
4858
let routeService: RouteService;
59+
let translateService: TranslateService;
4960

5061
let processes: Process[];
5162
let ePerson: EPerson;
@@ -217,4 +228,50 @@ describe('ProcessOverviewTableComponent', () => {
217228
});
218229

219230
});
231+
/*
232+
describe('getEPersonName', () => {
233+
beforeEach(() => {
234+
init();
235+
translateService = getMockTranslateService();
236+
});
237+
238+
it('should return the name when the ID is valid', () => {
239+
const id = 'valid_id';
240+
const expectedName = 'John Doe';
241+
242+
spyOn(dsoNameService, 'getName').and.returnValue(expectedName);
243+
244+
component.getEPersonName(id).subscribe(name => {
245+
expect(name).toEqual(expectedName);
246+
});
247+
248+
expect(ePersonService.findById).toHaveBeenCalledWith(id);
249+
});
250+
251+
fit('should return "Unknown" when the ID is invalid', () => {
252+
const id = 'invalid_id';
253+
const translationKey = 'unknown_user';
254+
const expectedMessage = 'Unknown';
255+
256+
spyOn(translateService, 'get').and.returnValue(of(expectedMessage));
257+
258+
component.getEPersonName(id).subscribe(name => {
259+
expect(name).toEqual(expectedMessage);
260+
});
261+
262+
expect(ePersonService.findById).toHaveBeenCalledWith(id);
263+
expect(translateService.get).toHaveBeenCalledWith(translationKey);
264+
});
265+
266+
it('should return an empty observable when the ID is null', () => {
267+
const id = null;
268+
269+
component.getEPersonName(id).subscribe(name => {
270+
expect(name).toBeUndefined();
271+
});
272+
273+
expect(ePersonService.findById).not.toHaveBeenCalled();
274+
});
275+
});
276+
*/
220277
});

src/app/process-page/overview/table/process-overview-table.component.ts

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ import { redirectOn4xx } from '../../../core/shared/authorized.operators';
4747
import {
4848
getAllCompletedRemoteData,
4949
getFirstSucceededRemoteDataPayload,
50+
getAllCompletedRemoteData, getFirstCompletedRemoteData
5051
} from '../../../core/shared/operators';
5152
import { hasValue } from '../../../shared/empty.util';
5253
import { ThemedLoadingComponent } from '../../../shared/loading/themed-loading.component';
@@ -60,6 +61,17 @@ import {
6061
ProcessOverviewService,
6162
ProcessSortField,
6263
} from '../process-overview.service';
64+
import { map, switchMap, toArray, take, filter } from 'rxjs/operators';
65+
import { EPerson } from '../../../core/eperson/models/eperson.model';
66+
import { PaginationService } from 'src/app/core/pagination/pagination.service';
67+
import { FindListOptions } from '../../../core/data/find-list-options.model';
68+
import { redirectOn4xx } from '../../../core/shared/authorized.operators';
69+
import { Router } from '@angular/router';
70+
import { AuthService } from '../../../core/auth/auth.service';
71+
import { isPlatformBrowser } from '@angular/common';
72+
import { RouteService } from '../../../core/services/route.service';
73+
import { hasValue, isNotEmpty } from '../../../shared/empty.util';
74+
import { TranslateService } from '@ngx-translate/core';
6375

6476
const NEW_PROCESS_PARAM = 'new_process_id';
6577

@@ -159,6 +171,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
159171
protected routeService: RouteService,
160172
protected router: Router,
161173
protected auth: AuthService,
174+
private translateService: TranslateService,
162175
@Inject(PLATFORM_ID) protected platformId: object,
163176
) {
164177
}
@@ -176,7 +189,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
176189
// Creates an ID from the first 2 characters of the process status.
177190
// Should two process status values ever start with the same substring,
178191
// increase the number of characters until the ids are distinct.
179-
this.paginationId = this.processStatus.toLowerCase().substring(0,2);
192+
this.paginationId = this.processStatus.toLowerCase().substring(0, 2);
180193

181194
const defaultPaginationOptions = Object.assign(new PaginationComponentOptions(), {
182195
id: this.paginationId,
@@ -218,7 +231,7 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
218231
// Map RemoteData<PaginatedList<Process>> to RemoteData<PaginatedList<ProcessOverviewTableEntry>>
219232
switchMap((processesRD: RemoteData<PaginatedList<Process>>) => {
220233
// Create observable emitting all processes one by one
221-
return observableFrom(processesRD.payload.page).pipe(
234+
return observableFrom(processesRD.payload.page).pipe(
222235
// Map every Process to ProcessOverviewTableEntry
223236
mergeMap((process: Process) => {
224237
return this.getEPersonName(process.userId).pipe(
@@ -243,7 +256,6 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
243256
}),
244257
);
245258
}),
246-
247259
).subscribe((next: RemoteData<PaginatedList<ProcessOverviewTableEntry>>) => {
248260
this.processesRD$.next(next);
249261
}));
@@ -267,10 +279,20 @@ export class ProcessOverviewTableComponent implements OnInit, OnDestroy {
267279
* @param id ID of the EPerson
268280
*/
269281
getEPersonName(id: string): Observable<string> {
270-
return this.ePersonDataService.findById(id).pipe(
271-
getFirstSucceededRemoteDataPayload(),
272-
map((eperson: EPerson) => this.dsoNameService.getName(eperson)),
273-
);
282+
if (isNotEmpty(id)) {
283+
return this.ePersonDataService.findById(id).pipe(
284+
getFirstCompletedRemoteData(),
285+
switchMap((rd: RemoteData<EPerson>) => {
286+
if (rd.hasSucceeded) {
287+
return observableFrom([this.dsoNameService.getName(rd.payload)]);
288+
} else {
289+
return this.translateService.get('process.overview.unknown.user');
290+
}
291+
})
292+
);
293+
} else {
294+
return this.translateService.get('process.overview.unknown.user');
295+
}
274296
}
275297

276298
/**

src/assets/i18n/en.json5

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3846,6 +3846,8 @@
38463846

38473847
"process.overview.delete.header": "Delete processes",
38483848

3849+
"process.overview.unknown.user": "Unknown",
3850+
38493851
"process.bulk.delete.error.head": "Error on deleteing process",
38503852

38513853
"process.bulk.delete.error.body": "The process with ID {{processId}} could not be deleted. The remaining processes will continue being deleted. ",

0 commit comments

Comments
 (0)