Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect to nearest public ancestor if page is private. #1

Open
wants to merge 3 commits into
base: python3
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion Products/AutoUserMakerPASPlugin/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
from Products.PluggableAuthService.utils import classImplements
from random import choice
from ZODB.POSException import ConflictError
from zope.security import checkPermission

import itertools
import re
Expand Down Expand Up @@ -268,7 +269,33 @@ def loginUrl(self, currentUrl):
def challenge(self, request, response):
# Just Start a challenge, if not logged yet
if request.getHeader(httpRemoteUserKey, None) == None:
url = self.loginUrl(request.ACTUAL_URL)
url = None

# try to redirect to a public parent
parents = request.get('PARENTS', [])

# the first element is the object itself. so we skip that.
if len(parents) > 1:
public_parent = None

obj = parents[0]
anon_redirect_link = getattr(obj, 'anon_redirect_link', None)
if anon_redirect_link:
response.redirect(anon_redirect_link, lock=True)
return True

for parent in parents[1:]:
perm = checkPermission('zope2.View', parent)
if perm:
public_parent = parent
break

if public_parent:
url = public_parent.absolute_url()

# redirect to login-view if no parents found.
if not url:
url = self.loginUrl(request.ACTUAL_URL)
if url:
response.redirect(url, lock=True)
return True
Expand Down