Skip to content

Commit

Permalink
[ACS-6278] - stop showing 'edit aspects' and 'manage rules' when node…
Browse files Browse the repository at this point in the history
… is a smart folder (#3512)

* [ACS-6278] - stop showing 'edit aspects' and 'manage rules' when node is a smart folder
  • Loading branch information
dominikiwanekhyland authored Nov 9, 2023
1 parent b54016b commit b5d561d
Show file tree
Hide file tree
Showing 2 changed files with 106 additions and 3 deletions.
92 changes: 91 additions & 1 deletion projects/aca-shared/rules/src/app.rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down Expand Up @@ -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;
}
17 changes: 15 additions & 2 deletions projects/aca-shared/rules/src/app.rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

/**
Expand All @@ -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.
Expand Down Expand Up @@ -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;
}

0 comments on commit b5d561d

Please sign in to comment.