Skip to content

Commit

Permalink
[AAE-12501] Align JS API (#8344)
Browse files Browse the repository at this point in the history
* [AAE-12501] Provide an AlfrescoApiService implementation that disable the AlfrescoApi oauth initialization when we use new oidc implementation

* [AAE-12501] Replace oauth2Auth with authentication service, define get username as abstract

* [AAE-12501] Replace sitesService with authentication service since sitesService get the username from oauth2Auth

* [AAE-12501] Call implicitLogin by authentication service

* [AAE-12501] Replace Oauth2Auth with AlfrescoApi and call the custom api without using authentication

* [AAE-12501] Replace oauth2Auth with authentication service to get the token

* [AAE-12501] Replace oauth2Auth with alfrescoApi

* remove unneeded JS-API dep
move auth in the right place

* [AAE-10501] Rename alfresco-api.http-client to adf-http-client

* [AAE-10501] Remove config from a CoreModule, a different service is provided in AuthModule to use angular http client instead of super agent

* [AAE-10501] Disable AlfrescoApi oauth initialization while using new adf oidc authentication

* [AAE-12501] Replace alfresco api client with AdfHttpClient

* [AAE-12501] Restore get username methods

* [AAE-12501] Get username with authentication service

* [AAE-12501] removee unused method

* [AAE-12501] Trigger on login when token is received

* [AAE-12501] Fix content-services unit test

* [AAE-12501] Fix import

* [AAE-12501] Fix core unit tests

* [AAE-12501] Fix process-services-cloud unit tests

* [AAE-12501] Create a request options interface with the needed props, remove the import from js-api, return the body from request

* [AAE-12501] Fix process-services-cloud unit tests without Expectation

* [AAE-12501] Fix Core secondary entrypoints unit tests are not executed: move test.ts one level up in order to find all the spec files into the secondary entrypoints folders and update path

* [AAE-12501] Fix Core unit tests that weren't executed because of the previous test.ts wrong location

* [AAE-12501] Fix authentication token_issued subscription

* add emitters

* [AAE-12501] Replace Math.random() to fix hospot security issue, fix lint issues

* [AAE-12501] Install event-emitter dependency

* [AAE-12501] Comment temporary setCsrfToken because is not possible to import app config service from core due to circular dependencies

* [AAE-12501] Get disableCsrf from app config serviice when app configuration is loaded

* [AAE-12501] Fix license-header lint issue

* [AAE-14221] Regenerate lock file

* [AAE-14221] Fix sonarcloud issues

* [AAE-12501] Remove wrong character

* [AAE-12501] Regenerate lock file

* [AAE-12501] Fix BC: update alfresco api response error

---------

Co-authored-by: eromano <eugenioromano16@gmail.com>
  • Loading branch information
alep85 and eromano committed Jun 27, 2023
1 parent 037dce0 commit 7abebf0
Show file tree
Hide file tree
Showing 53 changed files with 5,470 additions and 10,453 deletions.
4 changes: 2 additions & 2 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@
"core": {
"projectType": "library",
"root": "lib/core",
"sourceRoot": "lib/core/src",
"sourceRoot": "lib/core",
"prefix": "adf",
"architect": {
"build": {
Expand All @@ -327,7 +327,7 @@
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "lib/core/src/test.ts",
"main": "lib/core/test.ts",
"tsConfig": "lib/core/tsconfig.spec.json",
"karmaConfig": "lib/core/karma.conf.js",
"sourceMap": true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import { ObjectDataTableAdapter, AuthenticationService } from '@alfresco/adf-cor
<li>Global i18n: {{ 'APP_LAYOUT.DATATABLE_LAZY' | translate }}</li>
<li>Local i18n (work in progress): {{ 'LAZY.TEXT' | translate }}</li>
<li>isLoggedIn: {{ isLoggedIn }}</li>
<li>ECM username: {{ username }}
</ul>
`
})
Expand All @@ -39,10 +38,6 @@ export class LazyLoadingComponent {
return this.auth.isLoggedIn();
}

get username(): string {
return this.auth.getEcmUsername();
}

constructor(private auth: AuthenticationService) {
this.data = new ObjectDataTableAdapter(
// data
Expand Down
6 changes: 1 addition & 5 deletions demo-shell/src/app/services/app-notifications.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,7 @@ export class AppNotificationsService {
) {
this.alfrescoApiService.alfrescoApiInitialized.subscribe(() => {
if (this.isProcessServicesEnabled() && this.notificationsEnabled) {
this.alfrescoApiService.getInstance().oauth2Auth.once('token_issued', () => {

this.authenticationService.once('token_received').subscribe(() => {
const deployedApps = this.appConfigService.get('alfresco-deployed-apps', []);
if (deployedApps?.length) {
deployedApps.forEach((app) => {
Expand All @@ -69,11 +68,8 @@ export class AppNotificationsService {
});
});
}

});

}

});
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { from, Observable, throwError, Subject } from 'rxjs';
import { catchError, map, switchMap, filter, take } from 'rxjs/operators';
import { RepositoryInfo, SystemPropertiesRepresentation } from '@alfresco/js-api';

import { BpmProductVersionModel, AlfrescoApiService, AuthenticationService } from '@alfresco/adf-core';
import { BpmProductVersionModel, AuthenticationService } from '@alfresco/adf-core';
import { ApiClientsService } from '@alfresco/adf-core/api';

@Injectable({
Expand All @@ -34,13 +34,12 @@ export class DiscoveryApiService {
ecmProductInfo$ = new Subject<RepositoryInfo>();

constructor(
private apiService: AlfrescoApiService,
private authenticationService: AuthenticationService,
private apiClientsService: ApiClientsService
) {
this.authenticationService.onLogin
.pipe(
filter(() => this.apiService.getInstance()?.isEcmLoggedIn()),
filter(() => this.authenticationService.isEcmLoggedIn()),
take(1),
switchMap(() => this.getEcmProductInfo())
)
Expand Down
12 changes: 2 additions & 10 deletions lib/content-services/src/lib/common/services/sites.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ export class SitesService {
return this._sitesApi;
}

constructor(private apiService: AlfrescoApiService, private logService: LogService) {
constructor(private apiService: AlfrescoApiService,
private logService: LogService) {
}

/**
Expand Down Expand Up @@ -140,15 +141,6 @@ export class SitesService {
return from(this.sitesApi.listSiteMemberships(siteId, opts));
}

/**
* Gets the username of the user currently logged into ACS.
*
* @returns Username string
*/
getEcmCurrentLoggedUserName(): string {
return this.apiService.getInstance().getEcmUsername();
}

/**
* Looks for a site inside the path of a Node and returns its guid if it finds one.
* (return an empty string if no site is found)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@

import { Injectable } from '@angular/core';
import { Node } from '@alfresco/js-api';
import { AlfrescoApiService } from '@alfresco/adf-core';
import { AuthenticationService } from '@alfresco/adf-core';
import moment, { Moment } from 'moment';

@Injectable({
providedIn: 'root'
})
export class LockService {

constructor(private alfrescoApiService: AlfrescoApiService) {
constructor(private authService: AuthenticationService) {
}

isLocked(node: Node): boolean {
Expand All @@ -34,7 +34,7 @@ export class LockService {
if (this.isReadOnlyLock(node)) {
isLocked = !this.isLockExpired(node);
} else if (this.isLockOwnerAllowed(node)) {
isLocked = this.alfrescoApiService.getInstance().getEcmUsername() !== node.properties['cm:lockOwner'].id;
isLocked = this.authService.getEcmUsername() !== node.properties['cm:lockOwner'].id;
if (this.isLockExpired(node)) {
isLocked = false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { DebugElement } from '@angular/core';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { By } from '@angular/platform-browser';
import { DropdownSitesComponent, Relations } from './sites-dropdown.component';
import { setupTestBed } from '@alfresco/adf-core';
import { AuthenticationService, setupTestBed } from '@alfresco/adf-core';
import { of } from 'rxjs';
import { getFakeSitePaging,
getFakeSitePagingNoMoreItems,
Expand Down Expand Up @@ -57,6 +57,7 @@ describe('DropdownSitesComponent', () => {
let debug: DebugElement;
let element: HTMLElement;
let siteService: SitesService;
let authService: AuthenticationService;

setupTestBed({
imports: [
Expand Down Expand Up @@ -293,10 +294,11 @@ describe('DropdownSitesComponent', () => {

beforeEach(() => {
component.relations = Relations.Members;
authService = TestBed.inject(AuthenticationService);
});

it('should show only sites which logged user is member of when member relation is set', (done) => {
spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test');
spyOn(authService, 'getEcmUsername').and.returnValue('test');

fixture.detectChanges();
fixture.whenStable().then(() => {
Expand All @@ -317,10 +319,11 @@ describe('DropdownSitesComponent', () => {
describe('No relations', () => {
beforeEach(() => {
component.relations = [];
authService = TestBed.inject(AuthenticationService);
});

it('should show all the sites if no relation is set', (done) => {
spyOn(siteService, 'getEcmCurrentLoggedUserName').and.returnValue('test');
spyOn(authService, 'getEcmUsername').and.returnValue('test');

fixture.detectChanges();
fixture.whenStable().then(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*/

import { Component, EventEmitter, Input, OnInit, Output, ViewEncapsulation } from '@angular/core';
import { LogService, InfiniteSelectScrollDirective } from '@alfresco/adf-core';
import { LogService, InfiniteSelectScrollDirective, AuthenticationService } from '@alfresco/adf-core';
import { SitePaging, SiteEntry } from '@alfresco/js-api';
import { MatSelectChange } from '@angular/material/select';
import {LiveAnnouncer} from '@angular/cdk/a11y';
Expand Down Expand Up @@ -81,7 +81,8 @@ export class DropdownSitesComponent implements OnInit {
selected: SiteEntry = null;
MY_FILES_VALUE = '-my-';

constructor(private sitesService: SitesService,
constructor(private authService: AuthenticationService,
private sitesService: SitesService,
private logService: LogService,
private liveAnnouncer: LiveAnnouncer,
private translateService: TranslateService) {
Expand Down Expand Up @@ -174,7 +175,7 @@ export class DropdownSitesComponent implements OnInit {
}

private filteredResultsByMember(sites: SitePaging): SitePaging {
const loggedUserName = this.sitesService.getEcmCurrentLoggedUserName();
const loggedUserName = this.authService.getEcmUsername();
sites.list.entries = sites.list.entries.filter((site) => this.isCurrentUserMember(site, loggedUserName));
return sites;
}
Expand Down
3 changes: 2 additions & 1 deletion lib/core/api/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export * from './lib/api-client.factory';
export * from './lib/api-clients.service';
export * from './lib/clients';
export * from './lib/types';
export * from './lib/alfresco-api/alfresco-api.http-client';
export * from './lib/adf-http-client.service';
export * from './lib/interfaces';
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ import { Emitters, RequestOptions, ResultListDataRepresentationTaskRepresentatio
import { HttpParams } from '@angular/common/http';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { TestBed } from '@angular/core/testing';
import { AlfrescoApiHttpClient } from './alfresco-api.http-client';
import { AlfrescoApiResponseError } from './alfresco-api.response-error';
import { AdfHttpClient } from './adf-http-client.service';
import { AlfrescoApiResponseError } from './alfresco-api/alfresco-api.response-error';

const securityOptions: SecurityOptions = {
authentications: {},
Expand Down Expand Up @@ -52,8 +52,8 @@ const mockResponse = {
]
};

describe('AlfrescoApiHttpClient', () => {
let angularHttpClient: AlfrescoApiHttpClient;
describe('AdfHttpClient', () => {
let angularHttpClient: AdfHttpClient;
let controller: HttpTestingController;

beforeEach(() => {
Expand All @@ -62,7 +62,7 @@ describe('AlfrescoApiHttpClient', () => {
HttpClientTestingModule
]
});
angularHttpClient = TestBed.inject(AlfrescoApiHttpClient);
angularHttpClient = TestBed.inject(AdfHttpClient);
controller = TestBed.inject(HttpTestingController);
});

Expand Down Expand Up @@ -90,7 +90,7 @@ describe('AlfrescoApiHttpClient', () => {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
expect(res.data![0].created instanceof Date).toBeTruthy();
done();
});
}).catch(error=> fail(error));

const req = controller.expectOne('http://example.com');
expect(req.request.method).toEqual('POST');
Expand All @@ -110,7 +110,7 @@ describe('AlfrescoApiHttpClient', () => {
angularHttpClient.request('http://example.com', options, securityOptions, emitters).then((res) => {
expect(res).toEqual(mockResponse);
done();
});
}).catch(error=> fail(error));

const req = controller.expectOne('http://example.com');
expect(req.request.method).toEqual('POST');
Expand Down Expand Up @@ -177,7 +177,9 @@ describe('AlfrescoApiHttpClient', () => {
returnType: null
};

angularHttpClient.request('http://example.com', requestOptions, securityOptions, emitters);
angularHttpClient.request('http://example.com', requestOptions, securityOptions, emitters).catch(error =>
fail(error)
);
const req = controller.expectOne('http://example.com?autoRename=true&include=allowableOperations');
expect(req.request.method).toEqual('POST');

Expand Down Expand Up @@ -232,9 +234,9 @@ describe('AlfrescoApiHttpClient', () => {

const errorResponse = new Blob();

angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch((res: AlfrescoApiResponseError) => {
expect(res.status).toBe(400);
expect(res.error.response.body instanceof Blob).toBeTruthy();
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch((err: AlfrescoApiResponseError) => {
expect(err.status).toBe(400);
expect(err.response.body instanceof Blob).toBeTruthy();
done();
});

Expand All @@ -257,7 +259,9 @@ describe('AlfrescoApiHttpClient', () => {
}
};

angularHttpClient.request('http://example.com/candidatebaseapp/query/v1/process-instances', options, securityOptions, emitters);
angularHttpClient.request('http://example.com/candidatebaseapp/query/v1/process-instances', options, securityOptions, emitters).catch(error =>
fail(error)
);

const req = controller.expectOne('http://example.com/candidatebaseapp/query/v1/process-instances?skipCount=0&status=RUNNING&status=SUSPENDED&sort=startDate%2CDESC');
expect(req.request.method).toEqual('POST');
Expand All @@ -274,7 +278,7 @@ describe('AlfrescoApiHttpClient', () => {
angularHttpClient.request('http://example.com', options, securityOptions, emitters).then((res) => {
expect(res).toEqual('');
done();
});
}).catch(error=> fail(error));

const req = controller.expectOne('http://example.com');

Expand All @@ -290,7 +294,9 @@ describe('AlfrescoApiHttpClient', () => {
}
};

angularHttpClient.request('http://example.com', options, securityOptions, emitters);
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch(error =>
fail(error)
);

const req = controller.expectOne('http://example.com?lastModifiedFrom=2022-08-17T00%3A00%3A00.000%2B02%3A00');

Expand All @@ -306,7 +312,9 @@ describe('AlfrescoApiHttpClient', () => {
}
};

angularHttpClient.request('http://example.com', options, securityOptions, emitters);
angularHttpClient.request('http://example.com', options, securityOptions, emitters).catch(error =>
fail(error)
);

const req = controller.expectOne('http://example.com?lastModifiedFrom=2022-08-17T00%3A00%3A00.000Z');

Expand Down
Loading

0 comments on commit 7abebf0

Please sign in to comment.