-
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.
Fix authentication error viewing ZMI resource with virtual hosting (#…
…1204) * 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. * ZMI: use /++resource++logo/ for public resources /++resource++zmi/logo/ and /++resource++logo/ is the same folder on disk, the former is protected by Manage portal and the later is public. Protected resources were problematic, because we want to serve them from the root, but the manager user might not have permission on the root. * ZMI: include zmi.localstorage.api.js using js subscriber Using this approach we serve a resource relative to the path where user is authenticated. * copyright.dtml: update bootstrap URL This was referencing an old URL. Co-authored-by: Maurits van Rees <[email protected]>
- Loading branch information
1 parent
22adba1
commit 2e49bac
Showing
9 changed files
with
173 additions
and
48 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
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
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,63 @@ | ||
import itertools | ||
|
||
import zope.component | ||
import zope.interface | ||
from AccessControl.SecurityManagement import getSecurityManager | ||
from Acquisition import aq_parent | ||
|
||
|
||
def prepend_authentication_path(context, path): | ||
"""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. | ||
""" | ||
request = getattr(context, 'REQUEST', None) | ||
if request is None: | ||
return path | ||
user_folder = aq_parent(getSecurityManager().getUser()) | ||
if user_folder is None: | ||
return path | ||
# prepend the authentication path, unless it is already part of the | ||
# virtual host root. | ||
authentication_path = [] | ||
ufpp = aq_parent(user_folder).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, 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, 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', | ||
'/++resource++zmi/zmi.localstorage.api.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