Question

Global Search Field

Hi

 

I want to show the global search only for the admin users. Is there a way to acheive this ?

Like 0

Like

1 comments

Hello,

 

To achieve this task you can try the following approach:

 

1) Create a system operation in the "Operation permissions" section with the code like "GlobalSearchInputVisible" and grant access rights to system administrators only:

2) Activate the system feature with "AllowCreateAngularSchema" code (it's not available by default in the features list (available via /0/Shell/#Section/AppFeature_ListPage), you need to create a record in the list and enable it for your user).

 

3) After enabling the featue at step 2 a new option will appear in configurations that allows creating replacements for angular schemas:

Select this option and select "MainShell" as a parent schema for the created module.

 

4) Specify the following code in the schema from step 3:

define("MainShell", /**SCHEMA_DEPS*/["@creatio-devkit/common", "css!CardSchemaViewModule", "css!MainShellCSS"]/**SCHEMA_DEPS*/, function/**SCHEMA_ARGS*/(devkit)/**SCHEMA_ARGS*/ {
    return {
        viewConfigDiff: /**SCHEMA_VIEW_CONFIG_DIFF*/[]/**SCHEMA_VIEW_CONFIG_DIFF*/,
        viewModelConfig: /**SCHEMA_VIEW_MODEL_CONFIG*/{}/**SCHEMA_VIEW_MODEL_CONFIG*/,
        modelConfig: /**SCHEMA_MODEL_CONFIG*/{}/**SCHEMA_MODEL_CONFIG*/,
        handlers: /**SCHEMA_HANDLERS*/[
			{
				request: 'crt.ContentDisplayedStateChangedRequest',
				handler: async (request, next) => {
					const rightService = new devkit.RightsService();
					const canUseGlobalSearch = await rightService.getCanExecuteOperation('GlobalSearchInputVisible');
					if (!canUseGlobalSearch) {
						var element = document.querySelectorAll('[data-item-marker="AppToolbarGlobalSearch"]');
						element[0].remove();
					}
					return next?.handle(request);
				}
			}
		]/**SCHEMA_HANDLERS*/,
        converters: /**SCHEMA_CONVERTERS*/{}/**SCHEMA_CONVERTERS*/,
        validators: /**SCHEMA_VALIDATORS*/{}/**SCHEMA_VALIDATORS*/
    };
});

The idea here is simple: check if the user has access to system operation and if not - take the element that contains data-item-marker="AppToolbarGlobalSearch" selector and remove it from DOM.

5) Save the schema and refresh the page.

 

As a result the Global Search input will be hidden for regular users, but will be available for system administrators.

Show all comments