Skip to content

Commit e024b00

Browse files
milanmajchrakclaude
andcommitted
Match the upstream fix for the EPerson language lookup
DSpace/dspace-angular PR 5323 fixed the same freeze in main and was backported to 8.x and 9.x, not to 7.x. Using the same code and tests keeps later vanilla merges free of conflicts. The spec also resets the spy calls, so each test only sees its own request. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 5adff14 commit e024b00

2 files changed

Lines changed: 31 additions & 21 deletions

File tree

‎src/app/core/locale/locale.interceptor.spec.ts‎

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ describe(`LocaleInterceptor`, () => {
1515
let localeService: any;
1616

1717
const languageList = ['en;q=1', 'it;q=0.9', 'de;q=0.8', 'fr;q=0.7'];
18+
const rootHref = 'https://sandbox.dspace.org/server/api';
1819

19-
const mockLocaleService = jasmine.createSpyObj('LocaleService', {
20-
getCurrentLanguageCode: jasmine.createSpy('getCurrentLanguageCode'),
21-
getLanguageCodeList: of(languageList)
22-
});
20+
const mockLocaleService = jasmine.createSpyObj('LocaleService', [
21+
'getCurrentLanguageCode',
22+
'getLanguageCodeList',
23+
]);
2324

2425
const mockHalEndpointService = {
2526
getRootHref: jasmine.createSpy('getRootHref'),
@@ -46,7 +47,8 @@ describe(`LocaleInterceptor`, () => {
4647

4748
localeService.getCurrentLanguageCode.and.returnValue(of('en'));
4849
localeService.getLanguageCodeList.calls.reset();
49-
mockHalEndpointService.getRootHref.and.returnValue('server/api');
50+
localeService.getLanguageCodeList.and.returnValue(of(languageList));
51+
mockHalEndpointService.getRootHref.and.returnValue(rootHref);
5052
});
5153

5254
describe('', () => {
@@ -75,22 +77,29 @@ describe(`LocaleInterceptor`, () => {
7577
const lang = httpRequest.request.headers.get('Accept-Language');
7678
expect(lang).toBeDefined();
7779
expect(lang).toBe(languageList.toString());
80+
expect(localeService.getLanguageCodeList).toHaveBeenCalledWith(false);
7881
});
7982

80-
it('should use the EPerson language for other requests', () => {
81-
service.request(RestRequestMethod.GET, 'server/api/core/items/123').subscribe();
82-
httpMock.expectOne('server/api/core/items/123');
83+
it('should ignore EPerson settings for root endpoint requests', () => {
84+
service.request(RestRequestMethod.GET, rootHref).subscribe((response) => {
85+
expect(response).toBeTruthy();
86+
});
8387

84-
expect(localeService.getLanguageCodeList).toHaveBeenCalledWith(false);
88+
httpMock.expectOne(rootHref);
89+
90+
expect(localeService.getLanguageCodeList).toHaveBeenCalledWith(true);
8591
});
8692

87-
it('should not use the EPerson language for the root and EPerson requests, they load the EPerson', () => {
88-
service.request(RestRequestMethod.GET, 'server/api').subscribe();
89-
service.request(RestRequestMethod.GET, 'server/api/eperson/epersons/123').subscribe();
90-
httpMock.expectOne('server/api');
91-
httpMock.expectOne('server/api/eperson/epersons/123');
93+
it('should ignore EPerson settings for eperson endpoint requests', () => {
94+
const epersonHref = `${rootHref}/eperson/epersons/1234`;
95+
96+
service.request(RestRequestMethod.GET, epersonHref).subscribe((response) => {
97+
expect(response).toBeTruthy();
98+
});
99+
100+
httpMock.expectOne(epersonHref);
92101

93-
expect(localeService.getLanguageCodeList.calls.allArgs()).toEqual([[true], [true]]);
102+
expect(localeService.getLanguageCodeList).toHaveBeenCalledWith(true);
94103
});
95104

96105
});

‎src/app/core/locale/locale.interceptor.ts‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ export class LocaleInterceptor implements HttpInterceptor {
2323
*/
2424
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
2525
let newReq: HttpRequest<any>;
26-
return this.localeService.getLanguageCodeList(this.isNeededForEPersonLanguage(req.url))
26+
const ignoreEPersonSettings: boolean = this.shouldIgnoreEPersonSettings(req.url);
27+
28+
return this.localeService.getLanguageCodeList(ignoreEPersonSettings)
2729
.pipe(
2830
take(1),
2931
scan((acc: any, value: any) => [...acc, value], []),
@@ -39,11 +41,10 @@ export class LocaleInterceptor implements HttpInterceptor {
3941
}
4042

4143
/**
42-
* The EPerson's language is read through the root and the EPerson endpoints, so requests to them
43-
* can't wait for it: they would wait for themselves and block every other request.
44+
* Avoid recursive EPerson language lookup for requests that are needed to resolve EPerson itself.
4445
*/
45-
private isNeededForEPersonLanguage(url: string): boolean {
46-
const root = this.halEndpointService.getRootHref();
47-
return url === root || url.startsWith(`${root}/eperson/epersons/`);
46+
private shouldIgnoreEPersonSettings(url: string): boolean {
47+
const rootHref = this.halEndpointService.getRootHref();
48+
return url === rootHref || url.startsWith(`${rootHref}/eperson/epersons`);
4849
}
4950
}

0 commit comments

Comments
 (0)