[ACS-5678] create folder from template tests (#3456)

* [ACS-5678] create folder from template tests

* taking out only flag

* fixes for linter, import, method name and locator

* fix import and utils strings
This commit is contained in:
Adam Zakrzewski
2023-10-02 17:03:29 +02:00
committed by GitHub
parent 740b9b3579
commit 33c50bdd68
17 changed files with 665 additions and 13 deletions

View File

@@ -154,6 +154,15 @@ export class NodesApi {
}
}
async getNodeById(id: string): Promise<NodeEntry | null> {
try {
return await this.apiService.nodes.getNode(id);
} catch (error) {
logger.error(`${this.constructor.name} ${this.getNodeById.name}`, error);
return null;
}
}
async getNodeIdFromParent(name: string, parentId: string): Promise<string> {
try {
const children = (await this.getNodeChildren(parentId)).list.entries;
@@ -214,4 +223,77 @@ export class NodesApi {
}
}
async removeUserAccessOnSpaceTemplate(nodeName: string): Promise<NodeEntry> {
try {
const templatesRootFolderId = await this.getSpaceTemplatesFolderId();
const nodeId: string = await this.getNodeIdFromParent(nodeName, templatesRootFolderId);
return this.setInheritPermissions(nodeId, false);
} catch (error) {
logger.error('Admin Actions - removeUserAccessOnSpaceTemplate failed : ', error);
return null;
}
}
async setInheritPermissions(nodeId: string, inheritPermissions: boolean): Promise<NodeEntry | null> {
const data = {
permissions: {
isInheritanceEnabled: inheritPermissions
}
};
try {
return await this.apiService.nodes.updateNode(nodeId, data);
} catch (error) {
logger.error(`${this.constructor.name} ${this.setInheritPermissions.name}`, error);
return null;
}
}
private async addAspects(nodeId: string, aspectNames: string[]): Promise<NodeEntry> {
try {
return this.apiService.nodes.updateNode(nodeId, { aspectNames });
} catch (error) {
logger.error(`${this.constructor.name} ${this.addAspects.name}`, error);
return null;
}
}
async createFolderLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
const name = (await this.getNodeById(originalNodeId)).entry.name;
const nodeBody = {
name: `Link to ${name}.url`,
nodeType: 'app:folderlink',
properties: {
'cm:title': `Link to ${name}.url`,
'cm:destination': originalNodeId,
'cm:description': `Link to ${name}.url`,
'app:icon': 'space-icon-link'
}
};
try {
const link = await this.apiService.nodes.createNode(destinationId, nodeBody);
await this.addAspects(originalNodeId, ['app:linked']);
return link;
} catch (error) {
logger.error(`${this.constructor.name} ${this.createFolderLink.name}`, error);
return null;
}
}
async createLinkToFolderName(originalFolderName: string, originalFolderParentId: string, destinationParentId?: string): Promise<NodeEntry> {
if (!destinationParentId) {
destinationParentId = originalFolderParentId;
}
try {
const nodeId = await this.getNodeIdFromParent(originalFolderName, originalFolderParentId);
return this.createFolderLink(nodeId, destinationParentId);
} catch (error) {
logger.error('Admin Actions - createLinkToFolderName failed : ', error);
return null;
}
}
}