[AAE-11496] - Make aca-shared and aca-folder-rules buidlable (#2851)

* [AAE-11496] Fix aca-shared build

* Add build option to aca-folder-rules

* Add small test for aos
This commit is contained in:
Bartosz Sekuła
2022-12-20 19:21:22 +01:00
committed by GitHub
parent e570ef8da0
commit c5951edccf
19 changed files with 231 additions and 131 deletions

View File

@@ -26,8 +26,23 @@
import * as app from './app.rules';
import { TestRuleContext } from './test-rule-context';
import { NodeEntry } from '@alfresco/js-api';
import { getFileExtension } from './app.rules';
describe('app.evaluators', () => {
describe('getFileExtension', () => {
it('should return no extension when input is null', () => {
expect(getFileExtension(null)).toBe(null);
});
it('should extract file extension', () => {
expect(getFileExtension('test.docx')).toBe('docx');
});
it('should not extract file extension', () => {
expect(getFileExtension('unknown')).toBe(null);
});
});
describe('canDownloadSelection', () => {
it('should return [false] if selection is empty', () => {
const context = new TestRuleContext();

View File

@@ -25,11 +25,61 @@
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 * as repository from './repository.rules';
import { isAdmin } from './user.rules';
/* cspell:disable */
export const supportedExtensions = {
doc: 'ms-word',
docx: 'ms-word',
docm: 'ms-word',
dot: 'ms-word',
dotx: 'ms-word',
dotm: 'ms-word',
rtf: 'ms-word',
xls: 'ms-excel',
xlsx: 'ms-excel',
xlsb: 'ms-excel',
xlsm: 'ms-excel',
xlt: 'ms-excel',
xltx: 'ms-excel',
xltm: 'ms-excel',
xlam: 'ms-excel',
ppt: 'ms-powerpoint',
pptx: 'ms-powerpoint',
pot: 'ms-powerpoint',
potx: 'ms-powerpoint',
potm: 'ms-powerpoint',
pptm: 'ms-powerpoint',
pps: 'ms-powerpoint',
ppsx: 'ms-powerpoint',
ppam: 'ms-powerpoint',
ppsm: 'ms-powerpoint',
sldx: 'ms-powerpoint',
sldm: 'ms-powerpoint',
vsd: 'ms-visio',
vss: 'ms-visio',
vst: 'ms-visio',
vsdx: 'ms-visio',
vsdm: 'ms-visio',
vssx: 'ms-visio',
vssm: 'ms-visio',
vstx: 'ms-visio',
vstm: 'ms-visio'
};
/* cspell:enable */
export function getFileExtension(fileName: string): string | null {
if (fileName) {
const match = fileName.match(/\.([^\./\?\#]+)($|\?|\#)/);
return match ? match[1] : null;
}
return null;
}
export interface AcaRuleContext extends RuleContext {
withCredentials: boolean;
appConfig: AppConfigService;
@@ -257,7 +307,7 @@ export function canUpdateSelectedNode(context: RuleContext): boolean {
if (context.selection && !context.selection.isEmpty) {
const node = context.selection.first;
if (node.entry.isFile && hasLockedFiles(context)) {
if (node?.entry.isFile && hasLockedFiles(context)) {
return false;
}
@@ -329,8 +379,8 @@ export const isWriteLocked = (context: RuleContext): boolean =>
*/
export const isUserWriteLockOwner = (context: RuleContext): boolean =>
isWriteLocked(context) &&
context.selection.file.entry.properties['cm:lockOwner'] &&
context.selection.file.entry.properties['cm:lockOwner'].id === context.profile.id;
context.selection.file?.entry.properties['cm:lockOwner'] &&
context.selection.file?.entry.properties['cm:lockOwner'].id === context.profile.id;
/**
* Checks if user can lock selected file.
@@ -344,7 +394,7 @@ export const canLockFile = (context: RuleContext): boolean => !isWriteLocked(con
*/
export function canUnlockFile(context: RuleContext): boolean {
const { file } = context.selection;
return isWriteLocked(context) && (context.permissions.check(file.entry, ['delete']) || isUserWriteLockOwner(context));
return isWriteLocked(context) && (context.permissions.check(file?.entry, ['delete']) || isUserWriteLockOwner(context));
}
/**
@@ -475,7 +525,7 @@ export const canShowLogout = (context: AcaRuleContext): boolean => !context.with
* @param context Rule execution context
*/
export const isLibraryManager = (context: RuleContext): boolean =>
hasLibrarySelected(context) && context.selection.library.entry && context.selection.library.entry.role === 'SiteManager';
hasLibrarySelected(context) && context.selection.library?.entry.role === 'SiteManager';
/**
* Checks if the preview button for search results can be showed