From patchwork Tue Aug 17 00:32:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raxel Gutierrez X-Patchwork-Id: 1517359 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=OT4R9ZCB; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GpX6x74NJz9s5R for ; Tue, 17 Aug 2021 10:32:41 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GpX6x5dmJz303D for ; Tue, 17 Aug 2021 10:32:41 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=OT4R9ZCB; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--raxel.bounces.google.com (client-ip=2607:f8b0:4864:20::749; helo=mail-qk1-x749.google.com; envelope-from=3ngmbyqukcseo7ubidlldib.9ljm7q9etlohifpqp.lwi78p.lod@flex--raxel.bounces.google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=OT4R9ZCB; dkim-atps=neutral Received: from mail-qk1-x749.google.com (mail-qk1-x749.google.com [IPv6:2607:f8b0:4864:20::749]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GpX6p4DCfz2yLc for ; Tue, 17 Aug 2021 10:32:33 +1000 (AEST) Received: by mail-qk1-x749.google.com with SMTP id 62-20020a3706410000b02903d2cdd9acf0so8224600qkg.21 for ; Mon, 16 Aug 2021 17:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=7HUBiBvcQAK+OF6xb/+vRTJX+edhqVdQwWjl2Te91dY=; b=OT4R9ZCBcSDSy1DiO09qBVztYI8faT6tGLvMoAnpYPqs864JXbxTVYN/TVMhVbTf4o PayNNgNAdFgRS8+hW8vM4Sx5YMKRv1jzSepxnLhNd5ymClq3zkKl8nj6ennzKdfesEoN wfomhN9hQx8dhHjepjpQeLXKoC9Hv1L5TySltbHCQNxxVaZv2c1T7ZKj3Cw2go6n+jdc CIodloxYzCLazOSjpC0sOaD2I3D8w65JVRM/5/92hDq0OlL/ib2aJ21uXk6gOr9rBtAh ApQDcINfsXrXFKzQ+3JfZxt3OWB05sQG6zd3cHJ/01wIxCgfQvs8jbIXcxoi2zC3ppuu nDxQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=7HUBiBvcQAK+OF6xb/+vRTJX+edhqVdQwWjl2Te91dY=; b=RASrAofuzFuUunFnEAl3ESwpxxzkhEkQM/5wzGwCo4AvcJJKeZXlNVoGMnzkJAGkJZ Qf9Km7sk6oGFkYryhyvB0IMU8R1CxLWed7vY7coO9WGw/vxV5MUfUdkfxRqYOlPKfpa9 QH91vrd9UBTmJYfyobzJMdxcHvPxhlJfT8DH5blsFbD/DNC0wD6deUzo8ycqZ3xDd4eR pmB+pI9eEy3akAfrVV1yoWiFymL89f8T/ukVowqbxKI0l5r3kjzg8ax6Uc9NRsEq+Zcl sQhhUyqWMnSHqU5un6+kpKd1QtdTWp3yNpHWuV17nzXxf47U0mOCNVqzsI11A6fns9s1 oHSQ== X-Gm-Message-State: AOAM532EOP/cEyb09yRUMBW0W3eLfCscn+papzqXm9O8Vep3PDGiIJb5 +8vTPTDPMy/h/2ouKrkvstUmO8WpBSsXoJMPRZ2BbmEt6I/DdSgQJFYLIYi2EFgSoQpZNTahJWo Xe/r57EgnflLQAdCj1prLzz2FB51Kdha6V0ScAUfEsBbdYQSPlLRNHpvjGCRsqm+x X-Google-Smtp-Source: ABdhPJzmTQZwValppyKXxCprRcWcJSfWW4CbU7f2odc37M/T+Xax6NlXCZzrFyc8xdPWDLLu5ZJsJTMfJw== X-Received: from raxel-pw.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2fda]) (user=raxel job=sendgmr) by 2002:a0c:aac2:: with SMTP id g2mr634503qvb.44.1629160350501; Mon, 16 Aug 2021 17:32:30 -0700 (PDT) Date: Tue, 17 Aug 2021 00:32:23 +0000 In-Reply-To: <20210817003225.2813222-1-raxel@google.com> Message-Id: <20210817003225.2813222-2-raxel@google.com> Mime-Version: 1.0 References: <20210817003225.2813222-1-raxel@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH 1/3] messages: clean up messages and errors containers From: Raxel Gutierrez To: patchwork@lists.ozlabs.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Refactor the messages container to make use of message.tags [1] which allows for more customization for each level (e.g. success, warning, error, etc.) of a message through CSS selectors. As basic proof of concept, customize the text color of each existing message level. Also, this addition resolves a TODO by stephenfin in the previous code. Modularize the errors container with a new partial template errors.html that makes it easier to reuse errors in various pages. These changes make the code more readable and ready for change. Change both the messages and errors containers to always exist in the DOM. With this, the addition of update and error messages is simpler because it eliminates the need to create the containers if they don't exist. These changes will be useful in a following patch that introduces an internal JS module to make client-side requests to the REST API. [1] https://docs.djangoproject.com/en/3.2/ref/contrib/messages/#message-tags Signed-off-by: Raxel Gutierrez --- htdocs/css/style.css | 26 ++++++++++++++++--- patchwork/templates/patchwork/list.html | 10 +------ .../templates/patchwork/partials/errors.html | 10 +++++++ patchwork/templates/patchwork/submission.html | 2 ++ patchwork/templates/patchwork/user-link.html | 2 +- templates/base.html | 22 +++++++++------- 6 files changed, 49 insertions(+), 23 deletions(-) create mode 100644 patchwork/templates/patchwork/partials/errors.html diff --git a/htdocs/css/style.css b/htdocs/css/style.css index 46a91ee8..bcc57b2c 100644 --- a/htdocs/css/style.css +++ b/htdocs/css/style.css @@ -1,3 +1,9 @@ +:root { + --success-color:rgb(92, 184, 92); + --warning-color:rgb(240, 173, 78); + --danger-color:rgb(217, 83, 79); +} + h2 { font-size: 25px; margin: 18px 0 18px 0; @@ -78,14 +84,26 @@ dl dt { } /* messages */ -#messages { +.messages { background: #e0e0f0; margin: 0.5em 1em 0.0em 0.5em; padding: 0.3em; } -#messages .message { - color: green; +.messages:empty { + display: none; +} + +.messages .success { + color: var(--success-color); +} + +.messages .warning { + color: var(--warning-color); +} + +.messages .error { + color: var(--danger-color); } .filters { @@ -421,7 +439,7 @@ table.loginform { } /* form errors */ -.errorlist { +.error-list { color: red; list-style-type: none; padding-left: 0.2em; diff --git a/patchwork/templates/patchwork/list.html b/patchwork/templates/patchwork/list.html index 5d3d82aa..91387cf0 100644 --- a/patchwork/templates/patchwork/list.html +++ b/patchwork/templates/patchwork/list.html @@ -8,15 +8,7 @@ {% block body %} -{% if errors %} -

