[ACS-6066] viewer special permissions playwright (#3453)

* [ACS-5923] sidenav and singleclick test

* [ACS-5923] remove protractor test and fix flaky test

* [ACS-5923] test fix

* [ACS-5639] fix exclude test  in viewer

* [ACS-5923] remove exclude test and fix test

* [ACS-6066] viewer special permissions playwright test

* [ACS-6066] viewer protractor test remove

* [ACS-6066] viewer failed test fix

* [ACS-5923] review changes added

* [ACS-5923] fix error in script
This commit is contained in:
Akash Rathod
2023-10-05 12:19:57 +02:00
committed by GitHub
parent 4059a3d219
commit f2d09e8b1a
30 changed files with 1515 additions and 39 deletions

View File

@@ -23,7 +23,7 @@
*/
import { ApiClientFactory } from './api-client-factory';
import { FavoriteEntry } from '@alfresco/js-api';
import { FavoriteEntry, FavoritePaging } from '@alfresco/js-api';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../utils';
@@ -38,7 +38,7 @@ export class FavoritesPageApi {
await classObj.apiService.setUpAcaBackend(userName, password);
return classObj;
}
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry | null> {
async addFavoriteById(nodeType: 'file' | 'folder' | 'site', id: string): Promise<FavoriteEntry> {
let guid = nodeType === 'site' ? (await this.apiService.sites.getSite(id)).entry.guid : id;
const data = {
target: {
@@ -50,25 +50,40 @@ export class FavoritesPageApi {
return await this.apiService.favorites.createFavorite('-me-', data);
}
private async getFavorites(username: string) {
async addFavoritesByIds(nodeType: 'file' | 'folder' | 'site', ids: string[]): Promise<FavoriteEntry[]> {
const favorites: FavoriteEntry[] = [];
try {
if (ids && ids.length > 0) {
for (const id of ids) {
const favorite = await this.addFavoriteById(nodeType, id);
favorites.push(favorite);
}
}
} catch (error) {
Logger.error(`FavoritesApi addFavoritesByIds : catch : `, error);
}
return favorites;
}
private async getFavorites(username: string): Promise<FavoritePaging> {
try {
return await this.apiService.favorites.listFavorites(username);
} catch (error) {
Logger.error(`FavoritesApi getFavorites : catch : `, error);
return null;
return new FavoritePaging;
}
}
async isFavorite(username: string, nodeId: string) {
async isFavorite(username: string, nodeId: string): Promise<boolean> {
try {
return JSON.stringify((await this.getFavorites(username)).list.entries).includes(nodeId);
} catch (error) {
Logger.error(`FavoritesApi isFavorite : catch : `, error);
return null;
return false;
}
}
async isFavoriteWithRetry(username: string, nodeId: string, data: { expect: boolean }) {
async isFavoriteWithRetry(username: string, nodeId: string, data: { expect: boolean }): Promise<boolean> {
let isFavorite = false;
try {
const favorite = async () => {
@@ -83,4 +98,30 @@ export class FavoritesPageApi {
} catch (error) {}
return isFavorite;
}
async getFavoritesTotalItems(username: string): Promise<number> {
try {
return (await this.apiService.favorites.listFavorites(username)).list.pagination.totalItems;
} catch (error) {
Logger.error(`FavoritesApi getFavoritesTotalItems : catch : `, error);
return -1;
}
}
async waitForApi(username: string, data: { expect: number }) {
try {
const favoriteFiles = async () => {
const totalItems = await this.getFavoritesTotalItems(username);
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return await Utils.retryCall(favoriteFiles);
} catch (error) {
Logger.error(`FavoritesApi waitForApi : catch : `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -26,7 +26,7 @@ import * as fs from 'fs';
import { ApiClientFactory } from './api-client-factory';
import { Utils } from '../utils';
import { ApiUtil, Logger } from '@alfresco/adf-testing';
import { NodeEntry } from '@alfresco/js-api';
import { NodeBodyCreate, NodeEntry, ResultSetPaging } from '@alfresco/js-api';
export class FileActionsApi {
private apiService: ApiClientFactory;
@@ -50,6 +50,27 @@ export class FileActionsApi {
});
}
async uploadFileWithRename(fileLocation: string, parentId: string = '-my-', newName: string, title: string = '', description: string = '') {
const file = fs.createReadStream(fileLocation);
const nodeProps = {
properties: {
'cm:title': title,
'cm:description': description
}
} as NodeBodyCreate;
const opts = {
name: newName,
nodeType: 'cm:content'
};
try {
return await this.apiService.upload.uploadFile(file, '', parentId, nodeProps, opts);
} catch (error) {
Logger.error(`${this.constructor.name} ${this.uploadFileWithRename.name}`, error);
}
}
async lockNodes(nodeIds: string[], lockType: string = 'ALLOW_OWNER_CHANGES') {
try {
for (const nodeId of nodeIds) {
@@ -111,7 +132,7 @@ export class FileActionsApi {
return isLocked;
}
private async queryNodesNames(searchTerm: string) {
private async queryNodesNames(searchTerm: string): Promise<ResultSetPaging> {
const data = {
query: {
query: `cm:name:\"${searchTerm}*\"`,
@@ -124,10 +145,11 @@ export class FileActionsApi {
return this.apiService.search.search(data);
} catch (error) {
Logger.error(`SearchApi queryNodesNames : catch : `, error);
return null;
return new ResultSetPaging;
}
}
async waitForNodes(searchTerm: string, data: { expect: number }) {
async waitForNodes(searchTerm: string, data: { expect: number }): Promise<void> {
const predicate = (totalItems: number) => totalItems === data.expect;
const apiCall = async () => {

View File

@@ -31,3 +31,4 @@ export * from './people-api-models';
export * from './nodes-api';
export * from './sites-api';
export * from './node-content-tree';
export * from './search-api';

View File

@@ -223,6 +223,27 @@ export class NodesApi {
}
}
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions,
locallySet: [
{
authorityId: username,
name: role
}
]
}
};
try {
return await this.apiService.nodes.updateNode(nodeId, data);
} catch (error) {
logger.error(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
return null;
}
}
async removeUserAccessOnSpaceTemplate(nodeName: string): Promise<NodeEntry> {
try {
const templatesRootFolderId = await this.getSpaceTemplatesFolderId();
@@ -295,5 +316,4 @@ export class NodesApi {
return null;
}
}
}

View File

@@ -0,0 +1,84 @@
/*!
* 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 { ApiClientFactory } from './api-client-factory';
import { Logger } from '@alfresco/adf-testing';
import { Utils } from '../utils';
import { ResultSetPaging } from '@alfresco/js-api';
export class SearchPageApi {
private apiService: ApiClientFactory;
constructor() {
this.apiService = new ApiClientFactory();
}
static async initialize(userName: string, password?: string): Promise<SearchPageApi> {
const classObj = new SearchPageApi();
await classObj.apiService.setUpAcaBackend(userName, password);
return classObj;
}
private async querySearchFiles(username: string): Promise<ResultSetPaging> {
const data = {
query: {
query: '*',
language: 'afts'
},
filterQueries: [
{ query: `cm:modified:[NOW/DAY-30DAYS TO NOW/DAY+1DAY]` },
{ query: `cm:modifier:${username} OR cm:creator:${username}` },
{ query: `TYPE:"content" AND -TYPE:"app:filelink" AND -TYPE:"fm:post"` }
]
};
try {
return this.apiService.search.search(data);
} catch (error) {
Logger.error(`SearchApi queryRecentFiles : catch : `, error);
return new ResultSetPaging;
}
}
async getTotalItems(username: string): Promise<number> {
return (await this.querySearchFiles(username)).list.pagination.totalItems;
}
async waitForApi(username: string, data: { expect: number }) {
try {
const searchFiles = async () => {
const totalItems = await this.getTotalItems(username);
if (totalItems !== data.expect) {
return Promise.reject(totalItems);
} else {
return Promise.resolve(totalItems);
}
};
return await Utils.retryCall(searchFiles);
} catch (error) {
Logger.error(`SearchApi waitForApi : catch : `);
Logger.error(`\tExpected: ${data.expect} items, but found ${error}`);
}
}
}

View File

@@ -22,8 +22,10 @@
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
import { logger } from '@alfresco/adf-cli/scripts/logger';
import { ApiClientFactory } from './api-client-factory';
import { SharedLinkEntry } from '@alfresco/js-api';
import { SharedLinkEntry, SharedLinkPaging } from '@alfresco/js-api';
import { Utils } from '../utils';
export class SharedLinksApi {
private apiService: ApiClientFactory;
@@ -48,4 +50,50 @@ export class SharedLinksApi {
return null;
}
}
async shareFilesByIds(ids: string[]): Promise<SharedLinkEntry[]> {
const sharedLinks: SharedLinkEntry[] = [];
try {
if (ids && ids.length > 0) {
for (const id of ids) {
const sharedLink = await this.shareFileById(id);
sharedLinks.push(sharedLink);
}
}
} catch (error) {
logger.error(`SharedLinksApi shareFilesByIds : catch : `, error);
}
return sharedLinks;
}
private async getSharedLinks(maxItems: number = 250): Promise<SharedLinkPaging> {
try {
const opts = {
maxItems
};
return await this.apiService.share.listSharedLinks(opts);
} catch (error) {
logger.error(`SharedLinksApi getSharedLinks : catch : `, error);
return new SharedLinkPaging;
}
}
async waitForFilesToBeShared(filesIds: string[]): Promise<void> {
try {
const sharedFile = async () => {
const sharedFiles = (await this.getSharedLinks()).list.entries.map((link) => link.entry.nodeId);
const foundItems = filesIds.every((id) => sharedFiles.includes(id));
if (foundItems) {
return Promise.resolve(foundItems);
} else {
return Promise.reject(foundItems);
}
};
return Utils.retryCall(sharedFile);
} catch (error) {
logger.error(`SharedLinksApi waitForFilesToBeShared : catch : ${error}`);
logger.error(`\tWait timeout reached waiting for files to be shared`);
}
}
}

View File

@@ -23,7 +23,7 @@
*/
import { ApiClientFactory } from './api-client-factory';
import { Site, SiteBodyCreate, SiteEntry } from '@alfresco/js-api';
import { Site, SiteBodyCreate, SiteEntry, SiteMemberEntry, SiteMembershipBodyCreate, SiteMembershipBodyUpdate } from '@alfresco/js-api';
import { logger } from '@alfresco/adf-cli/scripts/logger';
export class SitesApi {
@@ -63,20 +63,51 @@ export class SitesApi {
}
}
/**
/**
* 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);
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);
}
}
async updateSiteMember(siteId: string, userId: string, role: string): Promise<SiteMemberEntry> {
const siteRole = {
role: role
} as SiteMembershipBodyUpdate;
try {
return await this.apiService.sites.updateSiteMembership(siteId, userId, siteRole);
} catch (error) {
logger.error(`SitesApi updateSiteMember : catch : `, error);
return new SiteMemberEntry;
}
}
async addSiteMember(siteId: string, userId: string, role: string): Promise<SiteMemberEntry> {
const memberBody = {
id: userId,
role: role
} as SiteMembershipBodyCreate;
try {
return await this.apiService.sites.createSiteMembership(siteId, memberBody);
} catch (error) {
if (error.status === 409) {
return this.updateSiteMember(siteId, userId, role);
} else {
logger.error(`SitesApi addSiteMember : catch : `, error);
return new SiteMemberEntry;
}
}
}
}