Show warning when extra fees may be applied on mailbox creation

This commit is contained in:
Santiago L 2021-10-05 13:31:09 +02:00
parent 9e51457069
commit 9b52bc4b92
3 changed files with 25 additions and 1 deletions

View file

@ -129,6 +129,10 @@ class UserAccount(OrchestraModel):
return super().new_from_json(data=data, billing=billing, language=language, last_login=last_login)
def allowed_resources(self, resource):
allowed_by_type = musician_settings.ALLOWED_RESOURCES[self.type]
return allowed_by_type[resource]
class DatabaseUser(OrchestraModel):
api_name = 'databaseusers'

View file

@ -4,6 +4,15 @@
{% block content %}
<h1 class="service-name">{{ service.verbose_name }}</h1>
{% if extra_mailbox %}
<div class="alert alert-warning alert-dismissible fade show" role="alert">
<strong>{% trans "Warning!" %}</strong> {% trans "You have reached the limit of mailboxes of your subscription so <strong>extra fees</strong> may apply." %}
<button type="button" class="close" data-dismiss="alert" aria-label="{% trans 'Close' %}">
<span aria-hidden="true">&times;</span>
</button>
</div>
{% endif %}
<form method="post">
{% csrf_token %}
{% bootstrap_form form %}

View file

@ -325,7 +325,18 @@ class MailboxCreateView(CustomContextMixin, UserTokenRequiredMixin, FormView):
template_name = "musician/mailbox_form.html"
form_class = MailboxCreateForm
success_url = reverse_lazy("musician:mailbox-list")
extra_context = {'service': service_class}
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
context.update({
'extra_mailbox': self.is_extra_mailbox(context['profile']),
'service': self.service_class,
})
return context
def is_extra_mailbox(self, profile):
number_of_mailboxes = len(self.orchestra.retrieve_mailbox_list())
return number_of_mailboxes >= profile.allowed_resources('mailbox')
def form_valid(self, form):
serialized_data = form.serialize()