Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* SERVICES */
export * from './services/session.service';
export * from './services/session-idle-timer.service'
export * from './services/session-clear.service'
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';

import { SessionClearService } from './session-clear.service';

describe('SessionClearService', () => {
let service: SessionClearService;

beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(SessionClearService);
});

it('should be created', () => {
expect(service).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {Injectable, OnDestroy} from '@angular/core';
import {Observable, Subject} from 'rxjs';

@Injectable({
providedIn: 'root'
})
export class SessionClearService implements OnDestroy {

private readonly _sessionCleared$: Subject<void>;

constructor() {
this._sessionCleared$ = new Subject<void>();
}

get sessionCleared(): Observable<void> {
return this._sessionCleared$.asObservable();
}

clearSession() {
this._sessionCleared$.next();
}

ngOnDestroy(): void {
this._sessionCleared$.complete();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
import {MessageResource} from '../../../resources/interface/message-resource';
import {LoadingEmitter} from '../../../utility/loading-emitter';
import {SessionIdleTimerService} from "./session-idle-timer.service";
import {SessionClearService} from './session-clear.service';


@Injectable({
providedIn: 'root'
})
export class SessionService implements OnDestroy {

Check warning on line 17 in projects/netgrif-components-core/src/lib/authentication/session/services/session.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark these members as `readonly`.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AaAzWTYeH7vICp03w1mP&open=AaAzWTYeH7vICp03w1mP&pullRequest=348

public static readonly SESSION_TOKEN_STORAGE_KEY = 'naet';
public static readonly SESSION_BEARER_HEADER_DEFAULT = 'X-Auth-Token';
Expand All @@ -28,7 +29,9 @@
constructor(private _config: ConfigurationService,
private _log: LoggerService,
private _http: HttpClient,
private idleTimerService: SessionIdleTimerService) {
private idleTimerService: SessionIdleTimerService,
private _sessionClearService: SessionClearService
) {
this._storage = this.resolveStorage(this._config.get().providers.auth['sessionStore']);
this._sessionHeader = this._config.get().providers.auth.sessionBearer ?
this._config.get().providers.auth.sessionBearer : SessionService.SESSION_BEARER_HEADER_DEFAULT;
Expand Down Expand Up @@ -97,6 +100,7 @@
this._verified = false;
this.sessionToken = '';
this._storage.removeItem(SessionService.SESSION_TOKEN_STORAGE_KEY);
this._sessionClearService.clearSession();
}

public verify(token?: string): Observable<boolean> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import { UriNodeResource } from '../../model/uri-resource';
import {MenuItemClickEvent, MenuItemLoadedEvent} from '../../model/navigation-menu-events';
import {GroupNavigationConstants} from "../../model/group-navigation-constants";
import {SessionClearService} from '../../../authentication/session/services/session-clear.service';
import {UserService} from "../../../user/services/user.service";

/**
Expand All @@ -40,7 +41,7 @@
@Injectable({
providedIn: 'root',
})
export class DoubleDrawerNavigationService implements OnDestroy {

Check warning on line 44 in projects/netgrif-components-core/src/lib/navigation/navigation-double-drawer/service/double-drawer-navigation.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark this member as `readonly`.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AaAzWTcuH7vICp03w1mQ&open=AaAzWTcuH7vICp03w1mQ&pullRequest=348

/**
* List of displayed items on the left side
Expand Down Expand Up @@ -81,6 +82,7 @@
protected hiddenCustomItemsInitialized: boolean;
protected itemClicked: EventEmitter<MenuItemClickEvent>;
protected itemLoaded: EventEmitter<MenuItemLoadedEvent>;
protected _sessionClearSubscription: Subscription;

constructor(protected _uriService: UriService,
protected _log: LoggerService,
Expand All @@ -91,7 +93,8 @@
protected _accessService: AccessService,
protected _translateService: TranslateService,
protected _dynamicRoutingService: DynamicNavigationRouteProviderService,
protected _redirectService: RedirectService) {
protected _redirectService: RedirectService,
private _sessionClearService: SessionClearService) {
this._leftItems$ = new BehaviorSubject([]);
this._rightItems$ = new BehaviorSubject([]);
this._moreItems$ = new BehaviorSubject([]);
Expand All @@ -113,10 +116,21 @@
).subscribe(node => {
this.currentNode = node;
});

this._sessionClearSubscription = this._sessionClearService.sessionCleared.subscribe({

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please unsubscribe to this subscription on service destroy. I can't find the unsubscription

next: () => {
this._currentNavigationItem = null;
this._childCustomViews = {};
this.customItemsInitialized = false;
this.hiddenCustomItemsInitialized = false;
this._currentNode = null;
}
});
}

public ngOnDestroy(): void {
this._currentNodeSubscription?.unsubscribe();
this._sessionClearSubscription?.unsubscribe();
this._leftLoading$.complete();
this._rightLoading$.complete();
this._nodeLoading$.complete();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@ import {MockUriResourceService} from '../../utility/tests/mocks/mock-uri-resourc
import {TestLoggingConfigurationService} from '../../utility/tests/test-logging-config';
import {UriResourceService} from './uri-resource.service';
import {UriService} from './uri.service';
import {SessionService} from '../../authentication/session/services/session.service';

describe('UriService', () => {
let service: UriService;
let sessionService: SessionService;

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -29,7 +31,9 @@ describe('UriService', () => {
{provide: CaseResourceService, useClass: MockCaseResourceService},
],
});
sessionService = TestBed.inject(SessionService);
service = TestBed.inject(UriService);
sessionService.setVerifiedToken('sessionToken');
});

afterEach(() => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {HttpParams} from '@angular/common/http';
import {Inject, Injectable, OnDestroy, Optional} from '@angular/core';
import {BehaviorSubject, Observable, of} from 'rxjs';
import {map} from 'rxjs/operators';
import {BehaviorSubject, Observable, of, Subscription} from 'rxjs';
import {map, filter} from 'rxjs/operators';
import {CaseSearchRequestBody, PetriNetSearchRequest} from '../../filter/models/case-search-request-body';
import {SimpleFilter} from '../../filter/models/simple-filter';
import {ActiveGroupService} from '../../groups/services/active-group.service';
Expand All @@ -15,6 +15,8 @@
import {UriNodeResource} from '../model/uri-resource';
import {UriResourceService} from './uri-resource.service';
import {GroupNavigationConstants} from "../model/group-navigation-constants";
import {SessionClearService} from '../../authentication/session/services/session-clear.service';
import {SessionService} from '../../authentication/session/services/session.service';

/**
* Service for managing URIs
Expand All @@ -22,18 +24,22 @@
@Injectable({
providedIn: 'root',
})
export class UriService implements OnDestroy {

Check warning on line 27 in projects/netgrif-components-core/src/lib/navigation/service/uri.service.ts

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Mark these members as `readonly`.

See more on https://sonarcloud.io/project/issues?id=netgrif_components&issues=AaAzWTeKH7vICp03w1mR&open=AaAzWTeKH7vICp03w1mR&pullRequest=348

public static ROOT: string = 'root';
private _rootNode: UriNodeResource;
private readonly _rootLoading$: LoadingEmitter;
private readonly _parentLoading$: LoadingEmitter;
private readonly _activeNode$: BehaviorSubject<UriNodeResource>;
protected _sessionClearSubscription: Subscription;
protected _sessionSubscription: Subscription;

constructor(protected _logger: LoggerService,
protected _resourceService: UriResourceService,
protected _caseResourceService: CaseResourceService,
protected _activeGroupService: ActiveGroupService,
private _sessionClearService: SessionClearService,
private _sessionService: SessionService,
@Optional() @Inject(NAE_URI_NODE_CASES_PAGE_SIZE) protected pageSize: string | number) {
if (!pageSize) {
this.pageSize = 20;
Expand All @@ -44,13 +50,25 @@
this._rootLoading$ = new LoadingEmitter();
this._parentLoading$ = new LoadingEmitter();
this._activeNode$ = new BehaviorSubject<UriNodeResource>(undefined);
this.loadRoot();
this._sessionSubscription = this._sessionService.session$.pipe(
filter(token => token !== '' && this._sessionService.verified)
).subscribe(() => {
this.loadRoot();
});
this._sessionClearSubscription = this._sessionClearService.sessionCleared.subscribe({
next: () => {
this._rootNode = null;
this._activeNode$.next(undefined)
}
});
}

public ngOnDestroy() {
this._rootLoading$.complete();
this._parentLoading$.complete();
this._activeNode$.complete();
this._sessionClearSubscription.unsubscribe();
this._sessionSubscription.unsubscribe();
}

public get root(): UriNodeResource {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ import {UriService} from "../../../navigation/service/uri.service";
import {AuthenticationModule} from "../../../authentication/authentication.module";
import {UriResourceService} from "../../../navigation/service/uri-resource.service";
import {MockUriResourceService} from "../../../utility/tests/mocks/mock-uri-resource.service";
import {SessionService} from '../../../authentication/session/services/session.service';

describe('AbstractImportNetComponent', () => {
let component: TestImportComponent;
let fixture: ComponentFixture<TestImportComponent>;
let sideMenuCloseSpy: jasmine.Spy;
let logSpy: jasmine.Spy;
let sessionService: SessionService;

beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -62,6 +64,8 @@ describe('AbstractImportNetComponent', () => {
fixture.detectChanges();
sideMenuCloseSpy = spyOn(TestBed.inject(NAE_SIDE_MENU_CONTROL), 'close');
logSpy = spyOn(TestBed.inject(LoggerService), 'info');
sessionService = TestBed.inject(SessionService);
sessionService.setVerifiedToken('sessionToken');
});

it('should create', () => {
Expand Down
Loading