Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ACS-6278] - stop showing 'edit aspects' and 'manage rules' when node is a smart folder #3512

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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', () => {
dominikiwanekhyland marked this conversation as resolved.
Show resolved Hide resolved
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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should use AcaRuleContext otherwise this rule won't be reusable in ADW as far as I remember

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isSmartFolder has parameter with RuleContext, because canEditAspects and canManagePermissions also have that. In ADW there is imported for example:
export const canEditAspects = (context: RuleContext)
so I think it would be fine if I just leave it like that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay fine for me

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;
}
Loading