mirror of
https://github.com/simple-login/app.git
synced 2024-11-13 07:31:12 +01:00
Allow to create pre-verified mailboxes
This commit is contained in:
parent
5b784e8989
commit
2478def834
3 changed files with 38 additions and 23 deletions
|
@ -28,8 +28,9 @@ MAX_ACTIVATION_TRIES = 3
|
|||
def create_mailbox(
|
||||
user: User,
|
||||
email: str,
|
||||
verified: bool = False,
|
||||
use_digit_codes: bool = False,
|
||||
send_verification_link: bool = True,
|
||||
send_link: bool = True,
|
||||
) -> Mailbox:
|
||||
if not user.is_premium():
|
||||
LOG.i(
|
||||
|
@ -51,15 +52,20 @@ def create_mailbox(
|
|||
f"User {user} has tried to create mailbox with {email} but email is invalid"
|
||||
)
|
||||
raise MailboxError("Invalid email")
|
||||
new_mailbox = Mailbox.create(email=email, user_id=user.id, commit=True)
|
||||
|
||||
LOG.i(f"User {user} has created mailbox with {email}")
|
||||
send_verification_email(
|
||||
user,
|
||||
new_mailbox,
|
||||
use_digit_code=use_digit_codes,
|
||||
send_link=send_verification_link,
|
||||
new_mailbox = Mailbox.create(
|
||||
email=email, user_id=user.id, verified=verified, commit=True
|
||||
)
|
||||
|
||||
if verified:
|
||||
LOG.i(f"User {user} as created a pre-verified mailbox with {email}")
|
||||
else:
|
||||
LOG.i(f"User {user} has created mailbox with {email}")
|
||||
send_verification_email(
|
||||
user,
|
||||
new_mailbox,
|
||||
use_digit_code=use_digit_codes,
|
||||
send_link=send_link,
|
||||
)
|
||||
return new_mailbox
|
||||
|
||||
|
||||
|
|
|
@ -68,12 +68,23 @@ def test_create_mailbox():
|
|||
assert mail_sent.envelope_to == email
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_create_mailbox_verified():
|
||||
email = random_email()
|
||||
mailbox_utils.create_mailbox(user, email, verified=True)
|
||||
mailbox = Mailbox.get_by(email=email)
|
||||
assert mailbox is not None
|
||||
assert mailbox.verified
|
||||
activation = MailboxActivation.get_by(mailbox_id=mailbox.id)
|
||||
assert activation is None
|
||||
|
||||
assert 0 == len(mail_sender.get_stored_emails())
|
||||
|
||||
|
||||
@mail_sender.store_emails_test_decorator
|
||||
def test_create_mailbox_with_digits():
|
||||
email = random_email()
|
||||
mailbox_utils.create_mailbox(
|
||||
user, email, use_digit_codes=True, send_verification_link=False
|
||||
)
|
||||
mailbox_utils.create_mailbox(user, email, use_digit_codes=True, send_link=False)
|
||||
mailbox = Mailbox.get_by(email=email)
|
||||
assert mailbox is not None
|
||||
assert not mailbox.verified
|
||||
|
@ -93,9 +104,7 @@ def test_create_mailbox_with_digits():
|
|||
@mail_sender.store_emails_test_decorator
|
||||
def test_send_verification_email():
|
||||
email = random_email()
|
||||
mailbox_utils.create_mailbox(
|
||||
user, email, use_digit_codes=True, send_verification_link=False
|
||||
)
|
||||
mailbox_utils.create_mailbox(user, email, use_digit_codes=True, send_link=False)
|
||||
mailbox = Mailbox.get_by(email=email)
|
||||
activation = MailboxActivation.get_by(mailbox_id=mailbox.id)
|
||||
old_code = activation.code
|
||||
|
@ -121,7 +130,7 @@ def test_delete_default_mailbox():
|
|||
def test_transfer_to_same_mailbox():
|
||||
email = random_email()
|
||||
mailbox = mailbox_utils.create_mailbox(
|
||||
user, email, use_digit_codes=True, send_verification_link=False
|
||||
user, email, use_digit_codes=True, send_link=False
|
||||
)
|
||||
with pytest.raises(mailbox_utils.MailboxError):
|
||||
mailbox_utils.delete_mailbox(user, mailbox.id, transfer_mailbox_id=mailbox.id)
|
||||
|
@ -130,7 +139,7 @@ def test_transfer_to_same_mailbox():
|
|||
def test_transfer_to_other_users_mailbox():
|
||||
email = random_email()
|
||||
mailbox = mailbox_utils.create_mailbox(
|
||||
user, email, use_digit_codes=True, send_verification_link=False
|
||||
user, email, use_digit_codes=True, send_link=False
|
||||
)
|
||||
other = create_new_user()
|
||||
other_mailbox = Mailbox.create(user_id=other.id, email=random_email(), commit=True)
|
||||
|
@ -143,7 +152,7 @@ def test_transfer_to_other_users_mailbox():
|
|||
def test_delete_with_no_transfer():
|
||||
email = random_email()
|
||||
mailbox = mailbox_utils.create_mailbox(
|
||||
user, email, use_digit_codes=True, send_verification_link=False
|
||||
user, email, use_digit_codes=True, send_link=False
|
||||
)
|
||||
mailbox_utils.delete_mailbox(user, mailbox.id, transfer_mailbox_id=None)
|
||||
job = Session.query(Job).order_by(Job.id.desc()).first()
|
||||
|
@ -155,10 +164,10 @@ def test_delete_with_no_transfer():
|
|||
|
||||
def test_delete_with_transfer():
|
||||
mailbox = mailbox_utils.create_mailbox(
|
||||
user, random_email(), use_digit_codes=True, send_verification_link=False
|
||||
user, random_email(), use_digit_codes=True, send_link=False
|
||||
)
|
||||
transfer_mailbox = mailbox_utils.create_mailbox(
|
||||
user, random_email(), use_digit_codes=True, send_verification_link=False
|
||||
user, random_email(), use_digit_codes=True, send_link=False
|
||||
)
|
||||
mailbox_utils.delete_mailbox(
|
||||
user, mailbox.id, transfer_mailbox_id=transfer_mailbox.id
|
||||
|
|
|
@ -29,7 +29,7 @@ def test_set_default_mailbox():
|
|||
other,
|
||||
random_email(),
|
||||
use_digit_codes=True,
|
||||
send_verification_link=False,
|
||||
send_link=False,
|
||||
)
|
||||
mailbox.verified = True
|
||||
Session.commit()
|
||||
|
@ -43,7 +43,7 @@ def test_cannot_set_unverified():
|
|||
user,
|
||||
random_email(),
|
||||
use_digit_codes=True,
|
||||
send_verification_link=False,
|
||||
send_link=False,
|
||||
)
|
||||
with pytest.raises(user_settings.CannotSetMailbox):
|
||||
user_settings.set_default_mailbox(user, mailbox.id)
|
||||
|
@ -55,7 +55,7 @@ def test_cannot_default_other_user_mailbox():
|
|||
other,
|
||||
random_email(),
|
||||
use_digit_codes=True,
|
||||
send_verification_link=False,
|
||||
send_link=False,
|
||||
)
|
||||
with pytest.raises(user_settings.CannotSetMailbox):
|
||||
user_settings.set_default_mailbox(user, mailbox.id)
|
||||
|
|
Loading…
Reference in a new issue