Biling page: moved user classification logic from template → view code
This is the kind of stuff that's much easier expressed in Python than in the template code. API calls removed: - fetching the user isn't necessary, since we have pillar.auth.current_user anyway. - a call for each group the user is member of, since we only used it to check whether the user has demo access anyway.
This commit is contained in:
@@ -347,25 +347,45 @@ def billing():
|
||||
"""
|
||||
from . import store
|
||||
|
||||
log.debug('START OF REQUEST')
|
||||
|
||||
if current_user.has_role('protected'):
|
||||
return abort(404) # TODO: make this 403, handle template properly
|
||||
api = system_util.pillar_api()
|
||||
user = User.find(current_user.objectid, api=api)
|
||||
groups = []
|
||||
if user.groups:
|
||||
for group_id in user.groups:
|
||||
group = Group.find(group_id, api=api)
|
||||
groups.append(group.name)
|
||||
|
||||
store_user = store.fetch_subscription_info(user.email)
|
||||
if store_user is None:
|
||||
expiration_date = 'Unable to reach Blender Store to check'
|
||||
expiration_date = 'No subscription to expire'
|
||||
|
||||
# Classify the user based on their roles and capabilities
|
||||
cap_subs = current_user.has_cap('subscriber')
|
||||
if current_user.has_role('demo'):
|
||||
user_cls = 'demo'
|
||||
elif not cap_subs and current_user.has_cap('can-renew-subscription'):
|
||||
# This user has an inactive but renewable subscription.
|
||||
user_cls = 'subscriber-expired'
|
||||
elif cap_subs:
|
||||
if current_user.has_role('subscriber'):
|
||||
# This user pays for their own subscription. Only in this case do we need to fetch
|
||||
# the expiration date from the Store.
|
||||
user_cls = 'subscriber'
|
||||
store_user = store.fetch_subscription_info(current_user.email)
|
||||
if store_user is None:
|
||||
expiration_date = 'Unable to reach Blender Store to check'
|
||||
else:
|
||||
expiration_date = store_user['expiration_date'][:10]
|
||||
|
||||
elif current_user.has_role('org-subscriber'):
|
||||
# An organisation pays for this subscription.
|
||||
user_cls = 'subscriber-org'
|
||||
else:
|
||||
# This user gets the subscription cap from somewhere else (like an organisation).
|
||||
user_cls = 'subscriber-other'
|
||||
else:
|
||||
expiration_date = store_user['expiration_date'][:10]
|
||||
user_cls = 'outsider'
|
||||
|
||||
return render_template(
|
||||
'users/settings/billing.html',
|
||||
expiration_date=expiration_date, groups=groups, title='billing')
|
||||
user_cls=user_cls,
|
||||
expiration_date=expiration_date,
|
||||
title='billing')
|
||||
|
||||
|
||||
@blueprint.route('/terms-and-conditions')
|
||||
|
@@ -9,16 +9,30 @@ style(type='text/css').
|
||||
|
||||
| {% block settings_page_title %}Subscription{% endblock %}
|
||||
| {% block settings_page_content %}
|
||||
| {% set renew_url = url_for('cloud.renew_subscription') %}
|
||||
| {% if current_user.has_cap('can-renew-subscription') %}
|
||||
| {% if current_user.has_cap('subscriber') %}
|
||||
h3.subscription-active
|
||||
i.pi-check
|
||||
| Your subscription is active
|
||||
h4 Thank you for supporting us!
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
| {% if user_cls == 'demo' %}
|
||||
h3.subscription-demo
|
||||
i.pi-heart-filled
|
||||
| You have a free account
|
||||
hr
|
||||
p Subscription expires on: <strong>{{ expiration_date }}</strong>
|
||||
| {% else %}
|
||||
p.
|
||||
You have full access to the Blender Cloud, provided by the Blender Institute. This account is
|
||||
meant for free evaluation of the service. Get in touch with
|
||||
#[a(href="mailto:cloudsupport@blender.org") cloudsupport@blender.org] if you have any questions.
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
| {% elif user_cls == 'outsider' %}
|
||||
h3.subscription-missing
|
||||
i.pi-info
|
||||
| You do not have an active subscription.
|
||||
hr
|
||||
h3
|
||||
a(href="https://store.blender.org/product/membership/") Get full access to Blender Cloud now!
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
| {% elif user_cls == 'subscriber-expired' %}
|
||||
| {% set renew_url = url_for('cloud.renew_subscription') %}
|
||||
h3.subscription-missing
|
||||
i.pi-info
|
||||
a(href="{{renew_url}}") Your subscription can be renewed
|
||||
@@ -26,26 +40,27 @@ hr
|
||||
p.text-danger Subscription expired on: <strong>{{ expiration_date }}</strong>
|
||||
p
|
||||
a.btn.btn-success(href="{{renew_url}}") Renew now
|
||||
| {% endif %}
|
||||
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
| {% elif current_user.has_cap('subscriber') %}
|
||||
h3.subscription-active
|
||||
i.pi-check
|
||||
| Your subscription is active
|
||||
|
||||
//---------------------------------
|
||||
| {% if user_cls == 'subscriber' %}
|
||||
h4 Thank you for supporting us!
|
||||
hr
|
||||
p Subscription expires on: <strong>{{ expiration_date }}</strong>
|
||||
p
|
||||
a(href="{{ config['EXTERNAL_SUBSCRIPTIONS_MANAGEMENT_SERVER'] | urljoin('my-account/subscriptions/') }}") Manage your subscription on Blender Store
|
||||
|
||||
| {% elif 'demo' in groups %}
|
||||
h3.subscription-demo
|
||||
i.pi-heart-filled
|
||||
| You have a free account
|
||||
//---------------------------------
|
||||
| {% elif user_cls == 'subscriber-org' %}
|
||||
p Your organisation provides you with your subscription.
|
||||
| {% endif %}
|
||||
|
||||
hr
|
||||
|
||||
p You have full access to the Blender Cloud, provided by the Blender Institute. This account is meant for free evaluation of the service. Get in touch with #[a(href="mailto:cloudsupport@blender.org") cloudsupport@blender.org] if you have any questions.
|
||||
|
||||
| {% else %}
|
||||
h3.subscription-missing
|
||||
i.pi-info
|
||||
| You do not have an active subscription.
|
||||
h3
|
||||
a(href="https://store.blender.org/product/membership/") Get full access to Blender Cloud now!
|
||||
//--------------------------------------------------------------------------------------------------
|
||||
| {% endif %}
|
||||
|
||||
hr
|
||||
|
Reference in New Issue
Block a user