mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ADF-5353] WS Token refresh (#6774)
* [ADF-5353] WS Toke refresh * Push UnauthorisedErrorHandler * Remove Unauthorized error handler * Remove app.config switch * Fix unit test test * Update app.module.ts * Update task-filters-cloud.component.ts * Excluded unstable flaky test under review Co-authored-by: Vito Albano <vito.albano@alfresco.com>
This commit is contained in:
@@ -17,8 +17,9 @@
|
||||
|
||||
import { Apollo } from 'apollo-angular';
|
||||
import { HttpLink } from 'apollo-angular/http';
|
||||
import { split, gql, InMemoryCache } from '@apollo/client/core';
|
||||
import { split, gql, InMemoryCache, ApolloLink, InMemoryCacheConfig } from '@apollo/client/core';
|
||||
import { WebSocketLink } from '@apollo/client/link/ws';
|
||||
import { onError } from '@apollo/client/link/error';
|
||||
import { getMainDefinition } from '@apollo/client/utilities';
|
||||
import { Injectable } from '@angular/core';
|
||||
import { StorageService, AppConfigService, AlfrescoApiService } from '@alfresco/adf-core';
|
||||
@@ -75,9 +76,34 @@ export class NotificationCloudService extends BaseCloudService {
|
||||
httpLink
|
||||
);
|
||||
|
||||
const errorLink = onError(({ graphQLErrors, operation, forward }) => {
|
||||
if (graphQLErrors) {
|
||||
for (const err of graphQLErrors) {
|
||||
switch (err.extensions.code) {
|
||||
case 'UNAUTHENTICATED':
|
||||
const oldHeaders = operation.getContext().headers;
|
||||
operation.setContext({
|
||||
headers: {
|
||||
...oldHeaders,
|
||||
'X-Authorization': 'Bearer ' + this.storageService.getItem('access_token')
|
||||
}
|
||||
});
|
||||
forward(operation);
|
||||
break;
|
||||
default:
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
this.apollo.createNamed(appName, {
|
||||
link,
|
||||
cache: new InMemoryCache()
|
||||
link: ApolloLink.from([errorLink, link]),
|
||||
cache: new InMemoryCache({ merge: true } as InMemoryCacheConfig),
|
||||
defaultOptions: {
|
||||
watchQuery: {
|
||||
errorPolicy: 'all'
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { SimpleChange } from '@angular/core';
|
||||
import { ComponentFixture, TestBed, async } from '@angular/core/testing';
|
||||
import { ComponentFixture, TestBed, async, fakeAsync, tick } from '@angular/core/testing';
|
||||
import { setupTestBed } from '@alfresco/adf-core';
|
||||
import { from, Observable, of } from 'rxjs';
|
||||
import { TASK_FILTERS_SERVICE_TOKEN } from '../../../services/cloud-token.service';
|
||||
@@ -381,10 +381,11 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should update filter counter when notification received', async(() => {
|
||||
it('should update filter counter when notification received', fakeAsync(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
component.appName = 'my-app-1';
|
||||
component.ngOnInit();
|
||||
tick(5000);
|
||||
fixture.detectChanges();
|
||||
component.showIcons = true;
|
||||
fixture.whenStable().then(() => {
|
||||
@@ -396,11 +397,12 @@ describe('TaskFiltersCloudComponent', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('should reset filter counter notification when filter is selected', async(() => {
|
||||
it('should reset filter counter notification when filter is selected', fakeAsync(() => {
|
||||
spyOn(taskFilterService, 'getTaskListFilters').and.returnValue(fakeGlobalFilterObservable);
|
||||
let change = new SimpleChange(undefined, 'my-app-1', true);
|
||||
component.appName = 'my-app-1';
|
||||
component.ngOnInit();
|
||||
tick(5000);
|
||||
fixture.detectChanges();
|
||||
component.showIcons = true;
|
||||
fixture.whenStable().then(() => {
|
||||
|
@@ -20,7 +20,7 @@ import { Observable } from 'rxjs';
|
||||
import { TaskFilterCloudService } from '../services/task-filter-cloud.service';
|
||||
import { TaskFilterCloudModel, FilterParamsModel } from '../models/filter-cloud.model';
|
||||
import { TranslationService } from '@alfresco/adf-core';
|
||||
import { takeUntil } from 'rxjs/operators';
|
||||
import { debounceTime, takeUntil } from 'rxjs/operators';
|
||||
import { BaseTaskFiltersCloudComponent } from './base-task-filters-cloud.component';
|
||||
import { TaskDetailsCloudModel } from '../../start-task/models/task-details-cloud.model';
|
||||
import { TaskCloudEngineEvent } from '../../../models/engine-event-cloud.model';
|
||||
@@ -98,6 +98,7 @@ export class TaskFiltersCloudComponent extends BaseTaskFiltersCloudComponent imp
|
||||
initFilterCounterNotifications() {
|
||||
if (this.appName) {
|
||||
this.taskFilterCloudService.getTaskNotificationSubscription(this.appName)
|
||||
.pipe(debounceTime(5000))
|
||||
.subscribe((result: TaskCloudEngineEvent[]) => {
|
||||
result.map((taskEvent: TaskCloudEngineEvent) => {
|
||||
this.checkFilterCounter(taskEvent.entity);
|
||||
|
Reference in New Issue
Block a user