mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-19 17:14:57 +00:00
rename two times service class just once
move responsability providers configurration in setting service refactoring
This commit is contained in:
parent
560bef7c1d
commit
dc19e45e7b
@ -126,6 +126,9 @@ class MyDemoApp {
|
|||||||
|
|
||||||
constructor(public alfrescoAuthenticationService: AlfrescoAuthenticationService,
|
constructor(public alfrescoAuthenticationService: AlfrescoAuthenticationService,
|
||||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
private alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
|
|
||||||
|
alfrescoSettingsService.ecmHost = this.ecmHost;
|
||||||
|
alfrescoSettingsService.setProviders('ECM');
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnInit() {
|
ngOnInit() {
|
||||||
@ -133,7 +136,7 @@ class MyDemoApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.alfrescoAuthenticationService.login('admin', 'admin', 'ECM').subscribe(
|
this.alfrescoAuthenticationService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
this.token = token.ticket;
|
this.token = token.ticket;
|
||||||
this.authenticated = true;
|
this.authenticated = true;
|
||||||
|
@ -17,15 +17,15 @@
|
|||||||
|
|
||||||
import {it, describe} from '@angular/core/testing';
|
import {it, describe} from '@angular/core/testing';
|
||||||
import {ReflectiveInjector, provide} from '@angular/core';
|
import {ReflectiveInjector, provide} from '@angular/core';
|
||||||
import {AlfrescoSettingsService} from './AlfrescoSettingsService.service';
|
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
|
||||||
import {AlfrescoAuthenticationService} from './AlfrescoAuthenticationService.service';
|
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
|
||||||
import {XHRBackend, HTTP_PROVIDERS} from '@angular/http';
|
import {XHRBackend, HTTP_PROVIDERS} from '@angular/http';
|
||||||
import {MockBackend} from '@angular/http/testing';
|
import {MockBackend} from '@angular/http/testing';
|
||||||
|
|
||||||
declare var AlfrescoApi: any;
|
declare var AlfrescoApi: any;
|
||||||
|
|
||||||
describe('AlfrescoAuthentication', () => {
|
describe('AlfrescoAuthentication', () => {
|
||||||
let injector, fakePromiseECM, fakePromiseBPM, service, fakePromiseBPMECM;
|
let injector, fakePromiseECM, fakePromiseBPM, authService, fakePromiseBPMECM;
|
||||||
|
|
||||||
fakePromiseECM = new Promise(function (resolve, reject) {
|
fakePromiseECM = new Promise(function (resolve, reject) {
|
||||||
resolve(
|
resolve(
|
||||||
@ -90,16 +90,15 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
describe('when the setting is ECM', () => {
|
describe('when the setting is ECM', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
this.providers = 'ECM';
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
service = injector.get(AlfrescoAuthenticationService);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return an ECM ticket after the login done', (done) => {
|
it('should return an ECM ticket after the login done', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM);
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
expect(service.isLoggedIn()).toBe(true);
|
expect(authService.isLoggedIn()).toBe(true);
|
||||||
expect(service.getTicket()).toEqual('fake-post-ticket-ECM');
|
expect(authService.getTicket()).toEqual('fake-post-ticket-ECM');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -108,12 +107,12 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin')
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin')
|
||||||
.and.returnValue(Promise.reject('fake invalid credentials'));
|
.and.returnValue(Promise.reject('fake invalid credentials'));
|
||||||
|
|
||||||
service.login('fake-wrong-username', 'fake-wrong-password', this.providers).subscribe(
|
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(service.getTicket()).toBeUndefined();
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -121,8 +120,7 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
it('should login in the ECM if no provider are defined calling the login', (done) => {
|
it('should login in the ECM if no provider are defined calling the login', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseECM);
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password').subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
service.TYPE = 'ECM';
|
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -131,9 +129,9 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
|
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM);
|
||||||
|
|
||||||
service.logout().subscribe(() => {
|
authService.logout().subscribe(() => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(service.getTicket()).toBeUndefined();
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
|
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -141,35 +139,38 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
|
|
||||||
it('should logout only if the provider is already logged in', (done) => {
|
it('should logout only if the provider is already logged in', (done) => {
|
||||||
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
|
localStorage.setItem('ticket-ECM', 'fake-post-ticket-ECM');
|
||||||
|
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseECM);
|
||||||
service.saveTicket('fake-ticket-ECM');
|
|
||||||
service.logout().subscribe(() => {
|
authService.saveTicket('fake-ticket-ECM');
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
|
||||||
expect(service.getTicket()).toBeUndefined();
|
authService.logout().subscribe(() => {
|
||||||
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
|
expect(localStorage.getItem('ticket-ECM')).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return false if the user is not logged in', () => {
|
it('should return false if the user is not logged in', () => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('when the setting is BPM', () => {
|
describe('when the setting is BPM', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
this.providers = 'BPM';
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
service = injector.get(AlfrescoAuthenticationService);
|
authService.providers = 'BPM';
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
it('should return an BPM ticket after the login done', (done) => {
|
it('should return an BPM ticket after the login done', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM);
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
expect(service.isLoggedIn()).toBe(true);
|
expect(authService.isLoggedIn()).toBe(true);
|
||||||
expect(service.getTicket()).toEqual('fake-post-ticket-BPM');
|
expect(authService.getTicket()).toEqual('fake-post-ticket-BPM');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -177,12 +178,12 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
it('should return ticket undefined when the credentials are wrong', (done) => {
|
it('should return ticket undefined when the credentials are wrong', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials'));
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials'));
|
||||||
|
|
||||||
service.login('fake-wrong-username', 'fake-wrong-password', this.providers).subscribe(
|
authService.login('fake-wrong-username', 'fake-wrong-password').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(service.getTicket()).toBeUndefined();
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -190,12 +191,12 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
it('should return a ticket undefined after logout', (done) => {
|
it('should return a ticket undefined after logout', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPM);
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseBPM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(fakePromiseBPM);
|
||||||
|
|
||||||
service.logout().subscribe(() => {
|
authService.logout().subscribe(() => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(service.getTicket()).toBeUndefined();
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
expect(localStorage.getItem('ticket-BPM')).toBeUndefined();
|
expect(localStorage.getItem('ticket-BPM')).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
@ -206,7 +207,7 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
|
localStorage.setItem('ticket-BPM', 'fake-post-ticket-BPM');
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(Promise.reject('fake logout error'));
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogout').and.returnValue(Promise.reject('fake logout error'));
|
||||||
|
|
||||||
service.logout().subscribe(
|
authService.logout().subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
@ -220,26 +221,16 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
describe('when the setting is both ECM and BPM ', () => {
|
describe('when the setting is both ECM and BPM ', () => {
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
this.providers = 'ALL';
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
service = injector.get(AlfrescoAuthenticationService);
|
authService.providers = 'ALL';
|
||||||
});
|
|
||||||
|
|
||||||
it('should create both instances', (done) => {
|
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM);
|
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(() => {
|
|
||||||
expect(service.isLoggedIn()).toBe(true);
|
|
||||||
expect(service.TYPE).toEqual(this.providers);
|
|
||||||
done();
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should return both ECM and BPM tickets after the login done', (done) => {
|
it('should return both ECM and BPM tickets after the login done', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM);
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM);
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(() => {
|
authService.login('fake-username', 'fake-password').subscribe(() => {
|
||||||
expect(service.isLoggedIn()).toBe(true);
|
expect(authService.isLoggedIn()).toBe(true);
|
||||||
expect(service.getTicket()).toEqual('fake-post-ticket-ECM,fake-post-ticket-BPM');
|
expect(authService.getTicket()).toEqual('fake-post-ticket-ECM,fake-post-ticket-BPM');
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@ -247,12 +238,12 @@ describe('AlfrescoAuthentication', () => {
|
|||||||
it('should return ticket undefined when the credentials are wrong', (done) => {
|
it('should return ticket undefined when the credentials are wrong', (done) => {
|
||||||
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials'));
|
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(Promise.reject('fake invalid credentials'));
|
||||||
|
|
||||||
service.login('fake-username', 'fake-password', this.providers).subscribe(
|
authService.login('fake-username', 'fake-password').subscribe(
|
||||||
(res) => {
|
(res) => {
|
||||||
},
|
},
|
||||||
(err: any) => {
|
(err: any) => {
|
||||||
expect(service.isLoggedIn()).toBe(false);
|
expect(authService.isLoggedIn()).toBe(false);
|
||||||
expect(service.getTicket()).toBeUndefined();
|
expect(authService.getTicket()).toBeUndefined();
|
||||||
done();
|
done();
|
||||||
});
|
});
|
||||||
});
|
});
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import {Injectable} from '@angular/core';
|
import {Injectable} from '@angular/core';
|
||||||
import {Observable} from 'rxjs/Rx';
|
import {Observable} from 'rxjs/Rx';
|
||||||
import {AlfrescoSettingsService} from './AlfrescoSettingsService.service';
|
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
|
||||||
|
|
||||||
declare let AlfrescoApi: any;
|
declare let AlfrescoApi: any;
|
||||||
|
|
||||||
@ -29,26 +29,11 @@ export class AlfrescoAuthenticationService {
|
|||||||
|
|
||||||
alfrescoApi: any;
|
alfrescoApi: any;
|
||||||
|
|
||||||
TYPE: string = 'ECM';
|
|
||||||
|
|
||||||
/**A
|
/**A
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param alfrescoSetting
|
* @param alfrescoSetting
|
||||||
*/
|
*/
|
||||||
constructor(public alfrescoSetting: AlfrescoSettingsService) {
|
constructor(public alfrescoSetting: AlfrescoSettingsService) {
|
||||||
|
|
||||||
if (!this.isLoggedIn()) {
|
|
||||||
this.alfrescoApi = new AlfrescoApi({
|
|
||||||
host: alfrescoSetting.ecmHost,
|
|
||||||
hostActiviti: alfrescoSetting.bpmHost
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
this.alfrescoApi = new AlfrescoApi({
|
|
||||||
ticket: this.getTicket(),
|
|
||||||
host: alfrescoSetting.ecmHost,
|
|
||||||
hostActiviti: alfrescoSetting.bpmHost
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -63,29 +48,43 @@ export class AlfrescoAuthenticationService {
|
|||||||
* Method to delegate to POST login
|
* Method to delegate to POST login
|
||||||
* @param username
|
* @param username
|
||||||
* @param password
|
* @param password
|
||||||
* @param provider
|
|
||||||
* @returns {Observable<R>|Observable<T>}
|
* @returns {Observable<R>|Observable<T>}
|
||||||
*/
|
*/
|
||||||
login(username: string, password: string, provider: string) {
|
login(username: string, password: string) {
|
||||||
|
|
||||||
this.TYPE = provider || this.TYPE;
|
if (this.isLoggedIn()) {
|
||||||
return Observable.fromPromise(this.callApiLogin(username, password, provider))
|
this.alfrescoApi = new AlfrescoApi({
|
||||||
.map((response: any) => {
|
provider: this.alfrescoSetting.getProviders(),
|
||||||
this.saveTicket(response);
|
ticket: this.getTicket(),
|
||||||
return {type: provider, ticket: response};
|
host: this.alfrescoSetting.ecmHost,
|
||||||
})
|
hostActiviti: this.alfrescoSetting.bpmHost
|
||||||
.catch(this.handleError);
|
});
|
||||||
|
|
||||||
|
return Observable.create((observer) => {
|
||||||
|
observer.next({type: this.alfrescoSetting.getProviders(), ticket: this.getTicket()});
|
||||||
|
observer.complete();
|
||||||
|
}).catch(this.handleError);
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return Observable.fromPromise(this.callApiLogin(username, password))
|
||||||
|
.map((response: any) => {
|
||||||
|
this.saveTicket(response);
|
||||||
|
return {type: this.alfrescoSetting.getProviders(), ticket: response};
|
||||||
|
})
|
||||||
|
.catch(this.handleError);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize the alfresco Api with user and password end call the login method
|
* Initialize the alfresco Api with user and password end call the login method
|
||||||
* @param username
|
* @param username
|
||||||
* @param password
|
* @param password
|
||||||
* @param provider
|
|
||||||
* @returns {*|Observable<any>}
|
* @returns {*|Observable<any>}
|
||||||
*/
|
*/
|
||||||
private callApiLogin(username: string, password: string, provider: string) {
|
private callApiLogin(username: string, password: string) {
|
||||||
|
|
||||||
this.alfrescoApi = new AlfrescoApi({
|
this.alfrescoApi = new AlfrescoApi({
|
||||||
|
provider: this.alfrescoSetting.getProviders(),
|
||||||
username: username,
|
username: username,
|
||||||
password: password,
|
password: password,
|
||||||
host: this.alfrescoSetting.ecmHost,
|
host: this.alfrescoSetting.ecmHost,
|
||||||
@ -114,7 +113,7 @@ export class AlfrescoAuthenticationService {
|
|||||||
* Remove the login ticket from localStorage
|
* Remove the login ticket from localStorage
|
||||||
*/
|
*/
|
||||||
public removeTicket(): void {
|
public removeTicket(): void {
|
||||||
localStorage.removeItem(`ticket-${this.TYPE}`);
|
localStorage.removeItem(`ticket-${this.alfrescoSetting.getProviders()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -122,16 +121,17 @@ export class AlfrescoAuthenticationService {
|
|||||||
* @returns {*|Observable<string>|Observable<any>|Promise<T>}
|
* @returns {*|Observable<string>|Observable<any>|Promise<T>}
|
||||||
*/
|
*/
|
||||||
private callApiLogout(): Promise<any> {
|
private callApiLogout(): Promise<any> {
|
||||||
return this.alfrescoApi.logout();
|
if (this.alfrescoApi) {
|
||||||
|
return this.alfrescoApi.logout();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The method return the ticket stored in the localStorage
|
* The method return the ticket stored in the localStorage
|
||||||
* @returns ticket
|
* @returns ticket
|
||||||
*/
|
*/
|
||||||
public getTicket(): string {
|
public getTicket(): string {
|
||||||
return localStorage.getItem(`ticket-${this.TYPE}`);
|
return localStorage.getItem(`ticket-${this.alfrescoSetting.getProviders()}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -140,7 +140,7 @@ export class AlfrescoAuthenticationService {
|
|||||||
*/
|
*/
|
||||||
public saveTicket(ticket): void {
|
public saveTicket(ticket): void {
|
||||||
if (ticket) {
|
if (ticket) {
|
||||||
localStorage.setItem(`ticket-${this.TYPE}`, ticket);
|
localStorage.setItem(`ticket-${this.alfrescoSetting.getProviders()}`, ticket);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -155,6 +155,6 @@ export class AlfrescoAuthenticationService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
getAlfrescoApi(): any {
|
getAlfrescoApi(): any {
|
||||||
return this.alfrescoApi;
|
return this.alfrescoApi;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
|
|
||||||
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
|
import { AlfrescoAuthenticationService } from './AlfrescoAuthentication.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class AlfrescoContentService {
|
export class AlfrescoContentService {
|
@ -0,0 +1,63 @@
|
|||||||
|
/*!
|
||||||
|
* @license
|
||||||
|
* Copyright 2016 Alfresco Software, Ltd.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
import {describe, it, beforeEach} from '@angular/core/testing';
|
||||||
|
import {ReflectiveInjector} from '@angular/core';
|
||||||
|
import {AlfrescoSettingsService} from './AlfrescoSettings.service';
|
||||||
|
import {AlfrescoAuthenticationService} from './AlfrescoAuthentication.service';
|
||||||
|
import {AlfrescoContentService} from './AlfrescoContent.service';
|
||||||
|
import {HTTP_PROVIDERS} from '@angular/http';
|
||||||
|
|
||||||
|
describe('AlfrescoContentService', () => {
|
||||||
|
|
||||||
|
let injector, contentService: AlfrescoContentService, authService: AlfrescoAuthenticationService, node;
|
||||||
|
|
||||||
|
const nodeId = 'fake-node-id';
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
injector = ReflectiveInjector.resolveAndCreate([
|
||||||
|
HTTP_PROVIDERS,
|
||||||
|
AlfrescoContentService,
|
||||||
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoSettingsService
|
||||||
|
]);
|
||||||
|
spyOn(localStorage, 'getItem').and.callFake(function (key) {
|
||||||
|
return 'myTicket';
|
||||||
|
});
|
||||||
|
|
||||||
|
contentService = injector.get(AlfrescoContentService);
|
||||||
|
authService = injector.get(AlfrescoAuthenticationService);
|
||||||
|
authService.login('fake-username', 'fake-password');
|
||||||
|
|
||||||
|
node = {
|
||||||
|
entry: {
|
||||||
|
id: nodeId
|
||||||
|
}
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a valid content URL', () => {
|
||||||
|
expect(contentService.getContentUrl(node)).toBe('http://127.0.0.1:8080/alfresco/api/' +
|
||||||
|
'-default-/public/alfresco/versions/1/nodes/fake-node-id/content?attachment=false&alf_ticket=myTicket');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return a valid thumbnail URL', () => {
|
||||||
|
expect(contentService.getDocumentThumbnailUrl(node))
|
||||||
|
.toBe('http://127.0.0.1:8080/alfresco/api/-default-/public/alfresco' +
|
||||||
|
'/versions/1/nodes/fake-node-id/renditions/doclib/content?attachment=false&alf_ticket=myTicket');
|
||||||
|
});
|
||||||
|
});
|
@ -1,69 +0,0 @@
|
|||||||
/*!
|
|
||||||
* @license
|
|
||||||
* Copyright 2016 Alfresco Software, Ltd.
|
|
||||||
*
|
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
||||||
* you may not use this file except in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing, software
|
|
||||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
* See the License for the specific language governing permissions and
|
|
||||||
* limitations under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import { describe, it, beforeEach } from '@angular/core/testing';
|
|
||||||
import { ReflectiveInjector } from '@angular/core';
|
|
||||||
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
|
|
||||||
import { AlfrescoAuthenticationService } from './AlfrescoAuthenticationService.service';
|
|
||||||
import { AlfrescoContentService } from './AlfrescoContentService.service';
|
|
||||||
import { HTTP_PROVIDERS } from '@angular/http';
|
|
||||||
|
|
||||||
describe('AlfrescoContentService', () => {
|
|
||||||
|
|
||||||
let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService;
|
|
||||||
const nodeId = 'blah';
|
|
||||||
let DEFAULT_CONTEXT_PATH: string = '/alfresco';
|
|
||||||
let DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1';
|
|
||||||
|
|
||||||
beforeEach(() => {
|
|
||||||
injector = ReflectiveInjector.resolveAndCreate([
|
|
||||||
HTTP_PROVIDERS,
|
|
||||||
AlfrescoContentService,
|
|
||||||
AlfrescoAuthenticationService,
|
|
||||||
AlfrescoSettingsService
|
|
||||||
]);
|
|
||||||
spyOn(localStorage, 'getItem').and.callFake(function (key) {
|
|
||||||
return 'myTicket';
|
|
||||||
});
|
|
||||||
service = injector.get(AlfrescoContentService);
|
|
||||||
authService = injector.get(AlfrescoAuthenticationService);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a valid content URL', () => {
|
|
||||||
expect(service.getContentUrl({
|
|
||||||
entry: {
|
|
||||||
id: nodeId
|
|
||||||
}
|
|
||||||
})).toBe(
|
|
||||||
AlfrescoSettingsService.DEFAULT_ECM_ADDRESS + DEFAULT_CONTEXT_PATH +
|
|
||||||
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
|
|
||||||
'?attachment=false&alf_ticket=' + authService.getTicket()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should return a valid thumbnail URL', () => {
|
|
||||||
expect(service.getDocumentThumbnailUrl({
|
|
||||||
entry: {
|
|
||||||
id: nodeId
|
|
||||||
}
|
|
||||||
})).toBe(
|
|
||||||
AlfrescoSettingsService.DEFAULT_ECM_ADDRESS + DEFAULT_CONTEXT_PATH +
|
|
||||||
DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
|
|
||||||
'?attachment=false&alf_ticket=' + authService.getTicket()
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
@ -17,7 +17,7 @@
|
|||||||
|
|
||||||
import { Injectable, ChangeDetectorRef, Pipe } from '@angular/core';
|
import { Injectable, ChangeDetectorRef, Pipe } from '@angular/core';
|
||||||
import { TranslatePipe } from 'ng2-translate/ng2-translate';
|
import { TranslatePipe } from 'ng2-translate/ng2-translate';
|
||||||
import { AlfrescoTranslationService } from './AlfrescoTranslationService.service';
|
import { AlfrescoTranslationService } from './AlfrescoTranslation.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@Pipe({
|
@Pipe({
|
||||||
|
@ -30,8 +30,8 @@ export class AlfrescoSettingsService {
|
|||||||
|
|
||||||
private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH;
|
private _bpmContextPath = AlfrescoSettingsService.DEFAULT_BPM_CONTEXT_PATH;
|
||||||
|
|
||||||
private providers: string[] = 'ALL';
|
private providers: string = 'ECM'; // ECM, BPM , ALL
|
||||||
|
|
||||||
public get ecmHost(): string {
|
public get ecmHost(): string {
|
||||||
return this._ecmHost;
|
return this._ecmHost;
|
||||||
}
|
}
|
||||||
@ -52,4 +52,12 @@ export class AlfrescoSettingsService {
|
|||||||
return this._bpmHost + this._bpmContextPath;
|
return this._bpmHost + this._bpmContextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public getProviders(): string {
|
||||||
|
return this.providers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public setProviders(providers: string) {
|
||||||
|
this.providers = providers;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
@ -16,7 +16,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { describe, it, beforeEach } from '@angular/core/testing';
|
import { describe, it, beforeEach } from '@angular/core/testing';
|
||||||
import { AlfrescoSettingsService } from './AlfrescoSettingsService.service';
|
import { AlfrescoSettingsService } from './AlfrescoSettings.service';
|
||||||
|
|
||||||
describe('AlfrescoSettingsService', () => {
|
describe('AlfrescoSettingsService', () => {
|
||||||
|
|
@ -15,9 +15,9 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
export * from './AlfrescoSettingsService.service';
|
export * from './AlfrescoSettings.service';
|
||||||
export * from './AlfrescoTranslationLoader.service';
|
export * from './AlfrescoTranslationLoader.service';
|
||||||
export * from './AlfrescoTranslationService.service';
|
export * from './AlfrescoTranslation.service';
|
||||||
export * from './AlfrescoPipeTranslate.service';
|
export * from './AlfrescoPipeTranslate.service';
|
||||||
export * from './AlfrescoAuthenticationService.service';
|
export * from './AlfrescoAuthentication.service';
|
||||||
export * from './AlfrescoContentService.service';
|
export * from './AlfrescoContent.service';
|
||||||
|
@ -189,7 +189,7 @@ class DocumentListDemo implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.authService.login('admin', 'admin', 'ECM').subscribe(
|
this.authService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
console.log(token);
|
console.log(token);
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -23,7 +23,7 @@ import {
|
|||||||
beforeEach,
|
beforeEach,
|
||||||
beforeEachProviders
|
beforeEachProviders
|
||||||
} from '@angular/core/testing';
|
} from '@angular/core/testing';
|
||||||
import { AlfrescoAuthenticationService } from 'ng2-alfresco-core';
|
import { AlfrescoAuthenticationService, AlfrescoSettingsService } from 'ng2-alfresco-core';
|
||||||
import { TestComponentBuilder } from '@angular/compiler/testing';
|
import { TestComponentBuilder } from '@angular/compiler/testing';
|
||||||
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
import { AlfrescoTranslationService } from 'ng2-alfresco-core';
|
||||||
import { AlfrescoLoginComponent } from './alfresco-login.component';
|
import { AlfrescoLoginComponent } from './alfresco-login.component';
|
||||||
@ -38,6 +38,7 @@ describe('AlfrescoLogin', () => {
|
|||||||
beforeEachProviders(() => {
|
beforeEachProviders(() => {
|
||||||
return [
|
return [
|
||||||
{ provide: AlfrescoAuthenticationService, useClass: AuthenticationMock },
|
{ provide: AlfrescoAuthenticationService, useClass: AuthenticationMock },
|
||||||
|
{ provide: AlfrescoSettingsService, useClass: AlfrescoSettingsService },
|
||||||
{ provide: AlfrescoTranslationService, useClass: TranslationMock }
|
{ provide: AlfrescoTranslationService, useClass: TranslationMock }
|
||||||
];
|
];
|
||||||
});
|
});
|
||||||
|
@ -15,12 +15,13 @@
|
|||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import { Component, Input, Output, EventEmitter } from '@angular/core';
|
import {Component, Input, Output, EventEmitter} from '@angular/core';
|
||||||
import { FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators } from '@angular/common';
|
import {FORM_DIRECTIVES, ControlGroup, FormBuilder, Validators} from '@angular/common';
|
||||||
import {
|
import {
|
||||||
AlfrescoTranslationService,
|
AlfrescoTranslationService,
|
||||||
AlfrescoPipeTranslate,
|
AlfrescoPipeTranslate,
|
||||||
AlfrescoAuthenticationService
|
AlfrescoAuthenticationService,
|
||||||
|
AlfrescoSettingsService
|
||||||
} from 'ng2-alfresco-core';
|
} from 'ng2-alfresco-core';
|
||||||
|
|
||||||
declare let componentHandler: any;
|
declare let componentHandler: any;
|
||||||
@ -67,11 +68,13 @@ export class AlfrescoLoginComponent {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
* @param _fb
|
* @param _fb
|
||||||
* @param auth
|
* @param authService
|
||||||
|
* @param settingService
|
||||||
* @param translate
|
* @param translate
|
||||||
*/
|
*/
|
||||||
constructor(private _fb: FormBuilder,
|
constructor(private _fb: FormBuilder,
|
||||||
public auth: AlfrescoAuthenticationService,
|
public authService: AlfrescoAuthenticationService,
|
||||||
|
public settingService: AlfrescoSettingsService,
|
||||||
private translate: AlfrescoTranslationService) {
|
private translate: AlfrescoTranslationService) {
|
||||||
|
|
||||||
this.formError = {
|
this.formError = {
|
||||||
@ -79,7 +82,7 @@ export class AlfrescoLoginComponent {
|
|||||||
'password': ''
|
'password': ''
|
||||||
};
|
};
|
||||||
|
|
||||||
this.form = this._fb.group({
|
this.form = this._fb.group({
|
||||||
username: ['', Validators.compose([Validators.required, Validators.minLength(4)])],
|
username: ['', Validators.compose([Validators.required, Validators.minLength(4)])],
|
||||||
password: ['', Validators.required]
|
password: ['', Validators.required]
|
||||||
});
|
});
|
||||||
@ -104,12 +107,15 @@ export class AlfrescoLoginComponent {
|
|||||||
* @param value
|
* @param value
|
||||||
* @param event
|
* @param event
|
||||||
*/
|
*/
|
||||||
onSubmit(value: any, event) {
|
onSubmit(value: any, event: any) {
|
||||||
this.error = false;
|
this.error = false;
|
||||||
if (event) {
|
if (event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
}
|
}
|
||||||
this.auth.login(value.username, value.password, this.providers)
|
|
||||||
|
this.settingService.setProviders(this.providers);
|
||||||
|
|
||||||
|
this.authService.login(value.username, value.password)
|
||||||
.subscribe(
|
.subscribe(
|
||||||
(token: any) => {
|
(token: any) => {
|
||||||
this.success = true;
|
this.success = true;
|
||||||
|
@ -81,7 +81,7 @@ class SearchDemo implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.authService.login('admin', 'admin', 'ECM').subscribe(
|
this.authService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
console.log(token);
|
console.log(token);
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -106,7 +106,7 @@ export class MyDemoApp implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.authService.login('admin', 'admin', 'ECM').subscribe(
|
this.authService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
console.log(token);
|
console.log(token);
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -79,7 +79,7 @@ class MyDemoApp {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.authService.login('admin', 'admin', 'ECM').subscribe(
|
this.authService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
console.log(token);
|
console.log(token);
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
@ -79,6 +79,8 @@ class WebscriptDemo implements OnInit {
|
|||||||
private alfrescoSettingsService: AlfrescoSettingsService) {
|
private alfrescoSettingsService: AlfrescoSettingsService) {
|
||||||
|
|
||||||
alfrescoSettingsService.ecmHost = this.ecmHost;
|
alfrescoSettingsService.ecmHost = this.ecmHost;
|
||||||
|
alfrescoSettingsService.setProviders('ECM');
|
||||||
|
|
||||||
if (this.authService.getTicket()) {
|
if (this.authService.getTicket()) {
|
||||||
this.token = this.authService.getTicket();
|
this.token = this.authService.getTicket();
|
||||||
}
|
}
|
||||||
@ -98,7 +100,7 @@ class WebscriptDemo implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
login() {
|
login() {
|
||||||
this.authService.login('admin', 'admin', ['ECM']).subscribe(
|
this.authService.login('admin', 'admin').subscribe(
|
||||||
token => {
|
token => {
|
||||||
console.log(token);
|
console.log(token);
|
||||||
this.token = token;
|
this.token = token;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user