Fix broken links when cs_sole_course is set #110

Manually merged
hz merged 5 commits from almonds/catsoop:main into main 2026-09-16 12:46:24 +00:00
Contributor

These diffs fix the broken settings links and breadcrumb _util links I mentioned a while ago. I've tested the following on 3.12 and 3.14, with and without cs_sole_course set:

  • registering a user (with the simple login auth)
  • logging in
  • logging out
  • breadcrumb URLs are working for paths that do not start with the cs_course (or do start with it, as before)
  • the "Exit Settings Menu" link is correct (catsoop.this_path in session storage)

A couple causes of the bug were from not checking if cs_sole_course was set. For the other causes, while the original code checked if cs_sole_course was set before popping the first element of the paths, it did not check if the first element of the path was cs_course, so it would remove '_util' by accident, for example.

I fixed & moved the _get_base_url helper from login.py to dispatch.py, and I imported it in login.py and in the default handler. (If there's a better place for a helper function that's used in multiple spots, then it could be moved there instead.) The patch should also fix SSO, LDAP3, and OpenID, since those three actually import _get_base_url from the simple login auth, but I did not test these explicitly.

I split this PR into two commits, because I noticed the other PRs also affect the default handler. In that file, the session storage was originally not saving the correct URL that accounts for a sole course. Running black on the handler changes some other parts of that file, but I did not commit them for this PR, to reduce confusion.

While these changes work smoothly for logging in/out and navigating settings, I suspect there are other forms of the same bug hidden somewhere, e.g., for submitting answers to questions. I could look into it, though my personal use case doesn't actually use questions, just logins/settings, and I'm unlikely to have time anytime soon.

These diffs fix the broken settings links and breadcrumb \_util links I mentioned a while ago. I've tested the following on 3.12 and 3.14, with and without `cs_sole_course` set: * registering a user (with the simple login auth) * logging in * logging out * breadcrumb URLs are working for paths that do not start with the `cs_course` (or do start with it, as before) * the "Exit Settings Menu" link is correct (`catsoop.this_path` in session storage) A couple causes of the bug were from not checking if `cs_sole_course` was set. For the other causes, while the original code checked if `cs_sole_course` was set before popping the first element of the paths, it did not check if the first element of the path was `cs_course`, so it would remove `'_util'` by accident, for example. I fixed & moved the `_get_base_url` helper from `login.py` to `dispatch.py`, and I imported it in `login.py` and in the default handler. (If there's a better place for a helper function that's used in multiple spots, then it could be moved there instead.) The patch should also fix SSO, LDAP3, and OpenID, since those three actually import `_get_base_url` from the simple login auth, but I did not test these explicitly. I split this PR into two commits, because I noticed the other PRs also affect the default handler. In that file, the session storage was originally not saving the correct URL that accounts for a sole course. Running `black` on the handler changes some other parts of that file, but I did not commit them for this PR, to reduce confusion. While these changes work smoothly for logging in/out and navigating settings, I suspect there are other forms of the same bug hidden somewhere, e.g., for submitting answers to questions. I could look into it, though my personal use case doesn't actually use questions, just logins/settings, and I'm unlikely to have time anytime soon.
* fix breadcrumbs for pages that do not start with `cs_course`
* fix settings link in dropdown menu
* fix redirect links for register, login, logout actions
* share `_get_base_url` helper between `dispatch.py` & `login.py`
* fix handler to use correct URL for session storage
  `catsoop.this_path`
Author
Contributor

I only tested this for production instances. Today I notice in my other courses, they aren't serving css, js, or images for local testing, because the URL is missing the cs_course (e.g., http://localhost:7667/_static/css/calendar.v0.css instead of http://localhost:7667/_static/iesj26/css/calendar.v0.css). I'll change this PR to a WIP, and see if I can figure out what's going on by the end of the day.

I only tested this for production instances. Today I notice in my other courses, they aren't serving css, js, or images for local testing, because the URL is missing the `cs_course` (e.g., `http://localhost:7667/_static/css/calendar.v0.css` instead of `http://localhost:7667/_static/iesj26/css/calendar.v0.css`). I'll change this PR to a WIP, and see if I can figure out what's going on by the end of the day.
almonds changed title from Fix broken links when cs_sole_course is set to WIP: Fix broken links when cs_sole_course is set 2026-06-19 17:01:08 +00:00
Author
Contributor

