[ACS-6252] support disabling the tags and categories feature in the applications (#3533)

* ACS-6252 Allow to hide tags and categories from metadata panel and to hide tags column from personal files

* ACS-6252 Allow to hide tags column from all other lists

* ACS-6252 Allow to hide tags and categories from search filters

* ACS-6252 Set type for search field

* ACS-6252 Hide displaying tags and categories related operators, properties and aspects in folder rules when that feature is disabled

* ACS-6252 Get from service information if tags and categories are disabled

* ACS-6252 Handled case when tags and categories configuration is missing in app.config.json

* ACS-6252 Unit tests for changes for RuleActionUiComponent

* ACS-6252 Unit tests for changes for RuleSimpleConditionUiComponent

* ACS-6252 Unit tests for changes for MetadataTabComponent

* ACS-6252 Unit tests for changes for app rules

* ACS-6252 Unit tests for changes for AppExtensionService

* ACS-6252 Removed redundant private from constructor parameter and corrected unit test title

* ACS-6252 Hide link to category action if categories feature is disabled

* ACS-6252 Move to beforeEach
This commit is contained in:
AleksanderSklorz
2023-11-28 14:09:00 +01:00
committed by GitHub
parent 6a326f776a
commit 2c69887e08
16 changed files with 535 additions and 64 deletions

View File

@@ -858,6 +858,72 @@ describe('app.evaluators', () => {
expect(app.canManagePermissions(context)).toBe(true);
});
});
describe('areTagsEnabled', () => {
it('should call context.appConfig.get with correct parameters', () => {
const context: any = {
appConfig: {
get: jasmine.createSpy()
}
};
app.areTagsEnabled(context);
expect(context.appConfig.get).toHaveBeenCalledWith('plugins.tags', true);
});
it('should return true if get from appConfig returns true', () => {
expect(
app.areTagsEnabled({
appConfig: {
get: () => true
}
} as any)
).toBeTrue();
});
it('should return false if get from appConfig returns false', () => {
expect(
app.areTagsEnabled({
appConfig: {
get: () => false
}
} as any)
).toBeFalse();
});
});
describe('areCategoriesEnabled', () => {
it('should call context.appConfig.get with correct parameters', () => {
const context: any = {
appConfig: {
get: jasmine.createSpy()
}
};
app.areCategoriesEnabled(context);
expect(context.appConfig.get).toHaveBeenCalledWith('plugins.categories', true);
});
it('should return true if get from appConfig returns true', () => {
expect(
app.areCategoriesEnabled({
appConfig: {
get: () => true
}
} as any)
).toBeTrue();
});
it('should return false if get from appConfig returns false', () => {
expect(
app.areCategoriesEnabled({
appConfig: {
get: () => false
}
} as any)
).toBeFalse();
});
});
});
function createTestContext(): TestRuleContext {

View File

@@ -636,3 +636,7 @@ export function isSmartFolder(context: RuleContext): boolean {
}
return false;
}
export const areTagsEnabled = (context: AcaRuleContext): boolean => context.appConfig.get('plugins.tags', true);
export const areCategoriesEnabled = (context: AcaRuleContext): boolean => context.appConfig.get('plugins.categories', true);

View File

@@ -1049,13 +1049,14 @@ describe('AppExtensionService', () => {
});
describe('search', () => {
let config: ExtensionConfig;
beforeEach(() => {
extensions.setEvaluators({
visible: () => true,
notVisible: () => false
});
applyConfig({
config = {
$id: 'test',
$name: 'test',
$version: '1.0.0',
@@ -1105,22 +1106,64 @@ describe('AppExtensionService', () => {
}
]
}
});
};
});
it('should load the search extension', () => {
applyConfig(config);
expect(service.search.length).toBe(2);
expect(service.search[0].id).toBe('app.search');
expect(service.search[1].id).toBe('app.search-1');
});
it('should not load the disabled search extension', () => {
applyConfig(config);
expect(service.search.find(({ id }) => id === 'app.search-2')).toBe(undefined, 'disabled configuration shown in the result');
});
it('should not load the not visible search extension', () => {
applyConfig(config);
expect(service.search.find(({ id }) => id === 'app.search-3')).toBe(undefined, 'not visible configuration shown in the result');
});
it('should contain category if it has no rules field', () => {
applyConfig(config);
const search = service.search[0];
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});
it('should contain category if it has no visible field in rules', () => {
config.features.search[0].categories[0].rules = {};
applyConfig(config);
const search = service.search[0];
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});
it('should contain category if it has visible field and extensions.evaluateRule returns true', () => {
spyOn(extensions, 'evaluateRule').and.returnValue(true);
const visible = 'test';
config.features.search[0].categories[0].rules = { visible };
applyConfig(config);
const search = service.search[0];
expect(extensions.evaluateRule).toHaveBeenCalledWith(visible, service);
expect(search.categories.length).toBe(1);
expect(search.categories[0].id).toBe('size');
});
it('should not contain category if it has visible field and extensions.evaluateRule returns false', () => {
spyOn(extensions, 'evaluateRule').and.returnValue(false);
const visible = 'test';
config.features.search[0].categories[0].rules = { visible };
applyConfig(config);
const search = service.search[0];
expect(extensions.evaluateRule).toHaveBeenCalledWith(visible, service);
expect(search.categories.length).toBe(0);
});
});
describe('rules', () => {

View File

@@ -56,6 +56,7 @@ import { ViewerRules } from '../models/viewer.rules';
import { Badge, SettingsGroupRef } from '../models/types';
import { NodePermissionService } from '../services/node-permission.service';
import { filter, map } from 'rxjs/operators';
import { SearchCategory } from '@alfresco/adf-content-services';
@Injectable({
providedIn: 'root'
@@ -167,6 +168,9 @@ export class AppExtensionService implements RuleContext {
this.sidebarTabs = this.loader.getElements<SidebarTabRef>(config, 'features.sidebar.tabs');
this.contentMetadata = this.loadContentMetadata(config);
this.search = this.loadSearchForms(config);
this.search?.forEach((searchSet) => {
searchSet.categories = searchSet.categories?.filter((category) => this.filterVisible(category));
});
this.documentListPresets = {
libraries: this.getDocumentListPreset(config, 'libraries'),
@@ -482,7 +486,7 @@ export class AppExtensionService implements RuleContext {
};
}
filterVisible(action: ContentActionRef | SettingsGroupRef | SidebarTabRef | DocumentListPresetRef): boolean {
filterVisible(action: ContentActionRef | SettingsGroupRef | SidebarTabRef | DocumentListPresetRef | SearchCategory): boolean {
if (action?.rules?.visible) {
return this.extensions.evaluateRule(action.rules.visible, this);
}