From 2a5ac66b07612e1528de8a4d9b78312c1658eff3 Mon Sep 17 00:00:00 2001 From: DominikIwanek Date: Wed, 8 Nov 2023 15:20:14 +0100 Subject: [PATCH 1/3] [ACS-6278] - stop showing 'edit aspects' and 'manage rules' when node is a smart folder --- .../aca-shared/rules/src/app.rules.spec.ts | 98 ++++++++++++++++++- projects/aca-shared/rules/src/app.rules.ts | 21 +++- 2 files changed, 116 insertions(+), 3 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index 6e5d538d1f..dd96564a55 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,100 @@ describe('app.evaluators', () => { expect(app.canOpenWithOffice(context)).toBeTruthy(); }); }); + + describe('canEditAspects', () => { + let context: TestRuleContext; + beforeEach(() => { + context = new TestRuleContext(); + context.repository = { + version: { + major: 10 + }, + edition: '', + status: undefined + } as unknown as RepositoryInfo; + + context.permissions = { + check() { + return true; + } + }; + context.selection.isEmpty = false; + }); + + 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 = new TestRuleContext(); + context.repository = { + version: { + major: 10 + }, + edition: '', + status: undefined + } as unknown as RepositoryInfo; + + context.permissions = { + check() { + return true; + } + }; + context.selection.isEmpty = false; + }); + 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.canEditAspects(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); + }); + }); }); diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index 9659103723..6142286447 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,19 @@ export function canOpenWithOffice(context: AcaRuleContext): boolean { return context.permissions.check(file, ['update']); } + +function isSmartFolder(context: RuleContext): boolean { + if (context.selection && !context.selection.isEmpty) { + const node = context.selection.first; + if (!node?.entry.isFolder) { + return false; + } + const nodeAspects = getNodeAspectNames(node); + return nodeAspects.includes('smf:customConfigSmartFolder') || nodeAspects.includes('smf:systemConfigSmartFolder'); + } + return false; +} + +function getNodeAspectNames(node: any): any[] { + return node.entry?.aspectNames ?? []; +} From bbff8ed04a0cdcad460566aa7a3b2af6d221c261 Mon Sep 17 00:00:00 2001 From: DominikIwanek Date: Wed, 8 Nov 2023 15:48:28 +0100 Subject: [PATCH 2/3] [ACS-6278] - fix after CR --- .../aca-shared/rules/src/app.rules.spec.ts | 56 +++++++++---------- projects/aca-shared/rules/src/app.rules.ts | 3 +- 2 files changed, 27 insertions(+), 32 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.spec.ts b/projects/aca-shared/rules/src/app.rules.spec.ts index dd96564a55..0b80eb57c9 100644 --- a/projects/aca-shared/rules/src/app.rules.spec.ts +++ b/projects/aca-shared/rules/src/app.rules.spec.ts @@ -796,22 +796,9 @@ describe('app.evaluators', () => { describe('canEditAspects', () => { let context: TestRuleContext; - beforeEach(() => { - context = new TestRuleContext(); - context.repository = { - version: { - major: 10 - }, - edition: '', - status: undefined - } as unknown as RepositoryInfo; - context.permissions = { - check() { - return true; - } - }; - context.selection.isEmpty = false; + beforeEach(() => { + context = createTestContext(); }); it('should return false for multiselection', () => { @@ -851,23 +838,11 @@ describe('app.evaluators', () => { describe('canManagePermissions', () => { let context: TestRuleContext; - beforeEach(() => { - context = new TestRuleContext(); - context.repository = { - version: { - major: 10 - }, - edition: '', - status: undefined - } as unknown as RepositoryInfo; - context.permissions = { - check() { - return true; - } - }; - context.selection.isEmpty = false; + beforeEach(() => { + context = createTestContext(); }); + it('should return false if user cannot update the selected node', () => { context.permissions.check = spyOn(context.permissions, 'check').and.returnValue(false); @@ -882,7 +857,7 @@ describe('app.evaluators', () => { 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); + 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', () => { @@ -890,3 +865,22 @@ describe('app.evaluators', () => { }); }); }); + +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 6142286447..ebebea9189 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -27,6 +27,7 @@ import { RuleContext } from '@alfresco/adf-extensions'; import * as navigation from './navigation.rules'; import * as repository from './repository.rules'; import { isAdmin } from './user.rules'; +import { NodeEntry } from '@alfresco/js-api'; /* cspell:disable */ export const supportedExtensions = { @@ -638,6 +639,6 @@ function isSmartFolder(context: RuleContext): boolean { return false; } -function getNodeAspectNames(node: any): any[] { +function getNodeAspectNames(node: NodeEntry): string[] { return node.entry?.aspectNames ?? []; } From 6c55b941261815b46c5f12cd522733cac3042d42 Mon Sep 17 00:00:00 2001 From: DominikIwanek Date: Thu, 9 Nov 2023 07:28:31 +0100 Subject: [PATCH 3/3] [ACS-6278] - changes after CR --- projects/aca-shared/rules/src/app.rules.ts | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/projects/aca-shared/rules/src/app.rules.ts b/projects/aca-shared/rules/src/app.rules.ts index ebebea9189..4b69368b62 100644 --- a/projects/aca-shared/rules/src/app.rules.ts +++ b/projects/aca-shared/rules/src/app.rules.ts @@ -27,7 +27,6 @@ import { RuleContext } from '@alfresco/adf-extensions'; import * as navigation from './navigation.rules'; import * as repository from './repository.rules'; import { isAdmin } from './user.rules'; -import { NodeEntry } from '@alfresco/js-api'; /* cspell:disable */ export const supportedExtensions = { @@ -628,17 +627,13 @@ export function canOpenWithOffice(context: AcaRuleContext): boolean { } function isSmartFolder(context: RuleContext): boolean { - if (context.selection && !context.selection.isEmpty) { + if (!context.selection?.isEmpty) { const node = context.selection.first; if (!node?.entry.isFolder) { return false; } - const nodeAspects = getNodeAspectNames(node); + const nodeAspects = node.entry?.aspectNames ?? []; return nodeAspects.includes('smf:customConfigSmartFolder') || nodeAspects.includes('smf:systemConfigSmartFolder'); } return false; } - -function getNodeAspectNames(node: NodeEntry): string[] { - return node.entry?.aspectNames ?? []; -}