Pretty sure it was because an "and" should have been an "or", oops... I'll test this on a production instance with static resources before removing the WIP.

Pretty sure it was because an "and" should have been an "or", oops... I'll test this on a production instance with static resources before removing the WIP.
Author
Contributor
  • local instance (tested locally) → works
  • production instance (tested on a server) → works... because my nginx config handles the static files
  • production instance (tested locally) → does not work

Damn. This is happening because ['_static', cs_course, 'img', 'blah.jpg'] should apparently have the cs_course bit removed, for ['_static', 'img', 'blah.jpg'], and my commits didn't expect that. Looking into it...

* local instance (tested locally) → works * production instance (tested on a server) → works... because my nginx config handles the static files * production instance (tested locally) → **does not** work Damn. This is happening because `['_static', cs_course, 'img', 'blah.jpg']` should apparently have the `cs_course` bit removed, for `['_static', 'img', 'blah.jpg']`, and my commits didn't expect that. Looking into it...
Author
Contributor

Turns out the "or" half wasn't necessary in that code branch. (It is necessary in the other branches.) I tested a local instance (locally), a production instance (locally), and a production instance (remote), when cs_sole_course is set versus not set:

  • <img src='COURSE/image.jpg'> when /__STATIC__/image.jpg exists
  • <img src='COURSE/img/image.jpg'> when /__STATIC__/img/image.jpg exists
  • <img src='COURSE/test/image.jpg'> when /test/__STATIC__/image.jpg exists
  • <img src='CURRENT/image.jpg'> on the /test page when /test/__STATIC__/image.jpg exists

(<img src='CURRENT/img/image.jpg'> on the /test page when /test/__STATIC__/img/image.jpg exists does not work, however, it did not work in the first place, and it looked like I would have to fix that bug elsewhere, so this is fine with me.)

All the URLs for the settings link that this PR originally set out to fix still work, so I think this is the one.

Turns out the "or" half wasn't necessary in that code branch. (It is necessary in the other branches.) I tested a local instance (locally), a production instance (locally), and a production instance (remote), when `cs_sole_course` is set versus not set: * `<img src='COURSE/image.jpg'>` when `/__STATIC__/image.jpg` exists * `<img src='COURSE/img/image.jpg'>` when `/__STATIC__/img/image.jpg` exists * `<img src='COURSE/test/image.jpg'>` when `/test/__STATIC__/image.jpg` exists * `<img src='CURRENT/image.jpg'>` on the `/test` page when `/test/__STATIC__/image.jpg` exists (`<img src='CURRENT/img/image.jpg'>` on the `/test` page when `/test/__STATIC__/img/image.jpg` exists does **not** work, however, it did not work in the first place, and it looked like I would have to fix that bug elsewhere, so this is fine with me.) All the URLs for the settings link that this PR originally set out to fix still work, so I think this is the one.
almonds changed title from WIP: Fix broken links when cs_sole_course is set to Fix broken links when cs_sole_course is set 2026-06-19 18:13:06 +00:00
Owner

Sorry for the long delay here, @almonds . I took a look through, and this all looks good to me! Happy to merge this in. Do you want to add yourself to the CONTRIBUTORS.md file as well before I merge it in?

Sorry for the long delay here, @almonds . I took a look through, and this all looks good to me! Happy to merge this in. Do you want to add yourself to the `CONTRIBUTORS.md` file as well before I merge it in?
Author
Contributor

Sure thing, one sec

Sure thing, one sec
hz referenced this pull request from a commit 2026-09-16 12:45:31 +00:00
hz manually merged commit 2ac5513a32 into main 2026-09-16 12:46:24 +00:00
Owner

Merged! Big thanks for this! :)

Merged! Big thanks for this! :)
Sign in to join this conversation.
No reviewers
No milestone
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
catsoop/catsoop!110
No description provided.