AlchemyCMS / alchemy_cms

Alchemy is the Open Source Rails CMS framework for the component based web that can be used as classic server side rendered or headless CMS.
https://www.alchemy-cms.com
BSD 3-Clause "New" or "Revised" License
817 stars 313 forks source link

Page tree doesn't switch languages when another site has more than one language. #2956

Open dbwinger opened 3 days ago

dbwinger commented 3 days ago

Steps to reproduce

  1. Start the dummy app
  2. Create a second site
  3. Add another language (de) to that site
  4. View pages for the new site and language
  5. Use the site select to switch back to the original default site
  6. Note that the page shown is from the new site/language, not the default site. You can confirm by looking at it's ID when hovering over the page link, or clicking in to edit the page and noting the site/language displayed in its tab.

Expected behavior

When using the site select to switch back to the default site, it should show that site's pages.

Actual behavior

It's stuck on the new site/language's pages. It looks like this is because Alchemy::Admin::CurrentLanguage.load_current_language is using the language ID stored in session, which is only changed by the Languages#switch action, which only happens when switching a language, not when switching sites. My best crack at a fix would be adding a check in Alchemy::Admin::CurrentLanguage.load_current_language for whether session[:alchemy_language_id] is an ID of the site indicated by the site_id parameter, and if not, set it to the site's default language. I'll probably take a stab at this if someone else doesn't get to it before me, but I wanted to report the bug first.

System configuration