rename can_create_custom_email -> can_create_new_custom_alias, can_create_new_email -> can_create_new_random_alias

This commit is contained in:
Son NK 2019-12-03 23:43:13 +00:00
parent 6764a4b582
commit c58d9052e7
6 changed files with 12 additions and 12 deletions

View File

@ -14,7 +14,7 @@ from app.utils import convert_to_id, random_string
@login_required
def custom_alias():
# check if user has the right to create custom alias
if not current_user.can_create_custom_email():
if not current_user.can_create_new_custom_alias():
# notify admin
LOG.error("user %s tries to create custom alias", current_user)
flash("ony premium user can choose custom alias", "warning")

View File

@ -50,9 +50,9 @@ def index():
)
elif request.form.get("form-name") == "create-random-email":
can_create_new_email = current_user.can_create_new_email()
can_create_new_random_alias = current_user.can_create_new_random_alias()
if can_create_new_email:
if can_create_new_random_alias:
gen_email = GenEmail.create_new_gen_email(user_id=current_user.id)
db.session.commit()
@ -66,7 +66,7 @@ def index():
)
elif request.form.get("form-name") == "create-custom-email":
if current_user.can_create_custom_email():
if current_user.can_create_new_custom_alias():
return redirect(url_for("dashboard.custom_alias"))
else:
flash(

View File

@ -134,7 +134,7 @@ class User(db.Model, ModelMixin, UserMixin):
return False
def can_create_custom_email(self):
def can_create_new_custom_alias(self):
if self.is_premium():
return True
@ -143,7 +143,7 @@ class User(db.Model, ModelMixin, UserMixin):
< MAX_NB_EMAIL_FREE_PLAN
)
def can_create_new_email(self):
def can_create_new_random_alias(self):
if self.is_premium():
return True
else:
@ -171,7 +171,7 @@ class User(db.Model, ModelMixin, UserMixin):
def suggested_emails(self) -> (str, [str]):
"""return suggested email and other email choices """
all_gen_emails = [ge.email for ge in GenEmail.filter_by(user_id=self.id)]
if self.can_create_new_email():
if self.can_create_new_random_alias():
# create a new email
suggested_gen_email = generate_email()
else:

View File

@ -90,7 +90,7 @@
{% endfor %}
</select>
{% if current_user.can_create_custom_email() %}
{% if current_user.can_create_new_custom_alias() %}
<div class="mt-2">OR</div>
<div style="display: flex; align-items: center" class="mt-2">
<input class="form-control"

View File

@ -151,7 +151,7 @@ def authorize():
gen_email = None
if custom_email_prefix:
# check if user can generate custom email
if not current_user.can_create_custom_email():
if not current_user.can_create_new_custom_alias():
raise Exception(f"User {current_user} cannot create custom email")
email = f"{convert_to_id(custom_email_prefix)}.{email_suffix}@{EMAIL_DOMAIN}"
@ -273,9 +273,9 @@ def authorize():
def create_or_choose_gen_email(user) -> GenEmail:
can_create_new_email = user.can_create_new_email()
can_create_new_random_alias = user.can_create_new_random_alias()
if can_create_new_email:
if can_create_new_random_alias:
gen_email = GenEmail.create_new_gen_email(user_id=user.id)
db.session.flush()
LOG.debug("generate email %s for user %s", gen_email.email, user)

View File

@ -19,7 +19,7 @@ def test_profile_picture_url(flask_client):
assert user.profile_picture_url() == "http://sl.test/static/default-avatar.png"
def test_suggested_emails_for_user_who_can_create_new_email(flask_client):
def test_suggested_emails_for_user_who_can_create_new_random_alias(flask_client):
user = User.create(
email="a@b.c", password="password", name="Test User", activated=True
)