From e82416882bdbee113f91796805093483b67bc0ab Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Sun, 1 Oct 2017 12:18:48 +0200 Subject: [PATCH] bugfix in deferred_unique_email_validator --- ordr2/resources/account.py | 5 +++++ ordr2/schemas/helpers.py | 5 ++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/ordr2/resources/account.py b/ordr2/resources/account.py index 9ad2888..ced05c0 100644 --- a/ordr2/resources/account.py +++ b/ordr2/resources/account.py @@ -5,6 +5,11 @@ from .base import BaseResource class Account(BaseResource): + def __init__(self, name, parent): + super().__init__(name, parent) + self.model = self.request.user + + def __acl__(self): return [ (Allow, Everyone, 'login'), diff --git a/ordr2/schemas/helpers.py b/ordr2/schemas/helpers.py index bed69a2..5f20119 100644 --- a/ordr2/schemas/helpers.py +++ b/ordr2/schemas/helpers.py @@ -44,10 +44,9 @@ def deferred_unique_email_validator(node, kw): email_validator(node, value) # raises exception on invalid address request = kw.get('request') user = request.dbsession.query(User).filter_by(email=value).first() - if user not in (request.user, request.context.model): + if user not in (None, request.context.model): # allow existing email addresses if - # it belongs to the current logged in user or - # an administrator edits a user + # it belongs to the user that is currently edited raise colander.Invalid(node, 'Email address in use') return validate_unique_email