From: Andrew Donnellan
Date: Tue, 19 Dec 2017 05:41:27 +0000 (+1100)
Subject: views: Don't render token section of user profile if REST API disabled
X-Git-Tag: v2.0.2~16
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cc1d5c5cd1076a26c4ed2d0cd9383bba86e7c8a2;p=thirdparty%2Fpatchwork.git
views: Don't render token section of user profile if REST API disabled
In profile.html, if settings.ENABLE_REST_API == False, trying to render a
link to the generate_token page will raise a NoReverseMatch exception, so
we shouldn't render that. In any case, if the REST API is disabled, we
really shouldn't render the API token section of the page at all.
Only render the API token and generation link if settings.ENABLE_REST_API
is True.
Reported-by: Tomas Novotny
Closes: #138 ("NoReverseMatch exception on user login with disabled REST API")
Fixes: 85c8f369204a ("views: Provide a way to view, (re)generate tokens")
Signed-off-by: Andrew Donnellan
Reviewed-by: Stephen Finucane
(cherry picked from commit 14034e8a44a497d32f56f31a0fdc4473336d92af)
---
diff --git a/patchwork/templates/patchwork/profile.html b/patchwork/templates/patchwork/profile.html
index 75c4f59f..4ca78dae 100644
--- a/patchwork/templates/patchwork/profile.html
+++ b/patchwork/templates/patchwork/profile.html
@@ -140,6 +140,7 @@ address.
Password: |
Change password
+{% if rest_api_enabled %}
|
| API Token: |
@@ -162,6 +163,7 @@ address.
|
+{% endif %}
diff --git a/patchwork/views/user.py b/patchwork/views/user.py
index d99fedf0..693c02da 100644
--- a/patchwork/views/user.py
+++ b/patchwork/views/user.py
@@ -128,6 +128,8 @@ def profile(request):
context['linked_emails'] = people
context['linkform'] = EmailForm()
context['api_token'] = request.user.profile.token
+ if settings.ENABLE_REST_API:
+ context['rest_api_enabled'] = True
return render(request, 'patchwork/profile.html', context)