From patchwork Tue Dec 19 05:41:27 2017
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Andrew Donnellan
X-Patchwork-Id: 850622
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68])
(using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 3z16M62YDpz9t0m
for ;
Tue, 19 Dec 2017 16:45:38 +1100 (AEDT)
Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3])
by lists.ozlabs.org (Postfix) with ESMTP id 3z16M608LvzDvJ1
for ;
Tue, 19 Dec 2017 16:45:38 +1100 (AEDT)
X-Original-To: patchwork@lists.ozlabs.org
Delivered-To: patchwork@lists.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (mailfrom) smtp.mailfrom=au1.ibm.com
(client-ip=148.163.158.5; helo=mx0a-001b2d01.pphosted.com;
envelope-from=andrew.donnellan@au1.ibm.com; receiver=)
Received: from mx0a-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com
[148.163.158.5])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256
bits)) (No client certificate requested)
by lists.ozlabs.org (Postfix) with ESMTPS id 3z16Gf27hXzDsSY
for ;
Tue, 19 Dec 2017 16:41:45 +1100 (AEDT)
Received: from pps.filterd (m0098419.ppops.net [127.0.0.1])
by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id
vBJ5d4wP127338
for ; Tue, 19 Dec 2017 00:41:43 -0500
Received: from e06smtp14.uk.ibm.com (e06smtp14.uk.ibm.com [195.75.94.110])
by mx0b-001b2d01.pphosted.com with ESMTP id 2exumgjc6w-1
(version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT)
for ; Tue, 19 Dec 2017 00:41:43 -0500
Received: from localhost
by e06smtp14.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use
Only! Violators will be prosecuted
for from ;
Tue, 19 Dec 2017 05:41:42 -0000
Received: from b06cxnps4076.portsmouth.uk.ibm.com (9.149.109.198)
by e06smtp14.uk.ibm.com (192.168.101.144) with IBM ESMTP SMTP
Gateway: Authorized Use Only! Violators will be prosecuted;
Tue, 19 Dec 2017 05:41:39 -0000
Received: from d06av23.portsmouth.uk.ibm.com (d06av23.portsmouth.uk.ibm.com
[9.149.105.59])
by b06cxnps4076.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with
ESMTP id vBJ5fdcb48300182; Tue, 19 Dec 2017 05:41:39 GMT
Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1])
by IMSVA (Postfix) with ESMTP id D912BA4057;
Tue, 19 Dec 2017 05:35:52 +0000 (GMT)
Received: from d06av23.portsmouth.uk.ibm.com (unknown [127.0.0.1])
by IMSVA (Postfix) with ESMTP id 869AFA4051;
Tue, 19 Dec 2017 05:35:52 +0000 (GMT)
Received: from ozlabs.au.ibm.com (unknown [9.192.253.14])
by d06av23.portsmouth.uk.ibm.com (Postfix) with ESMTP;
Tue, 19 Dec 2017 05:35:52 +0000 (GMT)
Received: from intelligence.ozlabs.ibm.com (haven.au.ibm.com [9.192.254.114])
(using TLSv1.2 with cipher DHE-RSA-AES128-GCM-SHA256 (128/128 bits))
(No client certificate requested)
by ozlabs.au.ibm.com (Postfix) with ESMTPSA id 62145A01CF;
Tue, 19 Dec 2017 16:41:37 +1100 (AEDT)
From: Andrew Donnellan
To: patchwork@lists.ozlabs.org
Subject: [PATCH] views: Don't render token section of user profile if REST
API disabled
Date: Tue, 19 Dec 2017 16:41:27 +1100
X-Mailer: git-send-email 2.11.0
X-TM-AS-GCONF: 00
x-cbid: 17121905-0016-0000-0000-0000050E960D
X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused
x-cbparentid: 17121905-0017-0000-0000-0000284ABC31
Message-Id: <20171219054127.26494-1-andrew.donnellan@au1.ibm.com>
X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:, ,
definitions=2017-12-19_04:, , signatures=0
X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0
priorityscore=1501
malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0
clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0
classifier=spam adjust=0 reason=mlx scancount=1
engine=8.0.1-1709140000
definitions=main-1712190083
X-BeenThere: patchwork@lists.ozlabs.org
X-Mailman-Version: 2.1.24
Precedence: list
List-Id: Patchwork development
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Cc: tomas@novotny.cz, stable@vger.kernel.org
MIME-Version: 1.0
Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org
Sender: "Patchwork"
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.
Cc: stable
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
Reviewed-by: Stephen Finucane
---
patchwork/templates/patchwork/profile.html | 2 ++
patchwork/views/user.py | 2 ++
2 files changed, 4 insertions(+)
diff --git a/patchwork/templates/patchwork/profile.html b/patchwork/templates/patchwork/profile.html
index 75c4f59..4ca78da 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 d99fedf..693c02d 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)