Skip to content

Commit

Permalink
Fix URL redirect for apps with no slash (#1088)
Browse files Browse the repository at this point in the history
* append a slash, if we need, on apps root

* remove white space in blank lines

* add test for new path
  • Loading branch information
gagelarsen authored Sep 6, 2024
1 parent c7b468f commit ce55da9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tests/unit_tests/test_tethys_apps/test_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ def test_get_active_app_url(self, mock_app):
result = utilities.get_active_app(url="/apps/foo/bar")
self.assertEqual(mock_app.objects.get(), result)

@override_settings(MULTIPLE_APP_MODE=True)
def test_get_active_app_no_app(self):
# check apps with /
result = utilities.get_active_app(url="/apps/")
self.assertEqual(None, result)
# check apps without /
result = utilities.get_active_app(url="/apps")
self.assertEqual(None, result)

@override_settings(MULTIPLE_APP_MODE=True)
@mock.patch("tethys_apps.utilities.SingletonHarvester")
@mock.patch("tethys_apps.models.TethysApp")
Expand Down
6 changes: 5 additions & 1 deletion tethys_apps/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,13 @@ def get_active_app(request=None, url=None, get_class=False):
else:
return None

apps_root = "apps"
if the_url.endswith(f"/{apps_root}"):
the_url += "/"

url_parts = the_url.split("/")
app = None
apps_root = "apps"

if apps_root in url_parts:
# The app root_url is the path item following (+1) the apps_root item
app_root_url_index = url_parts.index(apps_root) + 1
Expand Down

0 comments on commit ce55da9

Please sign in to comment.