Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Block channel user from accessing regular pro shop #13799

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions templates/account/forbidden.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ <h1>Access Forbidden</h1>
</p>
{% elif reason=="is_only_personal" %}
<p>This feature is accessible only by users with enterprise subscriptions for commercial use.</p>
{% elif reason=="channel_account" %}
<p>
You are a channel account user. Channel users are not allowed to access this page. Please contact your account administrator for more information, or go to <a href="/pro/distibutor">the distributor's home page.</a>
</p>
{% else %}
<p>You need administrator rights to the account to access this feature.</p>
{% endif %}
Expand Down
23 changes: 22 additions & 1 deletion webapp/shop/advantage/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,13 @@ def pro_page_view(advantage_mapper, **kwargs):
def advantage_view(advantage_mapper, is_in_maintenance, **kwargs):
is_technical = False
try:
channel_account = advantage_mapper.get_purchase_account(
"canonical-pro-channel"
)
if channel_account:
return flask.render_template(
"account/forbidden.html", reason="channel_account"
Comment on lines +79 to +80
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought displaying a forbidden page with a link to the distributor page was better than redirecting to the distributor page immediately but please let me know if the other way is better!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a good approach.

)
advantage_mapper.get_purchase_account("canonical-ua")
except UAContractsUserHasNoAccount:
pass
Expand Down Expand Up @@ -196,6 +203,13 @@ def advantage_shop_view(advantage_mapper, **kwargs):
account = None
if user_info(flask.session):
try:
channel_account = advantage_mapper.get_purchase_account(
"canonical-pro-channel"
)
if channel_account:
return flask.render_template(
"account/forbidden.html", reason="channel_account"
)
account = advantage_mapper.get_purchase_account("canonical-ua")
except UAContractsUserHasNoAccount:
# There is no purchase account yet for this user.
Expand Down Expand Up @@ -592,8 +606,15 @@ def get_distributor_view(advantage_mapper, **kwargs):


@shop_decorator(area="advantage", permission="user", response="json")
def get_account_offers(advantage_mapper, ua_contracts_api, **kwargs):
def get_account_offers(advantage_mapper, **kwargs):
try:
channel_account = advantage_mapper.get_purchase_account(
"canonical-pro-channel"
)
if channel_account:
return flask.render_template(
"account/forbidden.html", reason="channel_account"
)
account = advantage_mapper.get_purchase_account("canonical-ua")
except UAContractsUserHasNoAccount:
return flask.jsonify({"error": "User has no purchase account"}), 400
Expand Down
Loading