allow control of question group selection in subclass; provide principal/person also if request is not given

This commit is contained in:
Helmut Merz 2015-07-16 15:58:33 +02:00
parent dbc91c7e6f
commit 146b1c78aa
2 changed files with 19 additions and 2 deletions

View file

@ -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 # 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 # it under the terms of the GNU General Public License as published by
@ -46,6 +46,9 @@ class Questionnaire(AdapterBase, Questionnaire):
@property @property
def questionGroups(self): def questionGroups(self):
return self.getQuestionGroups()
def getQuestionGroups(self):
return [adapted(c) for c in self.context.getChildren()] return [adapted(c) for c in self.context.getChildren()]
@property @property

View file

@ -24,6 +24,7 @@ from persistent.mapping import PersistentMapping
from zope import interface, component from zope import interface, component
from zope.app.principalannotation import annotations from zope.app.principalannotation import annotations
from zope.app.security.interfaces import IAuthentication, PrincipalLookupError from zope.app.security.interfaces import IAuthentication, PrincipalLookupError
from zope.app.security.interfaces import IUnauthenticatedPrincipal
from zope.component import adapts from zope.component import adapts
from zope.interface import implements from zope.interface import implements
from zope.cachedescriptors.property import Lazy from zope.cachedescriptors.property import Lazy
@ -44,6 +45,7 @@ from loops.predicate import RelationAdapter
from loops.predicate import PredicateInterfaceSourceList from loops.predicate import PredicateInterfaceSourceList
from loops.security.common import assignOwner, removeOwner, allowEditingForOwner from loops.security.common import assignOwner, removeOwner, allowEditingForOwner
from loops.security.common import assignPersonRole, removePersonRole from loops.security.common import assignPersonRole, removePersonRole
from loops.security.common import getCurrentPrincipal
from loops.security.interfaces import ISecuritySetter from loops.security.interfaces import ISecuritySetter
from loops.type import TypeInterfaceSourceList from loops.type import TypeInterfaceSourceList
from loops import util from loops import util
@ -59,7 +61,10 @@ def getPersonForUser(context, request=None, principal=None):
if context is None: if context is None:
return None return None
if principal is None: if principal is None:
if request is not None:
principal = getattr(request, 'principal', None) principal = getattr(request, 'principal', None)
else:
principal = getPrincipal(context)
if principal is None: if principal is None:
return None return None
loops = context.getLoopsRoot() loops = context.getLoopsRoot()
@ -74,6 +79,15 @@ def getPersonForUser(context, request=None, principal=None):
return pa.get(util.getUidForObject(loops)) 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): class Person(AdapterBase, BasePerson):
""" typeInterface adapter for concepts of type 'person'. """ typeInterface adapter for concepts of type 'person'.
""" """