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();
|
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', () => {
|
it('should return [true] if all checks succeed', () => {
|
||||||
const context: any = {
|
const context: any = {
|
||||||
selection: {
|
selection: {
|
||||||
@@ -199,6 +218,9 @@ describe('evaluators', () => {
|
|||||||
properties: {}
|
properties: {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
permissions: {
|
||||||
|
check: () => true
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,24 @@ export function canOpenWithOffice(
|
|||||||
|
|
||||||
const { file } = context.selection;
|
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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,5 +80,5 @@ export function canOpenWithOffice(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return context.permissions.check(file, ['update']);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -321,12 +321,6 @@ export function canUpdateSelectedNode(
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.entry.hasOwnProperty('allowableOperationsOnTarget')) {
|
|
||||||
return context.permissions.check(node, ['update'], {
|
|
||||||
target: 'allowableOperationsOnTarget'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return context.permissions.check(node, ['update']);
|
return context.permissions.check(node, ['update']);
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -25,6 +25,14 @@
|
|||||||
|
|
||||||
import { Injectable } from '@angular/core';
|
import { Injectable } from '@angular/core';
|
||||||
import { NodePermissions } from '@alfresco/adf-extensions';
|
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({
|
@Injectable({
|
||||||
providedIn: 'root'
|
providedIn: 'root'
|
||||||
@@ -32,31 +40,41 @@ import { NodePermissions } from '@alfresco/adf-extensions';
|
|||||||
export class NodePermissionService implements NodePermissions {
|
export class NodePermissionService implements NodePermissions {
|
||||||
static DEFAULT_OPERATION = 'OR';
|
static DEFAULT_OPERATION = 'OR';
|
||||||
|
|
||||||
private defaultOptions = {
|
private defaultOptions: PermissionOptions = {
|
||||||
operation: NodePermissionService.DEFAULT_OPERATION,
|
operation: NodePermissionService.DEFAULT_OPERATION,
|
||||||
target: null
|
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 || {});
|
const opts = Object.assign({}, this.defaultOptions, options || {});
|
||||||
|
|
||||||
if (source) {
|
if (!source) {
|
||||||
if (Array.isArray(source) && source.length) {
|
return false;
|
||||||
const arr = this.sanitize(source);
|
|
||||||
|
|
||||||
return (
|
|
||||||
!!arr.length &&
|
|
||||||
source.every(node => this.hasPermission(node, permissions, opts))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return this.hasPermission(source, permissions, opts);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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(
|
const allowableOperations = this.getAllowableOperations(
|
||||||
node,
|
node,
|
||||||
options.target
|
options.target
|
||||||
@@ -77,21 +95,26 @@ export class NodePermissionService implements NodePermissions {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private getAllowableOperations(node, target): string[] {
|
private getAllowableOperations(
|
||||||
const entry = node.entry || node;
|
node: PermissionSource,
|
||||||
|
property?: string
|
||||||
|
): string[] {
|
||||||
|
let entry: Node | SharedLink;
|
||||||
|
|
||||||
if (!target && entry.allowableOperations) {
|
if ('entry' in node) {
|
||||||
return entry.allowableOperations;
|
entry = node.entry;
|
||||||
|
} else {
|
||||||
|
entry = node;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (target && entry[target]) {
|
if (property) {
|
||||||
return entry[target];
|
return entry[property] || [];
|
||||||
}
|
}
|
||||||
|
|
||||||
return [];
|
if ('allowableOperationsOnTarget' in entry) {
|
||||||
}
|
return entry.allowableOperationsOnTarget || [];
|
||||||
|
} else {
|
||||||
private sanitize(selection): any[] {
|
return entry.allowableOperations || [];
|
||||||
return (selection || []).filter(item => item);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -227,14 +227,7 @@ function updateSelectedNodes(
|
|||||||
? true
|
? true
|
||||||
: false;
|
: false;
|
||||||
});
|
});
|
||||||
folder = nodes.find((entity: any) =>
|
folder = nodes.find((entity: any) => entity.entry.isFolder);
|
||||||
// workaround Shared
|
|
||||||
entity.entry.isFolder ||
|
|
||||||
entity.entry.nodeId ||
|
|
||||||
entity.entry.sharedByUser
|
|
||||||
? true
|
|
||||||
: false
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user