def _user_from_avatar(self, avatar, **kwargs): email = sanitize_email( convert_to_unicode(avatar.email).lower().strip()) secondary_emails = { sanitize_email(convert_to_unicode(x).lower().strip()) for x in avatar.secondaryEmails } secondary_emails = { x for x in secondary_emails if x and is_valid_mail(x, False) and x != email } # we handle deletion later. otherwise it might be set before secondary_emails which would # result in those emails not being marked as deleted is_deleted = kwargs.pop('is_deleted', False) user = User( id=int(avatar.id), email=email, first_name=convert_to_unicode(avatar.name).strip() or 'UNKNOWN', last_name=convert_to_unicode(avatar.surName).strip() or 'UNKNOWN', title=USER_TITLE_MAP.get(avatar.title, UserTitle.none), phone=convert_to_unicode(avatar.telephone[0]).strip(), affiliation=convert_to_unicode(avatar.organisation[0]).strip(), address=convert_to_unicode(avatar.address[0]).strip(), secondary_emails=secondary_emails, is_blocked=avatar.status == 'disabled', **kwargs) if is_deleted or not is_valid_mail(user.email): user.is_deleted = True return user
def test_deletion_no_primary_email(): # this tests setting the is_deleted property on a user with no primary email # very unlikely case but let's make sure we never try to set the deleted # flag on a None primary email. user = User() assert user.email is None user.is_deleted = True
def test_deletion(db): user = User(first_name='Guinea', last_name='Pig', email='*****@*****.**', secondary_emails=['[email protected]']) db.session.add(user) db.session.flush() assert not user.is_deleted assert all(not ue.is_user_deleted for ue in user._all_emails) user.is_deleted = True db.session.flush() assert all(ue.is_user_deleted for ue in user._all_emails)
def _user_from_avatar(self, avatar, **kwargs): email = sanitize_email(convert_to_unicode(avatar.email).lower().strip()) secondary_emails = {sanitize_email(convert_to_unicode(x).lower().strip()) for x in avatar.secondaryEmails} secondary_emails = {x for x in secondary_emails if x and is_valid_mail(x, False) and x != email} # we handle deletion later. otherwise it might be set before secondary_emails which would # result in those emails not being marked as deleted is_deleted = kwargs.pop('is_deleted', False) user = User(id=int(avatar.id), email=email, first_name=convert_to_unicode(avatar.name).strip() or 'UNKNOWN', last_name=convert_to_unicode(avatar.surName).strip() or 'UNKNOWN', title=USER_TITLE_MAP.get(avatar.title, UserTitle.none), phone=convert_to_unicode(avatar.telephone[0]).strip(), affiliation=convert_to_unicode(avatar.organisation[0]).strip(), address=convert_to_unicode(avatar.address[0]).strip(), secondary_emails=secondary_emails, is_blocked=avatar.status == 'disabled', **kwargs) if is_deleted or not is_valid_mail(user.email): user.is_deleted = True return user