diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 6e5d538d1f..0b80eb57c9 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -24,7 +24,7 @@ import * as app from './app.rules'; import { TestRuleContext } from './test-rule-context'; -import { NodeEntry } from '@alfresco/js-api'; +import { NodeEntry, RepositoryInfo } from '@alfresco/js-api'; import { getFileExtension } from './app.rules'; describe('app.evaluators', () => { @@ -793,4 +793,94 @@ describe('app.evaluators', () => { expect(app.canOpenWithOffice(context)).toBeTruthy(); }); }); + + describe('canEditAspects', () => { + let context: TestRuleContext; + + beforeEach(() => { + context = createTestContext(); + }); + + it('should return false for multiselection', () => { + context.selection.count = 2; + + expect(app.canEditAspects(context)).toBe(false); + }); + + it('should return false if user cannot update the selected node', () => { + context.permissions.check = spyOn(context.permissions, 'check').and.returnValue(false); + + expect(app.canEditAspects(context)).toBe(false); + }); + + it('should return false if the selected node is write locked', () => { + context.selection.file = { entry: { properties: { 'cm:lockType': 'WRITE_LOCK' } } } as NodeEntry; + + expect(app.canEditAspects(context)).toBe(false); + }); + + it('should return false if the context is trashcan', () => { + context.navigation = { url: '/trashcan' }; + + expect(app.canEditAspects(context)).toBe(false); + }); + + it('should return false if the selected node is a smart folder', () => { + context.selection.first = { entry: { aspectNames: ['smf:customConfigSmartFolder'], isFolder: true } } as NodeEntry; + + expect(app.canEditAspects(context)).toBe(false); + }); + + it('should return true if all conditions are met', () => { + expect(app.canEditAspects(context)).toBe(true); + }); + }); + + describe('canManagePermissions', () => { + let context: TestRuleContext; + + beforeEach(() => { + context = createTestContext(); + }); + + it('should return false if user cannot update the selected node', () => { + context.permissions.check = spyOn(context.permissions, 'check').and.returnValue(false); + + expect(app.canManagePermissions(context)).toBe(false); + }); + + it('should return false if the context is trashcan', () => { + context.navigation = { url: '/trashcan' }; + + expect(app.canManagePermissions(context)).toBe(false); + }); + + it('should return false if the selected node is a smart folder', () => { + context.selection.first = { entry: { aspectNames: ['smf:customConfigSmartFolder'], isFolder: true } } as NodeEntry; + expect(app.canManagePermissions(context)).toBe(false); + }); + + it('should return true if user can update the selected node and it is not a trashcan nor smart folder', () => { + expect(app.canManagePermissions(context)).toBe(true); + }); + }); }); + +function createTestContext(): TestRuleContext { + const context = new TestRuleContext(); + context.repository = { + version: { + major: 10 + }, + edition: '', + status: undefined + } as unknown as RepositoryInfo; + + context.permissions = { + check() { + return true; + } + }; + context.selection.isEmpty = false; + return context; +} diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index 9659103723..4b69368b62 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -495,7 +495,8 @@ export const canEditAspects = (context: RuleContext): boolean => canUpdateSelectedNode(context), !isWriteLocked(context), navigation.isNotTrashcan(context), - repository.isMajorVersionAvailable(context, '7') + repository.isMajorVersionAvailable(context, '7'), + !isSmartFolder(context) ].every(Boolean); /** @@ -505,7 +506,7 @@ export const canEditAspects = (context: RuleContext): boolean => * @param context Rule execution context */ export const canManagePermissions = (context: RuleContext): boolean => - [canUpdateSelectedNode(context), navigation.isNotTrashcan(context)].every(Boolean); + [canUpdateSelectedNode(context), navigation.isNotTrashcan(context), !isSmartFolder(context)].every(Boolean); /** * Checks if user can toggle **Edit Offline** mode for selected node. @@ -624,3 +625,15 @@ export function canOpenWithOffice(context: AcaRuleContext): boolean { return context.permissions.check(file, ['update']); } + +function isSmartFolder(context: RuleContext): boolean { + if (!context.selection?.isEmpty) { + const node = context.selection.first; + if (!node?.entry.isFolder) { + return false; + } + const nodeAspects = node.entry?.aspectNames ?? []; + return nodeAspects.includes('smf:customConfigSmartFolder') || nodeAspects.includes('smf:systemConfigSmartFolder'); + } + return false; +}