Geo: Do not fail current_node recognition when name is missing a slash

What does this MR do and why?

Currently, each time the name field on GeoNode is updated, we check if the new value + a trailing slash matches the url. If it does, before saving, we add the slash to the DB value.

However, this behaviour causes a bug in the case where a user consciously uses the site's URL without a slash for the node name.

To silently remove this bug, I've done the following:

  1. Remove the automatic slash addition to the default setting. Now if gitlab_rails['node_name'] is empty, the default value is the URL, un-changed.
  2. Remove the name and name= methods from GeoNode. This guarantees that GeoNode.name always returns the database value and saves the name unchanged.
  3. Add complex logic to GeoNode.current_node and GeoNode.current?(node) to catch all corner cases concerning trailing slashes.

The last point logic can be defined as follows:

  • First we check if the value matches. If they do, very well! We've got our node. Else, we need to see if we fall under a corner case.
  • The corner case only happens when the name resembles the url. So we make sure that .current_node checks when the current_node_name matches the current_node_url with or without a trailing slash. Similarly, for .current?(node) we check that the node.name and node.url match with or without trailing slashes.
  • If the name and the URL don't match even with/without a trailing slash, the node isn't found.

References

Relates to: #536444 (closed)

How to set up and validate locally

  • On a Geo-enabled GDK, open config/gitlab.yml and the Rails console.
  • Play around various values of geo: node_name: in the config and GeoNode.current_node.name in the Rails console.
  • You can find a table of values I've tested on in my primary GDK in this spreadsheet, under the "Fix: tested values" tab.

MR acceptance checklist

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

Edited by Chloe Fons

Merge request reports

Loading