Search API indexes of CRM contacts do not apply CRM’s grant model by default. Without access filtering, contact search can expose private records to users who should not see them.

CRM Search API adds an opt-in CRM contact access processor. It indexes view grants and user–contact mappings, then filters Search API queries with the same access rules used by Views, list builders, and core Contact Search.

Use it whenever you build contact search with Search API—Database Search, Solr, Facets, or Search API Views—and contact privacy matters.

Features

  • Grant indexing — Denormalizes view grants from crm_contact_access into the search index.
  • Mapped-user indexing — Indexes user IDs mapped to each contact for blanket mapped access.
  • Access parity — Filters queries using the same model as Views and Contact Search: bypass permissions, bundle permissions, mapped access, and grant tokens (including hook_crm_contact_grants()).
  • Opt-in per index — Indexes do not enforce contact access until you enable the processor.
  • Mapping-aware reindex — When user–contact mappings change, affected contacts are marked for reindex automatically.
  • Mixed-datasource safe — On indexes that mix entity types, only CRM contacts are filtered.
  • Backend agnostic — Works with any Search API backend.

Example use cases:

  • A member directory where each person only sees contacts they are allowed to view.
  • Staff CRM search over Solr or Database Search with role- and grant-based privacy.
  • Faceted contact search that must match CRM’s existing access rules.

Post-Installation

This module has no configuration form of its own. After installing CRM, Search API, and a search backend:

  1. Enable CRM Search API.
  2. Create a Search API server and index.
  3. Add the CRM contact datasource (entity:crm_contact).
  4. On the index Processors tab, enable CRM contact access.
  5. Save the index and index (or reindex) items.
  6. Build Views, Facets, or other Search API UIs against the index as usual.

Assign CRM permissions and grants as needed (administer crm, view any crm contact, bundle-specific view permissions, view mapped crm contact, plus your grant setup). After access-model changes that do not go through mapping hooks, reindex affected contacts so search stays in sync.

Additional Requirements

  • CRM (^1.0.0-beta5)
  • Search API
  • Drupal 11.1 or later
  • A Search API backend (for example Database Search or Solr)
  • Database Search or Search API Solr — search backends for your index.
  • Facets — faceted browsing on contact indexes.
  • CRM’s crm_simpsons recipe — sample contacts for local exploration (see DDEV setup below).

Similar projects

  • CRM Contact Search — CRM’s built-in core Search plugin uses the same access model, but it is not Search API. Use this module when you need Search API indexes, backends, Views, or Facets.
  • Search API Content access — Filters node search by node_access. CRM Search API is the equivalent for CRM contacts and the crm_contact_access grant system.

Supporting this Module

Local development for this project relies on DDEV. If you use DDEV, consider sponsoring DDEV development.

Community Documentation

  • README in the project repository
  • Issue queue for questions, bugs, and feature requests

Develop with DDEV

If you have not already, install DDEV, then:

git clone git@git.drupal.org:project/crm_search_api.git
cd crm_search_api
ddev config --project-type=drupal --docroot=web --php-version=8.4 --corepack-enable --project-name=crm-search-api
ddev add-on get ddev/ddev-drupal-contrib
ddev add-on get s-ayers/ddev-drupal-contrib-mkdocs
ddev add-on get s-ayers/ddev-drupal-paratest
ddev start
ddev poser
ddev symlink-project
ddev drush site:install -y
ddev drush pm:install crm_search_api -y
ddev drush config:export -y
ddev drush user:login
ddev drush recipe modules/contrib/crm/recipes/crm_simpsons

Consider sponsoring DDEV development.

Supporting organizations: 

Project information

Releases