Skip to content
This repository has been archived by the owner on Sep 30, 2024. It is now read-only.

[SDPSUP-6512] Restrict modification of field_search_configuration to administrators #78

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
24 changes: 23 additions & 1 deletion src/TideSearchOperation.php
Original file line number Diff line number Diff line change
Expand Up @@ -334,5 +334,27 @@ public function setCoreSearchApiFields() {

$config->save();
}


/**
* Defines the name of the field that contains elasticsearch query config.
*/
const SEARCH_CONFIG_FIELD = "field_search_configuration";

/**
* Restricts field_search_configuration to administrators.
*/
public function restrictFieldSearchConfiguration() {
$config_factory = \Drupal::configFactory();
$config = $config_factory->getEditable('field.storage.node.field_search_configuration');
$config->set('third_party_settings', ['field_permissions' => ['permission_type' => 'custom']]);
$config->save();

foreach (["anonymous", "authenticated"] as $role_id) {
$role = \Drupal::entityTypeManager()->getStorage('user_role')->load($role_id);
$role->grantPermission(sprintf("view %s", self::SEARCH_CONFIG_FIELD));
$role->grantPermission(sprintf("view own %s", self::SEARCH_CONFIG_FIELD));
$role->save();
}
}

}
8 changes: 8 additions & 0 deletions tide_search.install
Original file line number Diff line number Diff line change
Expand Up @@ -117,3 +117,11 @@ function tide_search_update_10004() {
_tide_core_field_content_category_default_value('tide_search_listing', 'Search listing');
_tide_core_content_category_form_display('tide_search_listing');
}

/**
* Restricts field_search_configuration to administrators.
*/
function tide_search_update_10005() {
$tideSearchOperation = new TideSearchOperation();
$tideSearchOperation->restrictFieldSearchConfiguration();
}
Loading