Add endpoint for contacts autocomplete
What does this MR do and why?
It adds contacts as autocomplete source:
- adds a new route
- adds an endpoint to the controller + a new method to the AutocompleteService
- adds new finder for contacts
An existing feature flag is used here, this is not a user facing change. Using the endpoint should probably be under a new feature flag.
How to set up and validate locally
- Enable the feature flag
Feature.enable(:customer_relations)
- Visit any group general settings
http://127.0.0.1:3000/groups/flightjs/-/edit
- Enable the custom relations in
Permissions & group features
(last item in the section) - Check if you have any existing contacts (
http://127.0.0.1:3000/groups/flightjs/-/crm/contacts
) - Visit the contacts autocomplete endpoint (project)
http://127.0.0.1:3000/flightjs/Flight/-/autocomplete_sources/contacts
- You should see a json with contacts (id-email pair)
You can play around and verify that eg.
- contacts are not returned if a user is not a member of a root group but is a member of a subgroup
- contacts of a group with the feature disabled are not returned
- 404 is returned when user does not have permissions to see the contacts (at least reporters can see the contacts)
Database
ContactsFinder queries
Query plans based on group https://gitlab.com/gitlab-org/protect/demos/sandbox (id: 14491403) in order to have some hierarchy to search
Getting group root ancestor
- existing method used:
group = params[:group]&.root_ancestor
- query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/8111/commands/28875
Checking permissions
- existing method used:
can?(@current_user, :read_crm_contact, group)
- query plan: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/8111/commands/28876
- query plan against
gitlab-org
: https://console.postgres.ai/gitlab/gitlab-production-tunnel-pg12/sessions/8149/commands/29007
Getting contacts
- we don't have any data
group.contacts
SELECT "customer_relations_contacts".* FROM "customer_relations_contacts"
WHERE "customer_relations_contacts"."group_id" = 14491403
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Related to #350133 (closed)
Edited by Jarka Košanová