mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2025-07-31 17:38:28 +00:00
Prettier upgrade and e2e type checks (#1522)
* upgrade prettier * noImplicitAny rule * fix type * update tsconfig * upgrade to 150 print width
This commit is contained in:
@@ -26,18 +26,13 @@
|
||||
import { RepoApi } from '../repo-api';
|
||||
import { NodeBodyCreate } from './node-body-create';
|
||||
import { NodeContentTree, flattenNodeContentTree } from './node-content-tree';
|
||||
import {
|
||||
NodesApi as AdfNodeApi,
|
||||
NodeBodyLock,
|
||||
NodeEntry,
|
||||
NodeChildAssociationPaging
|
||||
} from '@alfresco/js-api';
|
||||
import { NodesApi as AdfNodeApi, NodeBodyLock, NodeEntry, NodeChildAssociationPaging } from '@alfresco/js-api';
|
||||
import { Utils } from '../../../../utilities/utils';
|
||||
|
||||
export class NodesApi extends RepoApi {
|
||||
nodesApi = new AdfNodeApi(this.alfrescoJsApi);
|
||||
|
||||
constructor(username?, password?) {
|
||||
constructor(username?: string, password?: string) {
|
||||
super(username, password);
|
||||
}
|
||||
|
||||
@@ -46,10 +41,7 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNode('-my-', { relativePath });
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeByPath.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeByPath.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -60,10 +52,7 @@ export class NodesApi extends RepoApi {
|
||||
const node = await this.nodesApi.getNode(id);
|
||||
return node;
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeById.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeById.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -71,12 +60,9 @@ export class NodesApi extends RepoApi {
|
||||
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 || '';
|
||||
return children.find((elem) => elem.entry.name === name).entry.id || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeIdFromParent.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeIdFromParent.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -84,16 +70,9 @@ export class NodesApi extends RepoApi {
|
||||
async getNodeDescription(name: string, parentId: string): Promise<string> {
|
||||
try {
|
||||
const children = (await this.getNodeChildren(parentId)).list.entries;
|
||||
return (
|
||||
children.find(elem => elem.entry.name === name).entry.properties[
|
||||
'cm:description'
|
||||
] || ''
|
||||
);
|
||||
return children.find((elem) => elem.entry.name === name).entry.properties['cm:description'] || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeDescription.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeDescription.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -101,16 +80,9 @@ export class NodesApi extends RepoApi {
|
||||
async getNodeTitle(name: string, parentId: string): Promise<string> {
|
||||
try {
|
||||
const children = (await this.getNodeChildren(parentId)).list.entries;
|
||||
return (
|
||||
children.find(elem => elem.entry.name === name).entry.properties[
|
||||
'cm:title'
|
||||
] || ''
|
||||
);
|
||||
return children.find((elem) => elem.entry.name === name).entry.properties['cm:title'] || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeTitle.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeTitle.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -120,10 +92,7 @@ export class NodesApi extends RepoApi {
|
||||
const node = await this.getNodeById(nodeId);
|
||||
return (node.entry.properties && node.entry.properties[property]) || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeProperty.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeProperty.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -133,10 +102,7 @@ export class NodesApi extends RepoApi {
|
||||
const prop = await this.getNodeProperty(nodeId, 'cm:versionType');
|
||||
return prop || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getFileVersionType.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getFileVersionType.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -146,10 +112,7 @@ export class NodesApi extends RepoApi {
|
||||
const prop = await this.getNodeProperty(nodeId, 'cm:versionLabel');
|
||||
return prop || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getFileVersionLabel.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getFileVersionLabel.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -159,26 +122,17 @@ export class NodesApi extends RepoApi {
|
||||
const sharedId = await this.getNodeProperty(nodeId, 'qshare:sharedId');
|
||||
return sharedId || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getSharedId.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getSharedId.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
async getSharedExpiryDate(nodeId: string): Promise<string> {
|
||||
try {
|
||||
const expiryDate = await this.getNodeProperty(
|
||||
nodeId,
|
||||
'qshare:expiryDate'
|
||||
);
|
||||
const expiryDate = await this.getNodeProperty(nodeId, 'qshare:expiryDate');
|
||||
return expiryDate || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getSharedExpiryDate.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getSharedExpiryDate.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -188,10 +142,7 @@ export class NodesApi extends RepoApi {
|
||||
const sharedId = await this.getSharedId(nodeId);
|
||||
return sharedId !== '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.isFileShared.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.isFileShared.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -201,69 +152,42 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
await this.nodesApi.deleteNode(id, { permanent });
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.deleteNodeById.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.deleteNodeById.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodeByPath(
|
||||
path: string,
|
||||
permanent: boolean = true
|
||||
): Promise<void> {
|
||||
async deleteNodeByPath(path: string, permanent: boolean = true): Promise<void> {
|
||||
try {
|
||||
const id = (await this.getNodeByPath(path)).entry.id;
|
||||
await this.deleteNodeById(id, permanent);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.deleteNodeByPath.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.deleteNodeByPath.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodes(
|
||||
names: string[],
|
||||
relativePath: string = '',
|
||||
permanent: boolean = true
|
||||
): Promise<void> {
|
||||
async deleteNodes(names: string[], relativePath: string = '', permanent: boolean = true): Promise<void> {
|
||||
try {
|
||||
await names.reduce(async (previous, current) => {
|
||||
await previous;
|
||||
const req = await this.deleteNodeByPath(
|
||||
`${relativePath}/${current}`,
|
||||
permanent
|
||||
);
|
||||
const req = await this.deleteNodeByPath(`${relativePath}/${current}`, permanent);
|
||||
return req;
|
||||
}, Promise.resolve());
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.deleteNodes.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.deleteNodes.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodesById(
|
||||
ids: string[],
|
||||
permanent: boolean = true
|
||||
): Promise<void> {
|
||||
async deleteNodesById(ids: string[], permanent: boolean = true): Promise<void> {
|
||||
try {
|
||||
for (const id of ids) {
|
||||
await this.deleteNodeById(id, permanent);
|
||||
}
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.deleteNodesById.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.deleteNodesById.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async getNodeChildren(
|
||||
nodeId: string
|
||||
): Promise<NodeChildAssociationPaging | null> {
|
||||
async getNodeChildren(nodeId: string): Promise<NodeChildAssociationPaging | null> {
|
||||
try {
|
||||
const opts = {
|
||||
include: ['properties']
|
||||
@@ -271,61 +195,35 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.listNodeChildren(nodeId, opts);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeChildren.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeChildren.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async deleteNodeChildren(
|
||||
parentId: string,
|
||||
exceptNodesNamed?: string[]
|
||||
): Promise<void> {
|
||||
async deleteNodeChildren(parentId: string, exceptNodesNamed?: string[]): Promise<void> {
|
||||
try {
|
||||
const listEntries = (await this.getNodeChildren(parentId)).list.entries;
|
||||
let nodeIds: string[];
|
||||
if (exceptNodesNamed) {
|
||||
nodeIds = listEntries
|
||||
.filter(entries => !exceptNodesNamed.includes(entries.entry.name))
|
||||
.map(entries => entries.entry.id);
|
||||
nodeIds = listEntries.filter((entries) => !exceptNodesNamed.includes(entries.entry.name)).map((entries) => entries.entry.id);
|
||||
} else {
|
||||
nodeIds = listEntries.map(entries => entries.entry.id);
|
||||
nodeIds = listEntries.map((entries) => entries.entry.id);
|
||||
}
|
||||
await this.deleteNodesById(nodeIds);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.deleteNodeChildren.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.deleteNodeChildren.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async createImageNode(
|
||||
name: string,
|
||||
parentId: string = '-my-',
|
||||
title: string = '',
|
||||
description: string = ''
|
||||
): Promise<NodeEntry | null> {
|
||||
async createImageNode(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry | null> {
|
||||
const imageProps = {
|
||||
'exif:pixelXDimension': 1000,
|
||||
'exif:pixelYDimension': 1200
|
||||
};
|
||||
try {
|
||||
return await this.createNode(
|
||||
'cm:content',
|
||||
name,
|
||||
parentId,
|
||||
title,
|
||||
description,
|
||||
imageProps
|
||||
);
|
||||
return await this.createNode('cm:content', name, parentId, title, description, imageProps);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createImageNode.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createImageNode.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -364,10 +262,7 @@ export class NodesApi extends RepoApi {
|
||||
majorVersion
|
||||
});
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createNode.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createNode.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -382,39 +277,18 @@ export class NodesApi extends RepoApi {
|
||||
aspectNames: string[] = null
|
||||
): Promise<NodeEntry> {
|
||||
try {
|
||||
return await this.createNode(
|
||||
'cm:content',
|
||||
name,
|
||||
parentId,
|
||||
title,
|
||||
description,
|
||||
null,
|
||||
author,
|
||||
majorVersion,
|
||||
aspectNames
|
||||
);
|
||||
return await this.createNode('cm:content', name, parentId, title, description, null, author, majorVersion, aspectNames);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFile.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFile.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createImage(
|
||||
name: string,
|
||||
parentId: string = '-my-',
|
||||
title: string = '',
|
||||
description: string = ''
|
||||
): Promise<NodeEntry | null> {
|
||||
async createImage(name: string, parentId: string = '-my-', title: string = '', description: string = ''): Promise<NodeEntry | null> {
|
||||
try {
|
||||
return await this.createImageNode(name, parentId, title, description);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createImage.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createImage.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -428,22 +302,9 @@ export class NodesApi extends RepoApi {
|
||||
aspectNames: string[] = null
|
||||
): Promise<NodeEntry | null> {
|
||||
try {
|
||||
return await this.createNode(
|
||||
'cm:folder',
|
||||
name,
|
||||
parentId,
|
||||
title,
|
||||
description,
|
||||
null,
|
||||
author,
|
||||
null,
|
||||
aspectNames
|
||||
);
|
||||
return await this.createNode('cm:folder', name, parentId, title, description, null, author, null, aspectNames);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFolder.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFolder.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -453,54 +314,31 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.createNode('-my-', data as any);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createChildren.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createChildren.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async createContent(
|
||||
content: NodeContentTree,
|
||||
relativePath: string = '/'
|
||||
): Promise<NodeEntry | any> {
|
||||
async createContent(content: NodeContentTree, relativePath: string = '/'): Promise<NodeEntry | any> {
|
||||
try {
|
||||
return await this.createChildren(
|
||||
flattenNodeContentTree(content, relativePath)
|
||||
);
|
||||
return await this.createChildren(flattenNodeContentTree(content, relativePath));
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createContent.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createContent.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async createFolders(
|
||||
names: string[],
|
||||
relativePath: string = '/'
|
||||
): Promise<NodeEntry | any> {
|
||||
async createFolders(names: string[], relativePath: string = '/'): Promise<NodeEntry | any> {
|
||||
try {
|
||||
return await this.createContent({ folders: names }, relativePath);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFolders.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFolders.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async createFiles(
|
||||
names: string[],
|
||||
relativePath: string = '/'
|
||||
): Promise<NodeEntry | any> {
|
||||
async createFiles(names: string[], relativePath: string = '/'): Promise<NodeEntry | any> {
|
||||
try {
|
||||
return await this.createContent({ files: names }, relativePath);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFiles.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFiles.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,18 +347,12 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return this.nodesApi.updateNode(nodeId, { aspectNames });
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.addAspects.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.addAspects.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createFileLink(
|
||||
originalNodeId: string,
|
||||
destinationId: string
|
||||
): Promise<NodeEntry | null> {
|
||||
async createFileLink(originalNodeId: string, destinationId: string): Promise<NodeEntry | null> {
|
||||
const name = (await this.getNodeById(originalNodeId)).entry.name;
|
||||
const nodeBody = {
|
||||
name: `Link to ${name}.url`,
|
||||
@@ -536,18 +368,12 @@ export class NodesApi extends RepoApi {
|
||||
await this.addAspects(originalNodeId, ['app:linked']);
|
||||
return link;
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFileLink.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFileLink.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async createFolderLink(
|
||||
originalNodeId: string,
|
||||
destinationId: string
|
||||
): Promise<NodeEntry | 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`,
|
||||
@@ -566,10 +392,7 @@ export class NodesApi extends RepoApi {
|
||||
await this.addAspects(originalNodeId, ['app:linked']);
|
||||
return link;
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.createFolderLink.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.createFolderLink.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -580,25 +403,16 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.getNodeContent(nodeId);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getNodeContent.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getNodeContent.name}`, error);
|
||||
}
|
||||
}
|
||||
|
||||
async editNodeContent(
|
||||
nodeId: string,
|
||||
content: string
|
||||
): Promise<NodeEntry | null> {
|
||||
async editNodeContent(nodeId: string, content: string): Promise<NodeEntry | null> {
|
||||
try {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNodeContent(nodeId, content);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.editNodeContent.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.editNodeContent.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -608,19 +422,13 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return this.nodesApi.updateNode(nodeId, { name: newName });
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.renameNode.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.renameNode.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// node permissions
|
||||
async setInheritPermissions(
|
||||
nodeId: string,
|
||||
inheritPermissions: boolean
|
||||
): Promise<NodeEntry | null> {
|
||||
async setInheritPermissions(nodeId: string, inheritPermissions: boolean): Promise<NodeEntry | null> {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions
|
||||
@@ -631,20 +439,12 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNode(nodeId, data);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.setGranularPermission.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async setGranularPermission(
|
||||
nodeId: string,
|
||||
inheritPermissions: boolean = false,
|
||||
username: string,
|
||||
role: string
|
||||
): Promise<NodeEntry | null> {
|
||||
async setGranularPermission(nodeId: string, inheritPermissions: boolean = false, username: string, role: string): Promise<NodeEntry | null> {
|
||||
const data = {
|
||||
permissions: {
|
||||
isInheritanceEnabled: inheritPermissions,
|
||||
@@ -661,19 +461,13 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.updateNode(nodeId, data);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.setGranularPermission.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.setGranularPermission.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
// lock node
|
||||
async lockFile(
|
||||
nodeId: string,
|
||||
lockType: string = 'ALLOW_OWNER_CHANGES'
|
||||
): Promise<NodeEntry | null> {
|
||||
async lockFile(nodeId: string, lockType: string = 'ALLOW_OWNER_CHANGES'): Promise<NodeEntry | null> {
|
||||
const data = {
|
||||
type: lockType
|
||||
} as NodeBodyLock;
|
||||
@@ -692,10 +486,7 @@ export class NodesApi extends RepoApi {
|
||||
await this.apiAuth();
|
||||
return await this.nodesApi.unlockNode(nodeId);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.unlockFile.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.unlockFile.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -705,10 +496,7 @@ export class NodesApi extends RepoApi {
|
||||
const lockType = await this.getNodeProperty(nodeId, 'cm:lockType');
|
||||
return lockType || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getLockType.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getLockType.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -718,10 +506,7 @@ export class NodesApi extends RepoApi {
|
||||
const lockOwner = await this.getNodeProperty(nodeId, 'cm:lockOwner');
|
||||
return lockOwner || '';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.getLockOwner.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.getLockOwner.name}`, error);
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -730,18 +515,12 @@ export class NodesApi extends RepoApi {
|
||||
try {
|
||||
return (await this.getLockType(nodeId)) === 'WRITE_LOCK';
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.isFileLockedWrite.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.isFileLockedWrite.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
async isFileLockedWriteWithRetry(
|
||||
nodeId: string,
|
||||
expect: boolean
|
||||
): Promise<boolean> {
|
||||
async isFileLockedWriteWithRetry(nodeId: string, expect: boolean): Promise<boolean> {
|
||||
const data = {
|
||||
expect: expect,
|
||||
retry: 5
|
||||
@@ -758,26 +537,17 @@ export class NodesApi extends RepoApi {
|
||||
};
|
||||
return await Utils.retryCall(locked, data.retry);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.isFileLockedWriteWithRetry.name}`, error);
|
||||
}
|
||||
return isLocked;
|
||||
}
|
||||
|
||||
async isFileLockedByName(
|
||||
fileName: string,
|
||||
parentId: string
|
||||
): Promise<boolean> {
|
||||
async isFileLockedByName(fileName: string, parentId: string): Promise<boolean> {
|
||||
try {
|
||||
const id = await this.getNodeIdFromParent(fileName, parentId);
|
||||
return await this.isFileLockedWrite(id);
|
||||
} catch (error) {
|
||||
this.handleError(
|
||||
`${this.constructor.name} ${this.isFileLockedByName.name}`,
|
||||
error
|
||||
);
|
||||
this.handleError(`${this.constructor.name} ${this.isFileLockedByName.name}`, error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user