mirror of
https://github.com/Alfresco/alfresco-content-app.git
synced 2026-09-09 18:02:54 +00:00
[ACA-2259] Edit in Microsoft Office - check update permissions (#1015)
* [ACA-2259] Edit in Microsoft Office - check update permissions * [ACA-2259] check update permissions - unit tests * [ACA-2259] refactor - check allowableOperationsOnTarget from service * [ACA-2259] add back check only on target for SharedFiles * [ACA-2259] SharedLinks are not folders * type-safe api for node permissions * workaround for shared files * use hasOwnProperty function
This commit is contained in:
committed by
Denys Vuika
parent
07f45e08cf
commit
88e74b1e2d
@@ -189,6 +189,25 @@ describe('evaluators', () => {
|
||||
expect(canOpenWithOffice(context)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return [false] if permissions check is false', () => {
|
||||
const context: any = {
|
||||
selection: {
|
||||
file: {
|
||||
entry: {
|
||||
name: 'document.docx',
|
||||
isLocked: false,
|
||||
properties: {}
|
||||
}
|
||||
}
|
||||
},
|
||||
permissions: {
|
||||
check: () => false
|
||||
}
|
||||
};
|
||||
|
||||
expect(canOpenWithOffice(context)).toBeFalsy();
|
||||
});
|
||||
|
||||
it('should return [true] if all checks succeed', () => {
|
||||
const context: any = {
|
||||
selection: {
|
||||
@@ -199,6 +218,9 @@ describe('evaluators', () => {
|
||||
properties: {}
|
||||
}
|
||||
}
|
||||
},
|
||||
permissions: {
|
||||
check: () => true
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -26,7 +26,24 @@ export function canOpenWithOffice(
|
||||
|
||||
const { file } = context.selection;
|
||||
|
||||
if (!file || !file.entry || !file.entry.properties) {
|
||||
if (!file || !file.entry) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// workaround for Shared files
|
||||
if (
|
||||
context.navigation &&
|
||||
context.navigation.url &&
|
||||
context.navigation.url.startsWith('/shared')
|
||||
) {
|
||||
if (file.entry.hasOwnProperty('allowableOperationsOnTarget')) {
|
||||
return context.permissions.check(file, ['update'], {
|
||||
target: 'allowableOperationsOnTarget'
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (!file.entry.properties) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -63,5 +80,5 @@ export function canOpenWithOffice(
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
return context.permissions.check(file, ['update']);
|
||||
}
|
||||
|
||||
@@ -321,12 +321,6 @@ export function canUpdateSelectedNode(
|
||||
return false;
|
||||
}
|
||||
|
||||
if (node.entry.hasOwnProperty('allowableOperationsOnTarget')) {
|
||||
return context.permissions.check(node, ['update'], {
|
||||
target: 'allowableOperationsOnTarget'
|
||||
});
|
||||
}
|
||||
|
||||
return context.permissions.check(node, ['update']);
|
||||
}
|
||||
return false;
|
||||
|
||||
@@ -25,6 +25,14 @@
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { NodePermissions } from '@alfresco/adf-extensions';
|
||||
import { Node, SharedLink, SharedLinkEntry, NodeEntry } from '@alfresco/js-api';
|
||||
|
||||
export type PermissionSource = NodeEntry | SharedLinkEntry | Node;
|
||||
|
||||
export interface PermissionOptions {
|
||||
target?: string;
|
||||
operation?: string;
|
||||
}
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -32,31 +40,41 @@ import { NodePermissions } from '@alfresco/adf-extensions';
|
||||
export class NodePermissionService implements NodePermissions {
|
||||
static DEFAULT_OPERATION = 'OR';
|
||||
|
||||
private defaultOptions = {
|
||||
private defaultOptions: PermissionOptions = {
|
||||
operation: NodePermissionService.DEFAULT_OPERATION,
|
||||
target: null
|
||||
};
|
||||
|
||||
check(source: any, permissions: string[], options?: any): boolean {
|
||||
check(
|
||||
source: PermissionSource | PermissionSource[],
|
||||
permissions: string[],
|
||||
options?: PermissionOptions
|
||||
): boolean {
|
||||
const opts = Object.assign({}, this.defaultOptions, options || {});
|
||||
|
||||
if (source) {
|
||||
if (Array.isArray(source) && source.length) {
|
||||
const arr = this.sanitize(source);
|
||||
|
||||
return (
|
||||
!!arr.length &&
|
||||
source.every(node => this.hasPermission(node, permissions, opts))
|
||||
);
|
||||
}
|
||||
|
||||
return this.hasPermission(source, permissions, opts);
|
||||
if (!source) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
if (Array.isArray(source)) {
|
||||
source = source.filter(item => item);
|
||||
|
||||
if (source.length > 0) {
|
||||
return source.every(node =>
|
||||
this.isOperationAllowed(node, permissions, opts)
|
||||
);
|
||||
}
|
||||
return false;
|
||||
} else {
|
||||
return this.isOperationAllowed(source, permissions, opts);
|
||||
}
|
||||
}
|
||||
|
||||
private hasPermission(node, permissions, options): boolean {
|
||||
private isOperationAllowed(
|
||||
node: PermissionSource,
|
||||
permissions: string[],
|
||||
options: PermissionOptions
|
||||
): boolean {
|
||||
const allowableOperations = this.getAllowableOperations(
|
||||
node,
|
||||
options.target
|
||||
@@ -77,21 +95,26 @@ export class NodePermissionService implements NodePermissions {
|
||||
return false;
|
||||
}
|
||||
|
||||
private getAllowableOperations(node, target): string[] {
|
||||
const entry = node.entry || node;
|
||||
private getAllowableOperations(
|
||||
node: PermissionSource,
|
||||
property?: string
|
||||
): string[] {
|
||||
let entry: Node | SharedLink;
|
||||
|
||||
if (!target && entry.allowableOperations) {
|
||||
return entry.allowableOperations;
|
||||
if ('entry' in node) {
|
||||
entry = node.entry;
|
||||
} else {
|
||||
entry = node;
|
||||
}
|
||||
|
||||
if (target && entry[target]) {
|
||||
return entry[target];
|
||||
if (property) {
|
||||
return entry[property] || [];
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
private sanitize(selection): any[] {
|
||||
return (selection || []).filter(item => item);
|
||||
if ('allowableOperationsOnTarget' in entry) {
|
||||
return entry.allowableOperationsOnTarget || [];
|
||||
} else {
|
||||
return entry.allowableOperations || [];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,14 +227,7 @@ function updateSelectedNodes(
|
||||
? true
|
||||
: false;
|
||||
});
|
||||
folder = nodes.find((entity: any) =>
|
||||
// workaround Shared
|
||||
entity.entry.isFolder ||
|
||||
entity.entry.nodeId ||
|
||||
entity.entry.sharedByUser
|
||||
? true
|
||||
: false
|
||||
);
|
||||
folder = nodes.find((entity: any) => entity.entry.isFolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user