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:
- 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. - Remove the
nameandname=methods fromGeoNode. This guarantees thatGeoNode.namealways returns the database value and saves the name unchanged. - Add complex logic to
GeoNode.current_nodeandGeoNode.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_nodechecks when thecurrent_node_namematches thecurrent_node_urlwith or without a trailing slash. Similarly, for.current?(node)we check that thenode.nameandnode.urlmatch 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.ymland the Rails console. - Play around various values of
geo: node_name:in the config andGeoNode.current_node.namein 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