The following error{{ errors|length|pluralize:" was,s were" }} encountered -while updating patches:

-
    -{% for error in errors %} -
  • {{ error }}
  • -{% endfor %} -
-{% endif %} +{% include "patchwork/partials/errors.html" %} {% include "patchwork/partials/patch-list.html" %} diff --git a/patchwork/templates/patchwork/partials/errors.html b/patchwork/templates/patchwork/partials/errors.html new file mode 100644 index 00000000..86eec121 --- /dev/null +++ b/patchwork/templates/patchwork/partials/errors.html @@ -0,0 +1,10 @@ +
+ {% if errors %} +

The following error{{ errors|length|pluralize:" was,s were" }} encountered while updating patches:

+
    + {% for error in errors %} +
  • {{ error }}
  • + {% endfor %} +
+ {% endif %} +
diff --git a/patchwork/templates/patchwork/submission.html b/patchwork/templates/patchwork/submission.html index 66efa0b5..3b65f81d 100644 --- a/patchwork/templates/patchwork/submission.html +++ b/patchwork/templates/patchwork/submission.html @@ -14,6 +14,8 @@ {% block body %} +{% include "patchwork/partials/errors.html" %} +
{% include "patchwork/partials/download-buttons.html" %}

{{ submission.name }}

diff --git a/patchwork/templates/patchwork/user-link.html b/patchwork/templates/patchwork/user-link.html index bf331520..e23e69d5 100644 --- a/patchwork/templates/patchwork/user-link.html +++ b/patchwork/templates/patchwork/user-link.html @@ -14,7 +14,7 @@ you.

