Simplified method

This commit is contained in:
Adrià Casajús 2022-05-12 18:33:13 +02:00
parent 4d07bc9d31
commit 9066116b7e
No known key found for this signature in database
GPG Key ID: F0033226A5AFC9B9
2 changed files with 4 additions and 6 deletions

View File

@ -8,6 +8,7 @@ from flask_wtf import FlaskForm
from sqlalchemy import and_, func, case
from wtforms import StringField, validators, ValidationError
# Need to import directly from config to allow modification from the tests
from app import config
from app.dashboard.base import dashboard_bp
from app.db import Session
@ -49,9 +50,7 @@ def email_validator():
return _check
def create_contact(
user: User, alias: Alias, contact_address: str, fail_if_already_exist: bool = True
) -> Contact:
def create_contact(user: User, alias: Alias, contact_address: str) -> Contact:
if not contact_address:
raise ErrAddressInvalid("Empty address")
try:
@ -64,9 +63,7 @@ def create_contact(
contact = Contact.get_by(alias_id=alias.id, website_email=contact_email)
if contact:
if fail_if_already_exist:
raise ErrContactAlreadyExists(contact)
return contact
raise ErrContactAlreadyExists(contact)
if config.DISABLE_CREATE_CONTACTS_FOR_FREE_USERS and (
not user.is_premium() and user.flags & User.FLAG_FREE_DISABLE_CREATE_ALIAS > 0

View File

@ -1,6 +1,7 @@
from flask import url_for
import arrow
# Need to import directly from config to allow modification from the tests
from app import config
from app.db import Session
from app.email_utils import is_reverse_alias