plone / Products.CMFPlone

The core of the Plone content management system
https://plone.org
GNU General Public License v2.0
240 stars 183 forks source link

Manage aliases (redirects) within `five.localsitemanager` folders #3947

Open petschki opened 2 months ago

petschki commented 2 months ago

I've came across this when using collective.lineage but I think this should be fixed here. Lineage basically only marks a folder as IObjectManagerSite and takes care of the persistent components registered to the base site.

Testsetup

  1. Create /Plone site
  2. Create a Folder Subsite and mark it as IChildSite
  3. Inside the subsite create a page Testpage, go to @@manage-aliases and add an alias /supertestpage
  4. In the existing aliases there's the new entry /subsite/supertestpage

What I expect

Redirect the path /subsite/supertestpage to /subsite/testpage

What really happens

The logic of the aliases browser view (https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/controlpanel/browser/redirects.py#L132) is:

  1. check if the provided alias is within a "navigationrooted" folder and add its path (if not already provided by the user) -> that's correct because plone_portal_state.portal_url() correctly traverses to ISiteRoot which is /Plone and plone_portal_state.navigation_root_url() is /Plone/subsite so the result is /subsite/supertestpage
  2. try to "absolutize" the path with the Plone portal path -> since this checks with zope.component.hooks.getSite it gets our IObjectSiteManager and you end up with the absolutized path /Plone/subsite/subsite/supertestpage

Solution

Use plone_portal_state.portal() to determine the absolute ISiteRoot path here https://github.com/plone/Products.CMFPlone/blob/master/Products/CMFPlone/controlpanel/browser/redirects.py#L51

Workaround

Add the redirects in @@redirection-controlpanel with the paths /subsite/supertestpage -> /subsite/testpage

mauritsvanrees commented 1 month ago

That sounds like it should work, without breaking the default case.