From c58d9052e76f67008c5a475c0a080c9a813f9300 Mon Sep 17 00:00:00 2001 From: Son NK Date: Tue, 3 Dec 2019 23:43:13 +0000 Subject: [PATCH] rename can_create_custom_email -> can_create_new_custom_alias, can_create_new_email -> can_create_new_random_alias --- app/dashboard/views/custom_alias.py | 2 +- app/dashboard/views/index.py | 6 +++--- app/models.py | 6 +++--- app/oauth/templates/oauth/authorize.html | 2 +- app/oauth/views/authorize.py | 6 +++--- tests/test_models.py | 2 +- 6 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/dashboard/views/custom_alias.py b/app/dashboard/views/custom_alias.py index fec1be7a..d1272bbc 100644 --- a/app/dashboard/views/custom_alias.py +++ b/app/dashboard/views/custom_alias.py @@ -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") diff --git a/app/dashboard/views/index.py b/app/dashboard/views/index.py index 56503804..02365a64 100644 --- a/app/dashboard/views/index.py +++ b/app/dashboard/views/index.py @@ -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( diff --git a/app/models.py b/app/models.py index b4445001..6cc06053 100644 --- a/app/models.py +++ b/app/models.py @@ -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: diff --git a/app/oauth/templates/oauth/authorize.html b/app/oauth/templates/oauth/authorize.html index b44636bb..259ef663 100644 --- a/app/oauth/templates/oauth/authorize.html +++ b/app/oauth/templates/oauth/authorize.html @@ -90,7 +90,7 @@ {% endfor %} - {% if current_user.can_create_custom_email() %} + {% if current_user.can_create_new_custom_alias() %}
OR
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) diff --git a/tests/test_models.py b/tests/test_models.py index 7ea6faff..e80e58e0 100644 --- a/tests/test_models.py +++ b/tests/test_models.py @@ -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 )