free trial account can't create more than MAX_NB_EMAIL_FREE_PLAN aliases

This commit is contained in:
Son NK 2021-04-09 12:40:55 +02:00
parent 95c8f14ea5
commit aad1270e0d
3 changed files with 26 additions and 22 deletions

View file

@ -99,7 +99,7 @@ def get_available_suffixes(user: User) -> [SuffixInfo]:
def custom_alias():
# check if user has not exceeded the alias quota
if not current_user.can_create_new_alias():
LOG.warning("user %s tries to create custom alias", current_user)
LOG.d("%s can't create new alias", current_user)
flash(
"You have reached free plan limit, please upgrade to create new aliases",
"warning",

View file

@ -81,22 +81,21 @@ def import_from_csv(batch_import: BatchImport, user: User, lines):
if len(mailboxes) == 0:
mailboxes = [user.default_mailbox_id]
alias = Alias.create(
user_id=user.id,
email=full_alias,
note=note,
mailbox_id=mailboxes[0],
custom_domain_id=custom_domain.id,
batch_import_id=batch_import.id,
)
db.session.commit()
db.session.flush()
LOG.d("Create %s", alias)
for i in range(1, len(mailboxes)):
alias_mailbox = AliasMailbox.create(
alias_id=alias.id,
mailbox_id=mailboxes[i],
if user.can_create_new_alias():
alias = Alias.create(
user_id=user.id,
email=full_alias,
note=note,
mailbox_id=mailboxes[0],
custom_domain_id=custom_domain.id,
batch_import_id=batch_import.id,
commit=True,
)
db.session.commit()
LOG.d("Create %s", alias_mailbox)
LOG.d("Create %s", alias)
for i in range(1, len(mailboxes)):
AliasMailbox.create(
alias_id=alias.id, mailbox_id=mailboxes[i], commit=True
)
db.session.commit()
LOG.d("Add %s to mailbox %s", alias, mailboxes[i])

View file

@ -25,6 +25,7 @@ from app.config import (
FIRST_ALIAS_DOMAIN,
DISABLE_ONBOARDING,
UNSUBSCRIBER,
MAX_ALIAS_PER_HOUR,
)
from app.errors import AliasInTrashError
from app.extensions import db
@ -504,10 +505,14 @@ class User(db.Model, ModelMixin, UserMixin):
return "N/A"
def can_create_new_alias(self) -> bool:
if self.is_premium():
"""
Whether user can create a new alias. User can't create a new alias if
- has more than 15 aliases in the free plan, *even in the free trial*
"""
if self._lifetime_or_active_subscription():
return True
return Alias.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN
else:
return Alias.filter_by(user_id=self.id).count() < MAX_NB_EMAIL_FREE_PLAN
def set_password(self, password):
salt = bcrypt.gensalt()