{{ form.non_field_errors }} {% endif %} {% if error %} -
  • {{error}}
+
  • {{error}}
{% endif %}
diff --git a/templates/base.html b/templates/base.html index a95a11b0..a9d0906b 100644 --- a/templates/base.html +++ b/templates/base.html @@ -104,15 +104,19 @@
-{% if messages %} -
- {% for message in messages %} - {# TODO(stephenfin): Make use of message.tags when completely #} - {# converted to django.contrib.messages #} -
{{ message }}
- {% endfor %} -
-{% endif %} + + {% spaceless %} +
    + {% if messages %} + {% for message in messages %} + {{ message }} + {% endfor %} + {% endif %} +
+ {% endspaceless %}
{% block body %} {% endblock %} From patchwork Tue Aug 17 00:32:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raxel Gutierrez X-Patchwork-Id: 1517362 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=j5xsKAIL; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GpXBc0p3vz9sVq for ; Tue, 17 Aug 2021 10:35:52 +1000 (AEST) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4GpXBb6dTQz2yxX for ; Tue, 17 Aug 2021 10:35:51 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=j5xsKAIL; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=flex--raxel.bounces.google.com (client-ip=2607:f8b0:4864:20::b49; helo=mail-yb1-xb49.google.com; envelope-from=3oambyqukcsmq9wdkfnnfkd.bnlo9sbgvnqjkhrsr.nyk9ar.nqf@flex--raxel.bounces.google.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=j5xsKAIL; dkim-atps=neutral Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4GpX6q1brhz2yLZ for ; Tue, 17 Aug 2021 10:32:34 +1000 (AEST) Received: by mail-yb1-xb49.google.com with SMTP id i32-20020a25b2200000b02904ed415d9d84so18543333ybj.0 for ; Mon, 16 Aug 2021 17:32:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=qmLO0Gg5uFxUBR2My5+jA8AYqIugA8m8Ycwup+UAoLI=; b=j5xsKAILDodzWlXbiCAsgUBS3XVtvhw/uwJvzmUarbq+CBDCdfG8tBMRotw8ZoUiCh ZjoO4KNk92uo3z9s8iu35UiSUMCW1YJa8a45M0UGM3T+A9cFpLyy8PjrB+G/6XD7DMWb zzzCIrloXR+AAU3VT95iP91ktRguI1W7Op0eUi2u0/IXhf1wF2FSDeeZSwitccIneC16 rGA5fKstrGIdAFsrX1RyQ4MhaEgDMftEuMOTvQvacu8c4kcz/NN63ezSMMUk7r7pKfVL YNA+i9gttnHAC5cBthFlrMbSfbNCBtb+ylkuh84p4Mrwo4xeVAQmarq6JX7P5JB51Un7 /Png== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=qmLO0Gg5uFxUBR2My5+jA8AYqIugA8m8Ycwup+UAoLI=; b=BHC3ZsJulQeDN7wU31vCStgKWb8kTg0rOC+mfRP3TgRdj3Y8F8nmdG0qhCtPEOYQ+Y /ICaAJXgo2w8ey5XCzSOozW4zWk/BElB8+RqCHM+5FF4xJuyD5sLOnUcn1uorGngyUSZ 79slTi2bmWJezy8nwG3lF9CEr8i8PFiBOyOW27mXG2RJYQm2CPKzgis7TQlG5wKc3qs4 LACDLqNjni3iY26BwXgaLKk7n1rFofzyK64lrfJ3HkIiB0E6Gz8kAq8PkZGf6BQxcEwU XJDe50QzlyaaloFwMHw5zGzXBjqmnh8JkD3ekuvdY3DZl+IQ+/xQwobB2YV4fVYYeeq6 geCw== X-Gm-Message-State: AOAM530uGVLOCsKl+QUei94AGj0eoy4u098Dmu4G76KoAYHedNrcRsT4 WQk6NY46FohY0Mz0JL45dvJOBKGA6PUip7tGZFf9BBpwAuXnc1shIddeuGm6o0reCEQlXHKbHqJ NTkjco0LqWSq395/hfSusRUDSjPbG6d3/i2J+T5hWwNFhdVNIUCPVH6or729FWM3p X-Google-Smtp-Source: ABdhPJzZdF5pQUXx9VbGMgID6OlefLzEhZwV/it1uyFZtE9JjeGjIpxtPcPCfUgXtmg4uidmUkDUXzz2Wg== X-Received: from raxel-pw.c.googlers.com ([fda3:e722:ac3:cc00:14:4d90:c0a8:2fda]) (user=raxel job=sendgmr) by 2002:a25:5cc:: with SMTP id 195mr1026694ybf.304.1629160352379; Mon, 16 Aug 2021 17:32:32 -0700 (PDT) Date: Tue, 17 Aug 2021 00:32:24 +0000 In-Reply-To: <20210817003225.2813222-1-raxel@google.com> Message-Id: <20210817003225.2813222-3-raxel@google.com> Mime-Version: 1.0 References: <20210817003225.2813222-1-raxel@google.com> X-Mailer: git-send-email 2.33.0.rc1.237.g0d66db33f3-goog Subject: [PATCH 2/3] static: add JS Cookie library to get csrftoken for client-side requests From: Raxel Gutierrez To: patchwork@lists.ozlabs.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" Currently in Patchwork, requests are made only through older methods via form submissions, which means the UI is rendered strictly server-side. This lags behind more modern and versatile approaches that use JavaScript to send requests and dynamically update the UI based on the respective responses. In order to make REST API requests on the client-side secure from CSRF attacks, add the JS Cookie library which allows the CSRF token to be passed in the request header. A following patch that introduces the `rest.js` module will make use of the JS Cookie library in this patch. The library is a recommendation from Django docs [1]. The files for the library can be downloaded in the releases page of the GitHub [2]. [1] https://docs.djangoproject.com/en/3.2/ref/csrf/#ajax [2] https://github.com/js-cookie/js-cookie/releases Signed-off-by: Raxel Gutierrez Reviewed-by: Daniel Axtens --- htdocs/README.rst | 9 +++++++++ htdocs/js/js.cookie.min.js | 2 ++ templates/base.html | 1 + 3 files changed, 12 insertions(+) create mode 100644 htdocs/js/js.cookie.min.js diff --git a/htdocs/README.rst b/htdocs/README.rst index 62f15c23..128dc7c2 100644 --- a/htdocs/README.rst +++ b/htdocs/README.rst @@ -122,6 +122,15 @@ js :GitHub: jQuery plug-in to drag and drop rows in HTML tables :Version: ??? +``js.cookie.min.js`` + + Library used to handle cookies. + + This is used to get the ``csrftoken`` cookie for AJAX requests in JavaScript. + + :GitHub: https://github.com/js-cookie/js-cookie/ + :Version: 3.0.0 + ``selectize.min.js`` Selectize is the hybrid of a ``textbox`` and ``