-
Notifications
You must be signed in to change notification settings - Fork 101
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ZMI: re-implement the logic to prepend authentication path
The previous approach from #1196 was not correct when using virtual host, because AUTHENTICATION_PATH is not usable in virtual host contexts. This uses a different approach, by making the js and css path subscribers take care of generating the URLs with the authentication path prepended using request API aware of virtual hosting.
- Loading branch information
1 parent
c33b799
commit 34108aa
Showing
4 changed files
with
151 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,60 @@ | ||
import itertools | ||
|
||
import zope.component | ||
import zope.interface | ||
from Acquisition import aq_parent | ||
from ZPublisher.HTTPRequest import HTTPRequest | ||
|
||
|
||
def prepend_authentication_path(request: HTTPRequest, path: str) -> str: | ||
"""Prepend the path of the user folder. | ||
Because ++resource++zmi is protected, we generate URLs relative to the | ||
user folder of the logged-in user, so that the user can access the | ||
resources. | ||
""" | ||
authenticated_user = request.get("AUTHENTICATED_USER") | ||
if not authenticated_user: | ||
return path | ||
|
||
# prepend the authentication path, unless it is already part of the | ||
# virtual host root. | ||
authentication_path = [] | ||
ufpp = aq_parent(aq_parent(authenticated_user)).getPhysicalPath() | ||
vrpp = request.get("VirtualRootPhysicalPath") or () | ||
for ufp, vrp in itertools.zip_longest(ufpp, vrpp): | ||
if ufp == vrp: | ||
continue | ||
authentication_path.append(ufp) | ||
|
||
parts = [ | ||
p for p in itertools.chain(authentication_path, path.split("/")) if p] | ||
|
||
return request.physicalPathToURL(parts, relative=True) | ||
|
||
|
||
@zope.component.adapter(zope.interface.Interface) | ||
def css_paths(context): | ||
"""Return paths to CSS files needed for the Zope 4 ZMI.""" | ||
return ( | ||
'/++resource++zmi/bootstrap-4.6.0/bootstrap.min.css', | ||
'/++resource++zmi/fontawesome-free-5.15.2/css/all.css', | ||
'/++resource++zmi/zmi_base.css', | ||
prepend_authentication_path(context.REQUEST, path) | ||
for path in ( | ||
'/++resource++zmi/bootstrap-4.6.0/bootstrap.min.css', | ||
'/++resource++zmi/fontawesome-free-5.15.2/css/all.css', | ||
'/++resource++zmi/zmi_base.css', | ||
) | ||
) | ||
|
||
|
||
@zope.component.adapter(zope.interface.Interface) | ||
def js_paths(context): | ||
"""Return paths to JS files needed for the Zope 4 ZMI.""" | ||
return ( | ||
'/++resource++zmi/jquery-3.5.1.min.js', | ||
'/++resource++zmi/bootstrap-4.6.0/bootstrap.bundle.min.js', | ||
'/++resource++zmi/ace.ajax.org/ace.js', | ||
'/++resource++zmi/zmi_base.js', | ||
prepend_authentication_path(context.REQUEST, path) | ||
for path in ( | ||
'/++resource++zmi/jquery-3.5.1.min.js', | ||
'/++resource++zmi/bootstrap-4.6.0/bootstrap.bundle.min.js', | ||
'/++resource++zmi/ace.ajax.org/ace.js', | ||
'/++resource++zmi/zmi_base.js', | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters