[ACS-5992] refactor api wrappers (#3425)

* [ACS-5992] refactor api wrappers

* code review fixes

* review siteVisibility fix

* deleting configs from index

* updating breadcrumb preconditions
This commit is contained in:
Adam Zakrzewski 2023-09-11 10:55:44 +02:00 committed by GitHub
parent b086093c2f
commit 8f0e4dfc87
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
14 changed files with 260 additions and 244 deletions

View File

@ -23,12 +23,11 @@
*/ */
import { expect } from '@playwright/test'; import { expect } from '@playwright/test';
import { ApiClientFactory, getUserState, SITE_VISIBILITY, test, Utils } from '@alfresco/playwright-shared'; import { getUserState, test, Utils } from '@alfresco/playwright-shared';
import { Site } from '@alfresco/js-api';
test.use({ storageState: getUserState('hruser') }); test.use({ storageState: getUserState('hruser') });
test.describe('viewer action file', () => { test.describe('viewer action file', () => {
const apiClientFactory = new ApiClientFactory();
const parent = `parent-${Utils.random()}`; const parent = `parent-${Utils.random()}`;
let parentId: string; let parentId: string;
const subFolder1 = `subFolder1-${Utils.random()}`; const subFolder1 = `subFolder1-${Utils.random()}`;
@ -53,8 +52,6 @@ test.describe('viewer action file', () => {
const folder1Renamed = `renamed-${Utils.random()}`; const folder1Renamed = `renamed-${Utils.random()}`;
test.beforeAll(async ({ nodesApiAction, sitesApiAction }) => { test.beforeAll(async ({ nodesApiAction, sitesApiAction }) => {
await apiClientFactory.setUpAcaBackend('hruser');
const parentNode = await nodesApiAction.createFolder(parent); const parentNode = await nodesApiAction.createFolder(parent);
parentId = parentNode.entry.id; parentId = parentNode.entry.id;
subFolder1Id = (await nodesApiAction.createFolder(subFolder1, parentId)).entry.id; subFolder1Id = (await nodesApiAction.createFolder(subFolder1, parentId)).entry.id;
@ -64,7 +61,7 @@ test.describe('viewer action file', () => {
parent2Id = (await nodesApiAction.createFolder(parent2)).entry.id; parent2Id = (await nodesApiAction.createFolder(parent2)).entry.id;
folder1Id = (await nodesApiAction.createFolder(folder1, parent2Id)).entry.id; folder1Id = (await nodesApiAction.createFolder(folder1, parent2Id)).entry.id;
await sitesApiAction.createSite(siteName, SITE_VISIBILITY.PUBLIC); await sitesApiAction.createSite(siteName, Site.VisibilityEnum.PUBLIC);
const docLibId = await sitesApiAction.getDocLibId(siteName); const docLibId = await sitesApiAction.getDocLibId(siteName);
parentFromSiteId = (await nodesApiAction.createFolder(parentFromSite, docLibId)).entry.id; parentFromSiteId = (await nodesApiAction.createFolder(parentFromSite, docLibId)).entry.id;
subFolder1FromSiteId = (await nodesApiAction.createFolder(subFolder1FromSite, parentFromSiteId)).entry.id; subFolder1FromSiteId = (await nodesApiAction.createFolder(subFolder1FromSite, parentFromSiteId)).entry.id;
@ -72,8 +69,8 @@ test.describe('viewer action file', () => {
await nodesApiAction.createFile(fileName1FromSite, subFolder2FromSiteId); await nodesApiAction.createFile(fileName1FromSite, subFolder2FromSiteId);
}); });
test.afterAll(async () => { test.afterAll(async ({ nodesApiAction }) => {
await apiClientFactory.nodes.deleteNode(parentId, { permanent: true }); await nodesApiAction.deleteNodes([parentId], true);
}); });
test('[C260964] Personal Files breadcrumb main node', async ({ personalFiles }) => { test('[C260964] Personal Files breadcrumb main node', async ({ personalFiles }) => {

View File

@ -23,7 +23,7 @@
*/ */
import { expect } from '@playwright/test'; import { expect } from '@playwright/test';
import { ApiClientFactory, LoginPage, test, TEST_FILES, Utils } from '@alfresco/playwright-shared'; import { ApiClientFactory, FileActionsApi, LoginPage, NodesApi, SitesApi, test, TEST_FILES, Utils } from '@alfresco/playwright-shared';
import { SiteBodyCreate } from '@alfresco/js-api'; import { SiteBodyCreate } from '@alfresco/js-api';
import { Logger } from '@alfresco/adf-testing'; import { Logger } from '@alfresco/adf-testing';
@ -34,21 +34,22 @@ test.describe('from File Libraries', () => {
const destination = `destFL-${Utils.random()}`; const destination = `destFL-${Utils.random()}`;
let destinationId: string; let destinationId: string;
const xlsxLibraries = `xlsxFL-${Utils.random()}`; const xlsxLibraries = `xlsxFL-${Utils.random()}`;
let nodesApi: NodesApi;
let sitesApi: SitesApi;
let fileApi: FileActionsApi;
test.beforeAll(async ({ userActions }) => { test.beforeAll(async () => {
await apiClientFactory.setUpAcaBackend('admin'); await apiClientFactory.setUpAcaBackend('admin');
await apiClientFactory.createUser({ username }); await apiClientFactory.createUser({ username });
await userActions.setUpUserAcaBackend(username, username); nodesApi = await NodesApi.initialize(username, username);
sitesApi = await SitesApi.initialize(username, username);
fileApi = await FileActionsApi.initialize(username, username);
try { try {
await userActions.sitesApi.createSite({ await sitesApi.createSite(siteName, SiteBodyCreate.VisibilityEnum.PUBLIC);
id: siteName, const docLibId = await sitesApi.getDocLibId(siteName);
title: siteName, const node = await nodesApi.createFolder(destination);
visibility: SiteBodyCreate.VisibilityEnum.PUBLIC
});
const docLibId = (await userActions.sitesApi.listSiteContainers(siteName)).list.entries[0].entry.id;
const node = await userActions.nodesApi.createNode('-my-', { name: destination, nodeType: 'cm:folder', relativePath: '/' });
destinationId = node.entry.id; destinationId = node.entry.id;
await userActions.uploadFile(TEST_FILES.XLSX.path, xlsxLibraries, docLibId); await fileApi.uploadFile(TEST_FILES.XLSX.path, xlsxLibraries, docLibId);
} catch (error) { } catch (error) {
Logger.error(`beforeAll failed : ${error}`); Logger.error(`beforeAll failed : ${error}`);
} }
@ -65,11 +66,10 @@ test.describe('from File Libraries', () => {
); );
}); });
test.afterAll(async ({ userActions }) => { test.afterAll(async () => {
try { try {
await userActions.setUpUserAcaBackend(username, username); await sitesApi.deleteSites([siteName]);
await userActions.deleteSites([siteName]); await nodesApi.deleteNodes([destinationId]);
await userActions.deleteNodes([destinationId]);
} catch (error) { } catch (error) {
Logger.error(`afterAll failed : ${error}`); Logger.error(`afterAll failed : ${error}`);
} }

View File

@ -89,8 +89,8 @@ export class ApiClientFactory {
this.alfrescoApi = new AlfrescoApi(config); this.alfrescoApi = new AlfrescoApi(config);
} }
public async setUpAcaBackend(userProfile: keyof typeof users): Promise<AcaBackend> { public async setUpAcaBackend(userName: string, password?: string): Promise<AcaBackend> {
await this.login(userProfile); await this.login(userName, password);
this.sites = new SitesApi(this.alfrescoApi); this.sites = new SitesApi(this.alfrescoApi);
this.upload = new UploadApi(this.alfrescoApi); this.upload = new UploadApi(this.alfrescoApi);
@ -135,19 +135,17 @@ export class ApiClientFactory {
return response; return response;
} }
async login(userProfile: keyof typeof users) { async login(userName: string, password?: string) {
const userToLog = const predefinedUserKey = Object.keys(users).find((user) => user === userName || users[user].username === userName);
users[ const userToLog = predefinedUserKey ? users[predefinedUserKey] : undefined;
Object.keys(users)
.filter((user) => user.match(new RegExp(`^${userProfile.toString()}$`)))
.toString()
] || userProfile;
let e: any; let e: any;
const user = userToLog?.username ?? userName;
const userPassword = userToLog?.password ?? password;
try { try {
e = await this.alfrescoApi.login(userToLog.username, userToLog.password); e = await this.alfrescoApi.login(user, userPassword);
} catch (error) { } catch (error) {
logger.error(`[API Client Factory] Log in user ${userToLog.username} failed ${e}`); logger.error(`[API Client Factory] Log in user ${user} failed ${e}`);
throw error; throw error;
} }
} }

View File

@ -24,22 +24,20 @@
import { ApiClientFactory } from './api-client-factory'; import { ApiClientFactory } from './api-client-factory';
import { FavoriteEntry } from '@alfresco/js-api'; import { FavoriteEntry } from '@alfresco/js-api';
import { users } from '../base-config/global-variables';
export class FavoritesPageApi extends ApiClientFactory { export class FavoritesPageApi {
private apiService: ApiClientFactory; private apiService: ApiClientFactory;
constructor() { constructor() {
super();
this.apiService = new ApiClientFactory(); this.apiService = new ApiClientFactory();
} }
static async initialize(userProfile: keyof typeof users): Promise<FavoritesPageApi> { static async initialize(userName: string, password?: string): Promise<FavoritesPageApi> {
const classObj = new FavoritesPageApi(); const classObj = new FavoritesPageApi();
await classObj.apiService.setUpAcaBackend(userProfile); await classObj.apiService.setUpAcaBackend(userName, password);
return classObj; return classObj;
} }
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry | null> { async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry | null> {
let guid = nodeType === 'site' ? (await this.sites.getSite(id)).entry.guid : id; let guid = nodeType === 'site' ? (await this.apiService.sites.getSite(id)).entry.guid : id;
const data = { const data = {
target: { target: {
[nodeType]: { [nodeType]: {

View File

@ -24,21 +24,17 @@
import * as fs from 'fs'; import * as fs from 'fs';
import { ApiClientFactory } from './api-client-factory'; import { ApiClientFactory } from './api-client-factory';
import { users } from '../base-config/global-variables';
export class FileActionsApi extends ApiClientFactory { export class FileActionsApi {
private apiService: ApiClientFactory; private apiService: ApiClientFactory;
constructor() { constructor() {
super();
this.apiService = new ApiClientFactory(); this.apiService = new ApiClientFactory();
} }
static async initialize( static async initialize(userName: string, password?: string): Promise<FileActionsApi> {
userProfile: keyof typeof users
): Promise<FileActionsApi> {
const classObj = new FileActionsApi(); const classObj = new FileActionsApi();
await classObj.apiService.setUpAcaBackend(userProfile); await classObj.apiService.setUpAcaBackend(userName, password);
return classObj; return classObj;
} }

View File

@ -27,7 +27,7 @@ export * from './api-client-factory';
export * from './file-actions'; export * from './file-actions';
export * from './shared-links-api'; export * from './shared-links-api';
export * from './favorites-api'; export * from './favorites-api';
export * from './user-actions';
export * from './people-api-models'; export * from './people-api-models';
export * from './nodes-api'; export * from './nodes-api';
export * from './sites-api'; export * from './sites-api';
export * from './node-content-tree';

View File

@ -0,0 +1,90 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* 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 { NodeBodyCreate } from '@alfresco/js-api';
const NODE_TYPE_FILE = 'cm:content';
const NODE_TYPE_FOLDER = 'cm:folder';
const NODE_TITLE = 'cm:title';
const NODE_DESCRIPTION = 'cm:description';
export interface NodeContentTree {
name?: string;
files?: string[];
folders?: (string | NodeContentTree)[];
title?: string;
description?: string;
}
export function flattenNodeContentTree(content: NodeContentTree, relativePath: string = '/'): NodeBodyCreate[] {
const { name, files, folders, title, description } = content;
const aspectNames: string[] = ['cm:versionable'];
let data: NodeBodyCreate[] = [];
let properties: any;
properties = {
[NODE_TITLE]: title,
[NODE_DESCRIPTION]: description
};
if (name) {
data = data.concat([
{
nodeType: NODE_TYPE_FOLDER,
name,
relativePath,
properties
}
]);
relativePath = relativePath === '/' ? `/${name}` : `${relativePath}/${name}`;
}
if (folders) {
const foldersData: NodeBodyCreate[] = folders
.map((folder: string | NodeContentTree): NodeBodyCreate[] => {
const folderData: NodeContentTree = typeof folder === 'string' ? { name: folder } : folder;
return flattenNodeContentTree(folderData, relativePath);
})
.reduce((nodesData: NodeBodyCreate[], folderData: NodeBodyCreate[]) => nodesData.concat(folderData), []);
data = data.concat(foldersData);
}
if (files) {
const filesData: NodeBodyCreate[] = files.map(
(filename: string): NodeBodyCreate => ({
nodeType: NODE_TYPE_FILE,
name: filename,
relativePath,
aspectNames
})
);
data = data.concat(filesData);
}
return data;
}

View File

@ -23,20 +23,20 @@
*/ */
import { ApiClientFactory } from './api-client-factory'; import { ApiClientFactory } from './api-client-factory';
import { NodeEntry } from '@alfresco/js-api'; import { NodeChildAssociationPaging, NodeEntry } from '@alfresco/js-api';
import { users } from '../base-config/global-variables';
import { logger } from '@alfresco/adf-cli/scripts/logger'; import { logger } from '@alfresco/adf-cli/scripts/logger';
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
export class NodesApi extends ApiClientFactory { export class NodesApi {
private apiService: ApiClientFactory; private apiService: ApiClientFactory;
constructor() { constructor() {
super();
this.apiService = new ApiClientFactory(); this.apiService = new ApiClientFactory();
} }
static async initialize(userProfile: keyof typeof users): Promise<NodesApi> {
static async initialize(userName: string, password?: string): Promise<NodesApi> {
const classObj = new NodesApi(); const classObj = new NodesApi();
await classObj.apiService.setUpAcaBackend(userProfile); await classObj.apiService.setUpAcaBackend(userName, password);
return classObj; return classObj;
} }
@ -120,4 +120,98 @@ export class NodesApi extends ApiClientFactory {
return null; return null;
} }
} }
/**
* Delete multiple nodes.
* @param nodeIds The list of node IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteNodes(nodeIds: string[], permanent: boolean = true): Promise<any> {
try {
for (const nodeId of nodeIds) {
await this.apiService.nodes.deleteNode(nodeId, { permanent });
}
} catch (error) {
logger.error(`${this.constructor.name} ${this.deleteNodes.name}`, error);
}
}
async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') {
try {
for (const nodeId of nodeIds) {
await this.apiService.nodes.lockNode(nodeId, { type: lockType });
}
} catch (error) {
logger.error(`${this.constructor.name} ${this.lockNodes.name}`, error);
}
}
async createContent(content: NodeContentTree, relativePath: string = '/'): Promise<NodeEntry | any> {
try {
return await this.apiService.nodes.createNode('-my-', flattenNodeContentTree(content, relativePath) as any);
} catch (error) {
logger.error(`${this.constructor.name} ${this.createContent.name}`, error);
}
}
async getNodeIdFromParent(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
return children.find((elem) => elem.entry.name === name).entry.id || '';
} catch (error) {
logger.error(`${this.constructor.name} ${this.getNodeIdFromParent.name}`, error);
return '';
}
}
private async getNodeChildren(nodeId: string): Promise<NodeChildAssociationPaging | null> {
try {
const opts = {
include: ['properties']
};
return await this.apiService.nodes.listNodeChildren(nodeId, opts);
} catch (error) {
logger.error(`${this.constructor.name} ${this.getNodeChildren.name}`, error);
return null;
}
}
async deleteNodeById(id: string, permanent: boolean = true): Promise<void> {
try {
await this.apiService.nodes.deleteNode(id, { permanent });
} catch (error) {
logger.error(`${this.constructor.name} ${this.deleteNodeById.name}`, error);
}
}
async cleanupSpaceTemplatesItems(nodeNames: string[]): Promise<void> {
try {
const spaceTemplatesNodeId = await this.getSpaceTemplatesFolderId();
for (const nodeName of nodeNames) {
const nodeId = await this.getNodeIdFromParent(nodeName, spaceTemplatesNodeId);
await this.deleteNodeById(nodeId);
}
} catch (error) {
logger.error('Admin Actions - cleanupSpaceTemplatesFolder failed : ', error);
}
}
async getSpaceTemplatesFolderId(): Promise<string> {
try {
return this.getNodeIdFromParent('Space Templates', await this.getDataDictionaryId());
} catch (error) {
logger.error('Admin Actions - getSpaceTemplatesFolderId failed : ', error);
return '';
}
}
private async getDataDictionaryId(): Promise<string> {
try {
return this.getNodeIdFromParent('Data Dictionary', '-root-');
} catch (error) {
logger.error('Admin Actions - getDataDictionaryId failed : ', error);
return '';
}
}
} }

View File

@ -24,19 +24,17 @@
import { ApiClientFactory } from './api-client-factory'; import { ApiClientFactory } from './api-client-factory';
import { FavoritePaging, SharedLinkEntry } from '@alfresco/js-api'; import { FavoritePaging, SharedLinkEntry } from '@alfresco/js-api';
import { users } from '../base-config/global-variables';
import { logger } from '@alfresco/adf-cli/scripts/logger'; import { logger } from '@alfresco/adf-cli/scripts/logger';
export class SharedLinksApi extends ApiClientFactory { export class SharedLinksApi {
private apiService: ApiClientFactory; private apiService: ApiClientFactory;
constructor() { constructor() {
super();
this.apiService = new ApiClientFactory(); this.apiService = new ApiClientFactory();
} }
static async initialize(userProfile: keyof typeof users): Promise<SharedLinksApi> { static async initialize(userName: string, password?: string): Promise<SharedLinksApi> {
const classObj = new SharedLinksApi(); const classObj = new SharedLinksApi();
await classObj.apiService.setUpAcaBackend(userProfile); await classObj.apiService.setUpAcaBackend(userName, password);
return classObj; return classObj;
} }

View File

@ -23,28 +23,25 @@
*/ */
import { ApiClientFactory } from './api-client-factory'; import { ApiClientFactory } from './api-client-factory';
import { SiteBodyCreate, SiteEntry } from '@alfresco/js-api'; import { Site, SiteBodyCreate, SiteEntry } from '@alfresco/js-api';
import { users } from '../base-config/global-variables';
import { logger } from '@alfresco/adf-cli/scripts/logger'; import { logger } from '@alfresco/adf-cli/scripts/logger';
import { SITE_VISIBILITY } from '../utils/configs';
export class SitesApi extends ApiClientFactory { export class SitesApi {
private apiService: ApiClientFactory; private apiService: ApiClientFactory;
constructor() { constructor() {
super();
this.apiService = new ApiClientFactory(); this.apiService = new ApiClientFactory();
} }
static async initialize(userProfile: keyof typeof users): Promise<SitesApi> { static async initialize(userName: string, password?: string): Promise<SitesApi> {
const classObj = new SitesApi(); const classObj = new SitesApi();
await classObj.apiService.setUpAcaBackend(userProfile); await classObj.apiService.setUpAcaBackend(userName, password);
return classObj; return classObj;
} }
async createSite(title: string, visibility?: string, description?: string, siteId?: string): Promise<SiteEntry | null> { async createSite(title: string, visibility?: string, description?: string, siteId?: string): Promise<SiteEntry | null> {
const site = { const site = {
title, title,
visibility: visibility || SITE_VISIBILITY.PUBLIC, visibility: visibility || Site.VisibilityEnum.PUBLIC,
description: description, description: description,
id: siteId || title id: siteId || title
} as SiteBodyCreate; } as SiteBodyCreate;
@ -65,4 +62,21 @@ export class SitesApi extends ApiClientFactory {
return null; return null;
} }
} }
/**
* Delete multiple sites/libraries.
* @param siteIds The list of the site/library IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteSites(siteIds: string[], permanent: boolean = true) {
try {
if (siteIds && siteIds.length > 0) {
for (const siteId of siteIds) {
await this.apiService.sites.deleteSite(siteId, { permanent });
}
}
} catch (error) {
logger.error(`${this.constructor.name} ${this.deleteSites.name}`, error);
}
}
} }

View File

@ -1,134 +0,0 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* 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 * as fs from 'fs';
import { Logger } from '@alfresco/adf-testing';
import { AlfrescoApi, CommentsApi, NodesApi, TrashcanApi, SitesApi, SharedlinksApi, UploadApi } from '@alfresco/js-api';
const { BASE_URL } = process.env;
const config = {
authType: 'BASIC',
hostBpm: BASE_URL,
hostEcm: BASE_URL,
provider: 'ECM',
contextRoot: 'alfresco'
};
export class UserActions {
public alfrescoApi: AlfrescoApi;
public commentsApi: CommentsApi;
public nodesApi: NodesApi;
public trashCanApi: TrashcanApi;
public sitesApi: SitesApi;
public sharedLinksApi: SharedlinksApi;
public uploadApi: UploadApi;
protected username: string;
protected password: string;
constructor() {
this.alfrescoApi = new AlfrescoApi(config);
}
public async setUpUserAcaBackend(username: string, password: string): Promise<void> {
await this.loginUser(username, password );
this.commentsApi = new CommentsApi(this.alfrescoApi);
this.nodesApi = new NodesApi(this.alfrescoApi);
this.trashCanApi = new TrashcanApi(this.alfrescoApi);
this.sitesApi = new SitesApi(this.alfrescoApi);
this.sharedLinksApi = new SharedlinksApi(this.alfrescoApi);
this.uploadApi = new UploadApi(this.alfrescoApi);
}
public async loginUser(username: string, password: string): Promise<any> {
this.username = username || this.username;
this.password = password || this.password;
try {
return this.alfrescoApi.login(this.username, this.password);
} catch (error) {
Logger.error(`\n [User Actions] - login failed ${error} error :`);
}
}
async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') {
try {
for (const nodeId of nodeIds) {
await this.nodesApi.lockNode(nodeId, { type: lockType });
}
} catch (error) {
Logger.error(`\n [User Actions] - lockNodes failed ${error} error :`);
}
}
async uploadFile(fileLocation: string, fileName: string, parentFolderId: string): Promise<any> {
const file = fs.createReadStream(fileLocation);
return this.uploadApi.uploadFile(
file,
'',
parentFolderId,
null,
{
name: fileName,
nodeType: 'cm:content',
renditions: 'doclib'
}
);
}
/**
* Delete multiple sites/libraries.
* @param siteIds The list of the site/library IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteSites(siteIds: string[], permanent: boolean = true) {
try {
if (siteIds && siteIds.length > 0) {
for (const siteId of siteIds) {
await this.sitesApi.deleteSite(siteId, { permanent });
}
}
} catch (error) {
Logger.error(`\n [User Actions] - deleteSites failed error : ${error}`);
}
}
/**
* Delete multiple nodes.
* @param nodeIds The list of node IDs to delete.
* @param permanent Delete permanently, without moving to the trashcan? (default: true)
*/
async deleteNodes(nodeIds: string[], permanent: boolean = true): Promise<any> {
try {
for (const nodeId of nodeIds) {
await this.nodesApi.deleteNode(nodeId, { permanent });
}
} catch (error) {
Logger.error(`\n [User Actions] - deleteNodes failed error : ${error}`);
}
}
}

View File

@ -35,10 +35,10 @@ import {
FavoritesPage, FavoritesPage,
FavoritesPageApi, FavoritesPageApi,
TrashPage, TrashPage,
UserActions,
LoginPage, LoginPage,
NodesApi, NodesApi,
SitesApi SitesApi,
users
} from '../'; } from '../';
interface Pages { interface Pages {
@ -57,7 +57,6 @@ interface Api {
fileAction: FileActionsApi; fileAction: FileActionsApi;
shareAction: SharedLinksApi; shareAction: SharedLinksApi;
favoritesPageAction: FavoritesPageApi; favoritesPageAction: FavoritesPageApi;
userActions: UserActions;
nodesApiAction: NodesApi; nodesApiAction: NodesApi;
sitesApiAction: SitesApi; sitesApiAction: SitesApi;
} }
@ -89,29 +88,25 @@ export const test = base.extend<Pages & Api>({
}, },
// eslint-disable-next-line no-empty-pattern // eslint-disable-next-line no-empty-pattern
fileAction: async ({}, use) => { fileAction: async ({}, use) => {
await use(await FileActionsApi.initialize('hruser')); await use(await FileActionsApi.initialize(users.hruser.username));
}, },
// eslint-disable-next-line no-empty-pattern // eslint-disable-next-line no-empty-pattern
shareAction: async ({}, use) => { shareAction: async ({}, use) => {
await use(await SharedLinksApi.initialize('hruser')); await use(await SharedLinksApi.initialize(users.hruser.username));
}, },
// eslint-disable-next-line no-empty-pattern // eslint-disable-next-line no-empty-pattern
favoritesPageAction: async ({}, use) => { favoritesPageAction: async ({}, use) => {
await use(await FavoritesPageApi.initialize('hruser')); await use(await FavoritesPageApi.initialize(users.hruser.username));
},
// eslint-disable-next-line no-empty-pattern
userActions: async ({}, use) => {
await use(new UserActions());
}, },
// eslint-disable-next-line no-empty-pattern // eslint-disable-next-line no-empty-pattern
nodesApiAction: async ({}, use) => { nodesApiAction: async ({}, use) => {
await use(await NodesApi.initialize('hruser')); await use(await NodesApi.initialize(users.admin.username, users.admin.password));
}, },
// eslint-disable-next-line no-empty-pattern // eslint-disable-next-line no-empty-pattern
sitesApiAction: async ({}, use) => { sitesApiAction: async ({}, use) => {
await use(await SitesApi.initialize('hruser')); await use(await SitesApi.initialize(users.hruser.username));
}, },
myLibrariesPage: async ({ page }, use) => { myLibrariesPage: async ({ page }, use) => {
await use(new MyLibrariesPage(page)); await use(new MyLibrariesPage(page));
} },
}); });

View File

@ -1,29 +0,0 @@
/*!
* Copyright © 2005-2023 Hyland Software, Inc. and its affiliates. All rights reserved.
*
* Alfresco Example Content Application
*
* 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/>.
*/
export const SITE_VISIBILITY = {
PUBLIC: 'PUBLIC',
MODERATED: 'MODERATED',
PRIVATE: 'PRIVATE'
};

View File

@ -29,4 +29,3 @@ export * from './state-helper';
export * from './folder-errors'; export * from './folder-errors';
export * from './utils'; export * from './utils';
export * from './library-errors'; export * from './library-errors';
export * from './configs';