diff --git a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts index ecdd7eb3b2..c8f88828ca 100644 --- a/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-documentlist/demo/src/main.ts @@ -156,8 +156,8 @@ class DocumentListDemo implements OnInit { alfrescoSettingsService.host = this.host; - if (localStorage.getItem('token')) { - this.token = localStorage.getItem('token'); + if (this.authService.getToken()) { + this.token = this.authService.getToken(); } translation.addTranslationFolder(); diff --git a/ng2-components/ng2-alfresco-search/demo/src/main.ts b/ng2-components/ng2-alfresco-search/demo/src/main.ts index 2747c510ea..56cead31a4 100644 --- a/ng2-components/ng2-alfresco-search/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-search/demo/src/main.ts @@ -67,8 +67,8 @@ class SearchDemo implements OnInit { translation: AlfrescoTranslationService) { alfrescoSettingsService.host = this.host; - if (localStorage.getItem('token')) { - this.token = localStorage.getItem('token'); + if (this.authService.getToken()) { + this.token = this.authService.getToken(); } translation.addTranslationFolder(); diff --git a/ng2-components/ng2-alfresco-upload/demo/src/main.ts b/ng2-components/ng2-alfresco-upload/demo/src/main.ts index 07b0766b86..a46b97a2ba 100644 --- a/ng2-components/ng2-alfresco-upload/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-upload/demo/src/main.ts @@ -83,8 +83,8 @@ export class MyDemoApp implements OnInit { constructor(private authService: AlfrescoAuthenticationService, private alfrescoSettingsService: AlfrescoSettingsService) { alfrescoSettingsService.host = this.host; - if (localStorage.getItem('token')) { - this.token = localStorage.getItem('token'); + if (this.authService.getToken()) { + this.token = this.authService.getToken(); } } diff --git a/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts b/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts index 53ad887d24..66f95a5990 100644 --- a/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts +++ b/ng2-components/ng2-alfresco-upload/src/assets/upload.service.mock.ts @@ -18,15 +18,16 @@ import { Observable } from 'rxjs/Observable'; import { FileModel } from '../models/file.model'; import { UploadService } from '../services/upload.service'; -import { AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; export class UploadServiceMock extends UploadService { filesUpload$: Observable; totalCompleted$: Observable; - constructor(settings: AlfrescoSettingsService) { - super(settings); + constructor(settings: AlfrescoSettingsService, + authService: AlfrescoAuthenticationService) { + super(settings, authService); } public setOptions(options: any): void { diff --git a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts index 6d78eb4b97..876f8a3262 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/file-uploading-dialog.component.spec.ts @@ -19,7 +19,7 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@ import { TestComponentBuilder } from '@angular/compiler/testing'; import { FileUploadingDialogComponent } from './file-uploading-dialog.component'; import { FileModel } from '../models/file.model'; -import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { TranslationMock } from '../assets/translation.service.mock'; import { UploadServiceMock } from '../assets/upload.service.mock'; import { UploadService } from '../services/upload.service'; @@ -33,6 +33,7 @@ describe('FileUploadDialog', () => { beforeEachProviders(() => { return [ { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService }, + { provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService }, { provide: AlfrescoTranslationService, useClass: TranslationMock }, { provide: UploadService, useClass: UploadServiceMock } ]; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts index b5058ee208..73046bbffe 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-button.component.spec.ts @@ -18,7 +18,7 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; import { UploadButtonComponent } from './upload-button.component'; -import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { TranslationMock } from '../assets/translation.service.mock'; import { UploadServiceMock } from '../assets/upload.service.mock'; import { UploadService } from '../services/upload.service'; @@ -39,6 +39,7 @@ describe('AlfrescoUploadButton', () => { beforeEachProviders(() => { return [ { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock }, + { provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService }, { provide: AlfrescoTranslationService, useClass: TranslationMock }, { provide: UploadService, useClass: UploadServiceMock } ]; diff --git a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts index c22f579e74..146ae3d0d2 100644 --- a/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/components/upload-drag-area.component.spec.ts @@ -18,7 +18,7 @@ import { describe, expect, it, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { TestComponentBuilder } from '@angular/compiler/testing'; import { UploadDragAreaComponent } from './upload-drag-area.component'; -import { AlfrescoTranslationService, AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoTranslationService, AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock'; import { TranslationMock } from '../assets/translation.service.mock'; import { UploadServiceMock } from '../assets/upload.service.mock'; @@ -38,6 +38,7 @@ describe('AlfrescoUploadDragArea', () => { beforeEachProviders(() => { return [ { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock }, + { provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService }, { provide: AlfrescoTranslationService, useClass: TranslationMock }, { provide: UploadService, useClass: UploadServiceMock } ]; diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts index 217eaad045..5c23107a5b 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.spec.ts @@ -18,7 +18,7 @@ import { it, describe, inject, beforeEach, beforeEachProviders } from '@angular/core/testing'; import { UploadService } from './upload.service'; import { FileModel } from './../models/file.model'; -import { AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { AlfrescoSettingsServiceMock } from '../assets/AlfrescoSettingsService.service.mock'; import { AlfrescoApiMock } from '../assets/AlfrescoApi.mock'; @@ -30,8 +30,9 @@ let errorFn = jasmine.createSpy('error'); class MockUploadService extends UploadService { - constructor(settings: AlfrescoSettingsService) { - super(settings); + constructor(settings: AlfrescoSettingsService, + authService: AlfrescoAuthenticationService) { + super(settings, authService); } createXMLHttpRequestInstance() { @@ -66,6 +67,7 @@ describe('AlfrescoUploadService', () => { beforeEachProviders(() => { return [ { provide: AlfrescoSettingsService, useClass: AlfrescoSettingsServiceMock }, + { provide: AlfrescoAuthenticationService, useClass: AlfrescoAuthenticationService }, { provide: UploadService, useClass: MockUploadService } ]; }); diff --git a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts index 8a657d2ded..eeafbf4674 100644 --- a/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts +++ b/ng2-components/ng2-alfresco-upload/src/services/upload.service.ts @@ -20,7 +20,7 @@ import { EventEmitter, Injectable } from '@angular/core'; import { Response } from '@angular/http'; import { Observable } from 'rxjs/Observable'; import { Observer } from 'rxjs/Observer'; -import { AlfrescoSettingsService } from 'ng2-alfresco-core'; +import { AlfrescoSettingsService, AlfrescoAuthenticationService } from 'ng2-alfresco-core'; import { FileModel } from '../models/file.model'; declare let AlfrescoApi: any; @@ -50,7 +50,8 @@ export class UploadService { public totalCompleted: number = 0; - constructor(private settings: AlfrescoSettingsService) { + constructor(private settings: AlfrescoSettingsService, + private authService: AlfrescoAuthenticationService) { console.log('UploadService constructor'); this.filesUpload$ = new Observable(observer => this._filesUploadObserver = observer).share(); this.totalCompleted$ = new Observable(observer => this._totalCompletedObserver = observer).share(); @@ -92,20 +93,12 @@ export class UploadService { return this._formFields; } - /** - * Get the token from the local storage - * @returns {any} - */ - private getAlfrescoTicket(): string { - return localStorage.getItem('token'); - } - /** * Get the alfresco client * @returns {AlfrescoApi.ApiClient} */ private getAlfrescoClient() { - return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.getAlfrescoTicket()); + return AlfrescoApi.getClientWithTicket(this.settings.getApiBaseUrl(), this.authService.getToken()); } /**