Fix elasticsearch_url setter to accept array input

What does this MR do and why?

Fix the elasticsearch_url= setter to accept both String and Array inputs, resolving API round-trip failures.

Problem

The elasticsearch_url getter returns an array of URIs (e.g., ["https://es.example.com"]), but the setter only accepted comma-separated strings. When API clients read settings via GET /api/v4/application/settings and then write them back unchanged via PUT, the request fails with a 500 error.

Root Cause

ActiveSupport adds an Array#split method that behaves differently from String#split. When an array like ['https://es.example.com'] is passed to the setter:

  1. values.split(',') returns [['https://es.example.com']] (nested array)
  2. Then url.strip fails because url is an Array, not a String

Solution

The setter now handles both input types using a case statement:

  • String input: Split by comma (existing behavior)
  • Array input: Flatten and convert each element to string, then split by comma

This maintains backward compatibility while enabling round-trip API calls to work correctly.

Follow-up Consideration

The API documentation at doc/api/settings.md states that elasticsearch_url should be a comma-separated string. A future improvement could change the getter to return a string instead of an array to fully align with the documentation. This would be a breaking change and should be tracked separately.

🛠️ with ❤️ at Siemens

References

Screenshots or screen recordings

Not applicable - backend-only change with no UI impact.

How to set up and validate locally

  • Enable Elasticsearch indexing in Admin > Settings > Advanced Search
  • Configure an elasticsearch_url value
  • Use the API to read application settings:
    curl --header "PRIVATE-TOKEN: <your_token>" "http://localhost:3000/api/v4/application/settings" | jq '.elasticsearch_url'
  • Verify the response contains an array like ["http://localhost:9200"]
  • Send the same value back via PUT:
    curl --request PUT --header "PRIVATE-TOKEN: <your_token>" \
      --header "Content-Type: application/json" \
      --data '{"elasticsearch_url": ["http://localhost:9200"]}' \
      "http://localhost:3000/api/v4/application/settings"
  • Verify the request succeeds (HTTP 200) instead of returning a 500 error
  • Also verify that string input still works:
    curl --request PUT --header "PRIVATE-TOKEN: <your_token>" \
      --header "Content-Type: application/json" \
      --data '{"elasticsearch_url": "http://localhost:9200"}' \
      "http://localhost:3000/api/v4/application/settings"

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

MR Checklist (@gerardo-navarro)
Edited by Gerardo Navarro

Merge request reports

Loading