mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-24 17:31:52 +00:00
e2e api enhancements (part 1) (#1727)
* add typings, deprecate username wrapper * improve imports * unify admin actions for people * remove auth api wrapper * remove unused apis * remove unused apis * use admin api actions everywhere
This commit is contained in:
@@ -23,15 +23,20 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoClient, NodeContentTree } from './repo-client/repo-client';
|
||||
import { PersonEntry, NodeEntry } from '@alfresco/js-api';
|
||||
import { PersonModel } from './repo-client/apis/people/people-api-models';
|
||||
|
||||
import { SitesApi } from './repo-client/apis/sites/sites-api';
|
||||
import { UploadApi } from './repo-client/apis/upload/upload-api';
|
||||
import { NodesApi } from './repo-client/apis/nodes/nodes-api';
|
||||
import { FavoritesApi } from './repo-client/apis/favorites/favorites-api';
|
||||
import { SearchApi } from './repo-client/apis/search/search-api';
|
||||
import { RepoClient } from './repo-client/repo-client';
|
||||
import { PersonEntry, NodeEntry, PeopleApi } from '@alfresco/js-api';
|
||||
import {
|
||||
PersonModel,
|
||||
SitesApi,
|
||||
UploadApi,
|
||||
NodesApi,
|
||||
FavoritesApi,
|
||||
SearchApi,
|
||||
NodeContentTree,
|
||||
Person,
|
||||
SharedLinksApi,
|
||||
TrashcanApi
|
||||
} from './repo-client/apis';
|
||||
|
||||
export class AdminActions {
|
||||
private adminApi: RepoClient;
|
||||
@@ -45,6 +50,8 @@ export class AdminActions {
|
||||
nodes: NodesApi = new NodesApi();
|
||||
favorites: FavoritesApi = new FavoritesApi();
|
||||
search: SearchApi = new SearchApi();
|
||||
shared: SharedLinksApi = new SharedLinksApi();
|
||||
trashcan: TrashcanApi = new TrashcanApi();
|
||||
|
||||
async getDataDictionaryId(): Promise<string> {
|
||||
return this.adminApi.nodes.getNodeIdFromParent('Data Dictionary', '-root-');
|
||||
@@ -59,7 +66,25 @@ export class AdminActions {
|
||||
}
|
||||
|
||||
async createUser(user: PersonModel): Promise<PersonEntry> {
|
||||
return this.adminApi.people.createUser(user);
|
||||
const person = new Person(user);
|
||||
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
|
||||
|
||||
await this.adminApi.apiAuth();
|
||||
return peopleApi.createPerson(person);
|
||||
}
|
||||
|
||||
async disableUser(username: string): Promise<PersonEntry> {
|
||||
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
|
||||
|
||||
await this.adminApi.apiAuth();
|
||||
return peopleApi.updatePerson(username, { enabled: false });
|
||||
}
|
||||
|
||||
async changePassword(username: string, newPassword: string): Promise<PersonEntry> {
|
||||
const peopleApi = new PeopleApi(this.adminApi.alfrescoApi);
|
||||
|
||||
await this.adminApi.apiAuth();
|
||||
return peopleApi.updatePerson(username, { password: newPassword });
|
||||
}
|
||||
|
||||
async createNodeTemplate(name: string, title: string = '', description: string = '', author: string = ''): Promise<NodeEntry> {
|
||||
|
@@ -1,41 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { RepoApi } from '../repo-api';
|
||||
|
||||
export class AuthenticationApi extends RepoApi {
|
||||
constructor(username?: string, password?: string) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async logout() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
await this.alfrescoJsApi.logout();
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.logout.name}`, error);
|
||||
}
|
||||
}
|
||||
}
|
@@ -33,16 +33,6 @@ export class CommentsApi extends RepoApi {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async getNodeComments(nodeId: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.commentsApi.listComments(nodeId);
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeComments.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addComment(nodeId: string, comment: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
@@ -52,14 +42,4 @@ export class CommentsApi extends RepoApi {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async addComments(nodeId: string, comment: any) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.commentsApi.createComment(nodeId, comment);
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.addComments.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ export class FavoritesApi extends RepoApi {
|
||||
async getFavorites() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.favoritesApi.listFavorites(this.getUsername());
|
||||
return await this.favoritesApi.listFavorites(this.username);
|
||||
} catch (error) {
|
||||
this.handleError(`FavoritesApi getFavorites : catch : `, error);
|
||||
return null;
|
||||
@@ -101,7 +101,7 @@ export class FavoritesApi extends RepoApi {
|
||||
async getFavoritesTotalItems(): Promise<number> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return (await this.favoritesApi.listFavorites(this.getUsername())).list.pagination.totalItems;
|
||||
return (await this.favoritesApi.listFavorites(this.username)).list.pagination.totalItems;
|
||||
} catch (error) {
|
||||
this.handleError(`FavoritesApi getFavoritesTotalItems : catch : `, error);
|
||||
return -1;
|
||||
|
@@ -23,14 +23,12 @@
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
export * from './authentication/authentication-api';
|
||||
export * from './comments/comments-api';
|
||||
export * from './favorites/favorites-api';
|
||||
export * from './nodes/node-body-create';
|
||||
export * from './nodes/node-content-tree';
|
||||
export * from './nodes/nodes-api';
|
||||
export * from './people/people-api-models';
|
||||
export * from './people/people-api';
|
||||
export * from './queries/queries-api';
|
||||
export * from './search/search-api';
|
||||
export * from './shared-links/shared-links-api';
|
||||
|
@@ -1,85 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Alfresco Example Content Application
|
||||
*
|
||||
* Copyright (C) 2005 - 2020 Alfresco Software Limited
|
||||
*
|
||||
* This file is part of the Alfresco Example Content Application.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* The Alfresco Example Content Application is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* The Alfresco Example Content Application is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public License
|
||||
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { PersonModel, Person } from './people-api-models';
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { PeopleApi as AdfPeopleApi } from '@alfresco/js-api';
|
||||
|
||||
export class PeopleApi extends RepoApi {
|
||||
peopleApi = new AdfPeopleApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?: string, password?: string) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
async createUser(user: PersonModel) {
|
||||
try {
|
||||
const person = new Person(user);
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.createPerson(person);
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.createUser.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async getUser(username: string) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.peopleApi.getPerson(username);
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.getUser.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async updateUser(username: string, userDetails?: PersonModel) {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return this.peopleApi.updatePerson(username, userDetails);
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.updateUser.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async disableUser(username: string) {
|
||||
try {
|
||||
return await this.updateUser(username, { enabled: false });
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.disableUser.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async changePassword(username: string, newPassword: string) {
|
||||
try {
|
||||
return await this.updateUser(username, { password: newPassword });
|
||||
} catch (error) {
|
||||
this.handleError(`${this.constructor.name} ${this.changePassword.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@@ -30,7 +30,7 @@ import { Logger } from '@alfresco/adf-testing';
|
||||
export abstract class RepoApi {
|
||||
alfrescoJsApi = new AlfrescoApi();
|
||||
|
||||
protected constructor(private username: string = browser.params.ADMIN_USERNAME, private password: string = browser.params.ADMIN_PASSWORD) {
|
||||
protected constructor(public username: string = browser.params.ADMIN_USERNAME, private password: string = browser.params.ADMIN_PASSWORD) {
|
||||
this.alfrescoJsApi.setConfig(browser.params.config);
|
||||
}
|
||||
|
||||
@@ -38,10 +38,6 @@ export abstract class RepoApi {
|
||||
return this.alfrescoJsApi.login(this.username, this.password);
|
||||
}
|
||||
|
||||
getUsername(): string {
|
||||
return this.username;
|
||||
}
|
||||
|
||||
protected handleError(message: string, response: any) {
|
||||
Logger.error(`\n--- ${message} error :`);
|
||||
Logger.error('\t>>> username: ', this.username);
|
||||
|
@@ -57,7 +57,7 @@ export class SitesApi extends RepoApi {
|
||||
async getSites() {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.sitesApi.listSiteMembershipsForPerson(this.getUsername());
|
||||
return await this.sitesApi.listSiteMembershipsForPerson(this.username);
|
||||
} catch (error) {
|
||||
this.handleError(`SitesApi getSites : catch : `, error);
|
||||
return null;
|
||||
@@ -67,7 +67,7 @@ export class SitesApi extends RepoApi {
|
||||
async getSitesTotalItems(): Promise<number> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return (await this.sitesApi.listSiteMembershipsForPerson(this.getUsername())).list.pagination.totalItems;
|
||||
return (await this.sitesApi.listSiteMembershipsForPerson(this.username)).list.pagination.totalItems;
|
||||
} catch (error) {
|
||||
this.handleError(`SitesApi getSitesTotalItems : catch : `, error);
|
||||
return -1;
|
||||
|
@@ -24,71 +24,59 @@
|
||||
*/
|
||||
|
||||
import { browser } from 'protractor';
|
||||
import { PeopleApi } from './apis/people/people-api';
|
||||
import { NodesApi } from './apis/nodes/nodes-api';
|
||||
import { CommentsApi } from './apis/comments/comments-api';
|
||||
import { SitesApi } from './apis/sites/sites-api';
|
||||
import { FavoritesApi } from './apis/favorites/favorites-api';
|
||||
import { QueriesApi } from './apis/queries/queries-api';
|
||||
import { SharedLinksApi } from './apis/shared-links/shared-links-api';
|
||||
import { TrashcanApi } from './apis/trashcan/trashcan-api';
|
||||
import { SearchApi } from './apis/search/search-api';
|
||||
import { UploadApi } from './apis/upload/upload-api';
|
||||
import { AuthenticationApi } from './apis/authentication/authentication-api';
|
||||
import { NodesApi, CommentsApi, SitesApi, FavoritesApi, QueriesApi, SharedLinksApi, TrashcanApi, SearchApi, UploadApi } from './apis';
|
||||
import { AlfrescoApi } from '@alfresco/js-api';
|
||||
|
||||
export class RepoClient {
|
||||
constructor(private username: string = browser.params.ADMIN_USERNAME, private password: string = browser.params.ADMIN_PASSWORD) {}
|
||||
alfrescoApi: AlfrescoApi;
|
||||
|
||||
private get auth() {
|
||||
const { username, password } = this;
|
||||
return { username, password };
|
||||
constructor(private username: string = browser.params.ADMIN_USERNAME, private password: string = browser.params.ADMIN_PASSWORD) {
|
||||
this.alfrescoApi = new AlfrescoApi();
|
||||
this.alfrescoApi.setConfig(browser.params.config);
|
||||
}
|
||||
|
||||
get people() {
|
||||
return new PeopleApi(this.auth.username, this.auth.password);
|
||||
apiAuth(): Promise<any> {
|
||||
return this.alfrescoApi.login(this.username, this.password);
|
||||
}
|
||||
|
||||
get nodes() {
|
||||
return new NodesApi(this.auth.username, this.auth.password);
|
||||
get nodes(): NodesApi {
|
||||
return new NodesApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get comments() {
|
||||
return new CommentsApi(this.auth.username, this.auth.password);
|
||||
get comments(): CommentsApi {
|
||||
return new CommentsApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get sites() {
|
||||
return new SitesApi(this.auth.username, this.auth.password);
|
||||
get sites(): SitesApi {
|
||||
return new SitesApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get favorites() {
|
||||
return new FavoritesApi(this.auth.username, this.auth.password);
|
||||
get favorites(): FavoritesApi {
|
||||
return new FavoritesApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get shared() {
|
||||
return new SharedLinksApi(this.auth.username, this.auth.password);
|
||||
get shared(): SharedLinksApi {
|
||||
return new SharedLinksApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get trashcan() {
|
||||
return new TrashcanApi(this.auth.username, this.auth.password);
|
||||
get trashcan(): TrashcanApi {
|
||||
return new TrashcanApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get search() {
|
||||
return new SearchApi(this.auth.username, this.auth.password);
|
||||
get search(): SearchApi {
|
||||
return new SearchApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get queries() {
|
||||
return new QueriesApi(this.auth.username, this.auth.password);
|
||||
get queries(): QueriesApi {
|
||||
return new QueriesApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get upload() {
|
||||
return new UploadApi(this.auth.username, this.auth.password);
|
||||
get upload(): UploadApi {
|
||||
return new UploadApi(this.username, this.password);
|
||||
}
|
||||
|
||||
get authentication() {
|
||||
return new AuthenticationApi(this.auth.username, this.auth.password);
|
||||
async logout(): Promise<any> {
|
||||
await this.apiAuth();
|
||||
return this.alfrescoApi.logout();
|
||||
}
|
||||
}
|
||||
|
||||
export * from './apis/nodes/node-body-create';
|
||||
export * from './apis/nodes/node-content-tree';
|
||||
export * from './apis/nodes/nodes-api';
|
||||
|
Reference in New Issue
Block a user