[ACA-4618] Decouple ACA and Governance (#2757)

* [ACA-4618] Remove governance dependecies from ACA

* [ACA-4618] Move canOpenWithOffice evaluator to ACA shared

* [ACA-4618] Add missing unit test changes

* [ACA-4618] Prettier fixes
This commit is contained in:
MichalKinas
2022-11-04 12:15:33 +01:00
committed by GitHub
parent ae57a094b1
commit 8081bc81d6
8 changed files with 284 additions and 444 deletions

View File

@@ -25,8 +25,8 @@
import { AppConfigService } from '@alfresco/adf-core';
import { RuleContext } from '@alfresco/adf-extensions';
import { getFileExtension, supportedExtensions } from '@alfresco/adf-office-services-ext';
import * as navigation from './navigation.rules';
import { isNodeRecord } from './record.rules';
import * as repository from './repository.rules';
import { isAdmin } from './user.rules';
@@ -359,7 +359,6 @@ export function canUploadVersion(context: RuleContext): boolean {
return [
hasFileSelected(context),
navigation.isNotTrashcan(context),
!isNodeRecord(context),
isWriteLocked(context) ? isUserWriteLockOwner(context) : canUpdateSelectedNode(context)
].every(Boolean);
}
@@ -446,9 +445,7 @@ export const canManagePermissions = (context: RuleContext): boolean =>
* @param context Rule execution context
*/
export const canToggleEditOffline = (context: RuleContext): boolean =>
[hasFileSelected(context), navigation.isNotTrashcan(context), canLockFile(context) || canUnlockFile(context), !isNodeRecord(context)].every(
Boolean
);
[hasFileSelected(context), navigation.isNotTrashcan(context), canLockFile(context) || canUnlockFile(context)].every(Boolean);
/**
* @deprecated Uses workarounds for for recent files and search api issues.
@@ -490,3 +487,58 @@ export const canInfoPreview = (context: RuleContext): boolean =>
navigation.isSearchResults(context) && !isMultiselection(context) && !hasFolderSelected(context) && !navigation.isPreview(context);
export const showInfoSelectionButton = (context: RuleContext): boolean => navigation.isSearchResults(context) && !navigation.isPreview(context);
/**
* Checks if the file can be opened with MS Office
* JSON ref: `aos.canOpenWithOffice`
*
* @param context Rule execution context
*/
export function canOpenWithOffice(context: RuleContext): boolean {
if (context.navigation && context.navigation.url && context.navigation.url.startsWith('/trashcan')) {
return false;
}
if (!context || !context.selection) {
return false;
}
const { file } = context.selection;
if (!file || !file.entry) {
return false;
}
const extension = getFileExtension(file.entry.name);
if (!extension || !supportedExtensions[extension]) {
return false;
}
if (!file.entry.properties) {
return false;
}
if (file.entry.isLocked) {
return false;
}
if (file.entry.properties['cm:lockType'] === 'WRITE_LOCK' || file.entry.properties['cm:lockType'] === 'READ_ONLY_LOCK') {
return false;
}
const lockOwner = file.entry.properties['cm:lockOwner'];
if (lockOwner && lockOwner.id !== context.profile.id) {
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'
});
}
}
return context.permissions.check(file, ['update']);
}