allow control of question group selection in subclass; provide principal/person also if request is not given
This commit is contained in:
parent
dbc91c7e6f
commit
146b1c78aa
2 changed files with 19 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
#
|
||||
# Copyright (c) 2013 Helmut Merz helmutm@cy55.de
|
||||
# Copyright (c) 2015 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -46,6 +46,9 @@ class Questionnaire(AdapterBase, Questionnaire):
|
|||
|
||||
@property
|
||||
def questionGroups(self):
|
||||
return self.getQuestionGroups()
|
||||
|
||||
def getQuestionGroups(self):
|
||||
return [adapted(c) for c in self.context.getChildren()]
|
||||
|
||||
@property
|
||||
|
|
|
@ -24,6 +24,7 @@ from persistent.mapping import PersistentMapping
|
|||
from zope import interface, component
|
||||
from zope.app.principalannotation import annotations
|
||||
from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
|
||||
from zope.app.security.interfaces import IUnauthenticatedPrincipal
|
||||
from zope.component import adapts
|
||||
from zope.interface import implements
|
||||
from zope.cachedescriptors.property import Lazy
|
||||
|
@ -44,6 +45,7 @@ from loops.predicate import RelationAdapter
|
|||
from loops.predicate import PredicateInterfaceSourceList
|
||||
from loops.security.common import assignOwner, removeOwner, allowEditingForOwner
|
||||
from loops.security.common import assignPersonRole, removePersonRole
|
||||
from loops.security.common import getCurrentPrincipal
|
||||
from loops.security.interfaces import ISecuritySetter
|
||||
from loops.type import TypeInterfaceSourceList
|
||||
from loops import util
|
||||
|
@ -59,7 +61,10 @@ def getPersonForUser(context, request=None, principal=None):
|
|||
if context is None:
|
||||
return None
|
||||
if principal is None:
|
||||
principal = getattr(request, 'principal', None)
|
||||
if request is not None:
|
||||
principal = getattr(request, 'principal', None)
|
||||
else:
|
||||
principal = getPrincipal(context)
|
||||
if principal is None:
|
||||
return None
|
||||
loops = context.getLoopsRoot()
|
||||
|
@ -74,6 +79,15 @@ def getPersonForUser(context, request=None, principal=None):
|
|||
return pa.get(util.getUidForObject(loops))
|
||||
|
||||
|
||||
def getPrincipal(context):
|
||||
principal = getCurrentPrincipal()
|
||||
if principal is not None:
|
||||
if IUnauthenticatedPrincipal.providedBy(principal):
|
||||
return None
|
||||
return principal
|
||||
return None
|
||||
|
||||
|
||||
class Person(AdapterBase, BasePerson):
|
||||
""" typeInterface adapter for concepts of type 'person'.
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue