Skip to content

Commit ae4dadf

Browse files
author
abhinav
committed
fix circular find Eperson request
1 parent 7da01d8 commit ae4dadf

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { HttpClientTestingModule, HttpTestingController, } from '@angular/common
33
import { HTTP_INTERCEPTORS } from '@angular/common/http';
44

55
import { DspaceRestService } from '../dspace-rest/dspace-rest.service';
6+
import { HALEndpointService } from '../shared/hal-endpoint.service';
67
import { RestRequestMethod } from '../data/rest-request-method';
78
import { LocaleService } from './locale.service';
89
import { LocaleInterceptor } from './locale.interceptor';
@@ -20,6 +21,10 @@ describe(`LocaleInterceptor`, () => {
2021
getLanguageCodeList: of(languageList)
2122
});
2223

24+
const mockHalEndpointService = {
25+
getRootHref: jasmine.createSpy('getRootHref'),
26+
};
27+
2328
beforeEach(() => {
2429
TestBed.configureTestingModule({
2530
imports: [HttpClientTestingModule],
@@ -30,6 +35,7 @@ describe(`LocaleInterceptor`, () => {
3035
useClass: LocaleInterceptor,
3136
multi: true,
3237
},
38+
{ provide: HALEndpointService, useValue: mockHalEndpointService },
3339
{ provide: LocaleService, useValue: mockLocaleService },
3440
],
3541
});

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,17 @@ import { HttpEvent, HttpHandler, HttpInterceptor, HttpRequest } from '@angular/c
33

44
import { Observable } from 'rxjs';
55

6+
import { HALEndpointService } from '../shared/hal-endpoint.service';
67
import { LocaleService } from './locale.service';
78
import { mergeMap, scan, take } from 'rxjs/operators';
89

910
@Injectable()
1011
export class LocaleInterceptor implements HttpInterceptor {
1112

12-
constructor(private localeService: LocaleService) {
13+
constructor(
14+
protected halEndpointService: HALEndpointService,
15+
protected localeService: LocaleService,
16+
) {
1317
}
1418

1519
/**
@@ -19,7 +23,7 @@ export class LocaleInterceptor implements HttpInterceptor {
1923
*/
2024
intercept(req: HttpRequest<any>, next: HttpHandler): Observable<HttpEvent<any>> {
2125
let newReq: HttpRequest<any>;
22-
return this.localeService.getLanguageCodeList()
26+
return this.localeService.getLanguageCodeList(req.url === this.halEndpointService.getRootHref())
2327
.pipe(
2428
take(1),
2529
scan((acc: any, value: any) => [...acc, value], []),

src/app/core/locale/locale.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ export class LocaleService implements OnDestroy {
7676
*
7777
* @returns {Observable<string[]>}
7878
*/
79-
getLanguageCodeList(): Observable<string[]> {
79+
getLanguageCodeList(ignoreEPersonSettings = false): Observable<string[]> {
8080
const obs$ = combineLatest([
8181
this.authService.isAuthenticated(),
8282
this.authService.isAuthenticationLoaded()
@@ -85,7 +85,7 @@ export class LocaleService implements OnDestroy {
8585
return obs$.pipe(
8686
mergeMap(([isAuthenticated, isLoaded]) => {
8787
let epersonLang$: Observable<string[]> = observableOf([]);
88-
if (isAuthenticated && isLoaded) {
88+
if (isAuthenticated && isLoaded && !ignoreEPersonSettings) {
8989
epersonLang$ = this.authService.getAuthenticatedUserFromStore().pipe(
9090
take(1),
9191
map((eperson) => {

src/app/core/locale/server-locale.service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export class ServerLocaleService extends LocaleService {
3131
*
3232
* @returns {Observable<string[]>}
3333
*/
34-
getLanguageCodeList(): Observable<string[]> {
34+
getLanguageCodeList(ignoreEPersonSettings = false): Observable<string[]> {
3535
const obs$ = combineLatest([
3636
this.authService.isAuthenticated(),
3737
this.authService.isAuthenticationLoaded()
@@ -41,7 +41,7 @@ export class ServerLocaleService extends LocaleService {
4141
take(1),
4242
mergeMap(([isAuthenticated, isLoaded]) => {
4343
let epersonLang$: Observable<string[]> = observableOf([]);
44-
if (isAuthenticated && isLoaded) {
44+
if (isAuthenticated && isLoaded && !ignoreEPersonSettings) {
4545
epersonLang$ = this.authService.getAuthenticatedUserFromStore().pipe(
4646
take(1),
4747
map((eperson) => {

0 commit comments

Comments
 (0)