Update html

This commit is contained in:
Adrià Casajús 2022-05-12 18:46:42 +02:00
parent bfb1ae6371
commit 0c896100a4
No known key found for this signature in database
GPG key ID: F0033226A5AFC9B9
2 changed files with 12 additions and 4 deletions

View file

@ -51,6 +51,15 @@ def email_validator():
return _check
def user_can_create_contacts(user: User) -> bool:
if user.is_premium():
return True
return (
config.DISABLE_CREATE_CONTACTS_FOR_FREE_USERS
and user.flags & User.FLAG_FREE_DISABLE_CREATE_ALIAS > 0
)
def create_contact(user: User, alias: Alias, contact_address: str) -> Contact:
"""
Create a contact for a user. Can be restricted for new free users by enabling DISABLE_CREATE_CONTACTS_FOR_FREE_USERS.
@ -74,9 +83,7 @@ def create_contact(user: User, alias: Alias, contact_address: str) -> Contact:
if 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
):
if not user_can_create_contacts(user):
raise ErrContactErrorUpgradeNeeded()
contact = Contact.create(
@ -312,4 +319,5 @@ def alias_contact_manager(alias_id):
last_page=last_page,
query=query,
nb_contact=nb_contact,
can_create_contacts=user_can_create_contacts(current_user),
)

View file

@ -64,7 +64,7 @@
<div class="small-text">
Where do you want to send the email?
</div>
{% if alias.user.is_premium() %}
{% if can_create_contacts %}
<button class="btn btn-primary mt-2">Create reverse-alias</button>
{% else %}
<button disabled title='Upgrade to premium to create reverse-aliases' class="btn btn-primary mt-2">Create reverse-alias</button>