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

Commit

Permalink
[SDPSUP-6512] Restrict modification of field_search_configuration to …
Browse files Browse the repository at this point in the history
…administrators
  • Loading branch information
nicksantamaria committed May 2, 2024
1 parent 40187e3 commit 9cad4ba
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
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();
}

0 comments on commit 9cad4ba

Please sign in to comment.