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 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: 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. 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: if contact:
raise ErrContactAlreadyExists(contact) raise ErrContactAlreadyExists(contact)
if config.DISABLE_CREATE_CONTACTS_FOR_FREE_USERS and ( if not user_can_create_contacts(user):
not user.is_premium() and user.flags & User.FLAG_FREE_DISABLE_CREATE_ALIAS > 0
):
raise ErrContactErrorUpgradeNeeded() raise ErrContactErrorUpgradeNeeded()
contact = Contact.create( contact = Contact.create(
@ -312,4 +319,5 @@ def alias_contact_manager(alias_id):
last_page=last_page, last_page=last_page,
query=query, query=query,
nb_contact=nb_contact, nb_contact=nb_contact,
can_create_contacts=user_can_create_contacts(current_user),
) )

View file

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