mockup icon indicating copy to clipboard operation
mockup copied to clipboard

relateditems .pattern-relateditems-result-browse links broken on non-site rootPath

Open seanupton opened this issue 7 years ago • 2 comments

If you set anything other than the site root as the rootPath (e.g. a navroot/subsite) in options for the relateditems pattern, the path passed to the AJAX catalog query will be incorrect. This leads to missing results in browse mode everywhere outside of the rootPath.

To duplicate (using mockup master), something like the following:

  • Site's nav root is at /mysite/my-navroot-folder -- so...
  • rootPath could be set to /mysite/my-navroot-folder in my pattern options
    • I use a subclass of the server-side widget to inject this, but that seems a trivial detail.
  • site root is /mysite
  • A folder "animals" exists at /mysite/my-navroot-folder/animals
  • Clicking the .pattern-relateditems-browse-results link for "animals" will lead to erroneous path:
    • /mysite/my-navroot-folder/my-navroot-folder/animals is passed to @@getVocbaulary catalog query as path, and of course, this path always yields zero results/brains.
    • This is in part because the rootPath and the currentPath are concatenated without some sort of normalization to their respective relationship to the site root's path.

There is really no way that a non-site-root rootPath works at present. I would like to address this, but a fix is a bit elusive, because:

  • Some of this hides behind the abstractions of Select2.
  • There is no clear way I understand yet in JavaScript to ascertain the site-root-path in a Plone 5 site (without possibly making an AJAX call).
  • We cannot always assume that a duplicated path fragment like my-navroot-folder/my-navroot-folder is accidental, in the general case. This is the easiest way to generalize to most situations, but it does not solve all possible navroot path choices, and possibly incurs some unwanted technical debt as a workaround.

@thet any thoughts?

seanupton avatar Aug 16 '17 04:08 seanupton

@seanupton sorry for my late answer! I'm using the relateditems widget a lot for a lineage multisite project. Out of the box, the rootPath is set to what Products.CMFPlone.utils.get_top_site_from_url returns and rootUrl to that URL. basePath is set to the current navigation root object's path. The reason for that is, that if you are in a subsite of your main site without virtual hosting into the subsite, you want to start to browse/search from the subsite but be able to go to upper levels too. If you have a virtual host pointing into your subsite, then rootPath == basePath and root URL will be the FQDN of your site and you cannot go beyond rootPath.

Example 1: You have a subsite under /Plone/subsite Your browser points to: http://localhost:8080/Plone/subsite

rootPath = '/Plone'
rootUrl = 'http://localhost:8080/Plone'
basePath = '/Plone/subsite'

Example 2: You have a subsite under /Plone/subsite Your browser points to: http://subsite.com

rootPath = '/Plone/subsite'
rootUrl = 'http://localhost:8080/Plone/subsite'
basePath = '/Plone/subsite'

My guess is, that if you manually set the rootPath, you also have to set the rootUrl and it's done.

thet avatar Sep 28 '17 08:09 thet

Example 3: You have a subsite named /Plone/subsite your browser points to https://example.com/subsite

rootPath = '/Plone' rootURL = 'http://localhost:8080/Plone/' basePath = '/Plone/subsite'

I'm seeing the widget work properly on the first load - when it has no value - but when it does have a value, it removes the subsite from the path and the ajax query breaks.

First load - no existing value in field 'top story' (where I'm using the relateditems widget for a RelationChoice field) Ajax query works:

localhost:8080/RFA/english/@@edit/++widget++form.widgets.top_story/@@getSource?query={"criteria":[{"i":"SearchableText","o":"plone.app.querystring.operation.string.contains","v":"story"},{"i":"path","o":"plone.app.querystring.operation.string.path","v":"/RFA/english"}],"sort_on":null,"sort_order":null}&attributes=["UID","Title","portal_type","path","getURL","getIcon","is_folderish","review_state"]&batch={"page":1,"size":10}

Set and save a 'top story' - note that the story is at /RFA/english/news/story . The subsite is taken out of the query and it breaks:

Re-visit the edit page, and ajax query is broken:

localhost:8080/RFA/english/@@edit/++widget++form.widgets.top_story/@@getSource?query={"criteria":[{"i":"SearchableText","o":"plone.app.querystring.operation.string.contains","v":"story"},{"i":"path","o":"plone.app.querystring.operation.string.path","v":"/RFA/news"}],"sort_on":null,"sort_order":null}&attributes=["UID","Title","portal_type","path","getURL","getIcon","is_folderish","review_state"]&batch={"page":1,"size":10}

I was able to create some acceptable behavior for my case only, with: https://github.com/plone/plone.app.widgets/blob/f31946043d3b6f6619a576e730c5c41d1ddcc5ff/plone/app/widgets/utils.py#L159

Changing rootUrl to nav_root.getPhysicalPath()

I don't see this as the right answer, tho. Would love some advice.

flipmcf avatar Sep 29 '20 20:09 flipmcf