get:
Show a patch.

patch:
Update a patch.

put:
Update a patch.

GET /api/patches/1523343/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 1523343,
    "url": "http://patchwork.ozlabs.org/api/patches/1523343/?format=api",
    "web_url": "http://patchwork.ozlabs.org/project/patchwork/patch/20210901165756.181192-13-stephen@that.guru/",
    "project": {
        "id": 16,
        "url": "http://patchwork.ozlabs.org/api/projects/16/?format=api",
        "name": "Patchwork",
        "link_name": "patchwork",
        "list_id": "patchwork.lists.ozlabs.org",
        "list_email": "patchwork@lists.ozlabs.org",
        "web_url": "http://jk.ozlabs.org/projects/patchwork/",
        "scm_url": "git://github.com/getpatchwork/patchwork",
        "webscm_url": "https://github.com/getpatchwork/patchwork",
        "list_archive_url": "",
        "list_archive_url_format": "",
        "commit_url_format": ""
    },
    "msgid": "<20210901165756.181192-13-stephen@that.guru>",
    "list_archive_url": null,
    "date": "2021-09-01T16:57:49",
    "name": "[RFC,v2,12/19] view: Simplify user opt-in, opt-out",
    "commit_ref": null,
    "pull_url": null,
    "state": "rfc",
    "archived": false,
    "hash": "5d2c487c5bc0acb699deb941f56ceaf95471c818",
    "submitter": {
        "id": 69991,
        "url": "http://patchwork.ozlabs.org/api/people/69991/?format=api",
        "name": "Stephen Finucane",
        "email": "stephen@that.guru"
    },
    "delegate": null,
    "mbox": "http://patchwork.ozlabs.org/project/patchwork/patch/20210901165756.181192-13-stephen@that.guru/mbox/",
    "series": [
        {
            "id": 260605,
            "url": "http://patchwork.ozlabs.org/api/series/260605/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/patchwork/list/?series=260605",
            "date": "2021-09-01T16:57:37",
            "name": "Integrate Bulma",
            "version": 2,
            "mbox": "http://patchwork.ozlabs.org/series/260605/mbox/"
        }
    ],
    "comments": "http://patchwork.ozlabs.org/api/patches/1523343/comments/",
    "check": "pending",
    "checks": "http://patchwork.ozlabs.org/api/patches/1523343/checks/",
    "tags": {},
    "related": [
        {
            "id": 1516052,
            "url": "http://patchwork.ozlabs.org/api/patches/1516052/?format=api",
            "web_url": "http://patchwork.ozlabs.org/project/patchwork/patch/20210811213705.36293-13-stephen@that.guru/",
            "msgid": "<20210811213705.36293-13-stephen@that.guru>",
            "list_archive_url": null,
            "date": "2021-08-11T21:36:58",
            "name": "[RFC,12/19] view: Simplify user opt-in, opt-out",
            "mbox": "http://patchwork.ozlabs.org/project/patchwork/patch/20210811213705.36293-13-stephen@that.guru/mbox/"
        }
    ],
    "headers": {
        "Return-Path": "\n <patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>",
        "X-Original-To": [
            "incoming@patchwork.ozlabs.org",
            "patchwork@lists.ozlabs.org"
        ],
        "Delivered-To": [
            "patchwork-incoming@bilbo.ozlabs.org",
            "patchwork@lists.ozlabs.org"
        ],
        "Authentication-Results": [
            "ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" header.d=that.guru\n header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=BA/F6mS7;\n\tdkim-atps=neutral",
            "ozlabs.org;\n spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org\n (client-ip=112.213.38.117; helo=lists.ozlabs.org;\n envelope-from=patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org;\n receiver=<UNKNOWN>)",
            "lists.ozlabs.org;\n\tdkim=fail reason=\"key not found in DNS\" header.d=that.guru\n header.i=@that.guru header.a=rsa-sha256 header.s=x header.b=BA/F6mS7;\n\tdkim-atps=neutral",
            "lists.ozlabs.org;\n spf=none (no SPF record) smtp.mailfrom=that.guru\n (client-ip=136.175.108.76; helo=mail-108-mta76.mxroute.com;\n envelope-from=stephen@that.guru; receiver=<UNKNOWN>)",
            "lists.ozlabs.org;\n dkim=fail reason=\"key not found in DNS\" header.d=that.guru\n header.i=@that.guru\n header.a=rsa-sha256 header.s=x header.b=BA/F6mS7;\n dkim-atps=neutral"
        ],
        "Received": [
            "from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange X25519 server-signature RSA-PSS (4096 bits))\n\t(No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 4H09hg2vt7z9sW8\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Sep 2021 03:16:51 +1000 (AEST)",
            "from boromir.ozlabs.org (localhost [IPv6:::1])\n\tby lists.ozlabs.org (Postfix) with ESMTP id 4H09hg1ns0z2yJT\n\tfor <incoming@patchwork.ozlabs.org>; Thu,  2 Sep 2021 03:16:51 +1000 (AEST)",
            "from mail-108-mta76.mxroute.com (mail-108-mta76.mxroute.com\n [136.175.108.76])\n (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))\n (No client certificate requested)\n by lists.ozlabs.org (Postfix) with ESMTPS id 4H09hM5Rwvz2yR7\n for <patchwork@lists.ozlabs.org>; Thu,  2 Sep 2021 03:16:35 +1000 (AEST)",
            "from filter004.mxroute.com ([149.28.56.236] filter004.mxroute.com)\n (Authenticated sender: mN4UYu2MZsgR)\n by mail-108-mta76.mxroute.com (ZoneMTA) with ESMTPSA id\n 17ba25cc05200074ba.001\n for <patchwork@lists.ozlabs.org>\n (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES128-GCM-SHA256);\n Wed, 01 Sep 2021 17:16:32 +0000"
        ],
        "X-Zone-Loop": "f76c4c6955add1ddc975da23a566a87021a025667948",
        "X-Originating-IP": "[149.28.56.236]",
        "DKIM-Signature": "v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru;\n s=x;\n h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:\n Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:\n Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe:\n List-Post:List-Owner:List-Archive;\n bh=2ki0d7GcplR0dWcO9kWZbbcpQLlU0/0xXK9nfBfEJO4=; b=BA/F6mS7/dplfKhzx2r2qoxGC2\n b/YJHgxCosYJtsa++GDJssUdEWd1PcXDfFCTV82sxmAyVLlU/loFg/NPCwV3FJEa6gXOVSMKrSceW\n 7p6vgrf8rzqHFTn35kaIJmfVKaYC6p60ia8QQMGw1qhXpTTXSy33tSNwRX2i+wS3DIxJtSDaDOf3m\n YA4kRZqMW1c3KPbDR95J2D/3GGmRwjVlfIxCizNR6ooanKwU+EaRZjhop+sexetv3YpPSypQ3jfDu\n NY923z73pDemhHhY0MnS9y74WY7nbXARGe5K4GJ9OruCV+JuqPaJocnZvOc27z6nEhnqPLQm7dCog\n BNCOJPDQ==;",
        "From": "Stephen Finucane <stephen@that.guru>",
        "To": "patchwork@lists.ozlabs.org",
        "Subject": "[RFC PATCH v2 12/19] view: Simplify user opt-in, opt-out",
        "Date": "Wed,  1 Sep 2021 17:57:49 +0100",
        "Message-Id": "<20210901165756.181192-13-stephen@that.guru>",
        "X-Mailer": "git-send-email 2.31.1",
        "In-Reply-To": "<20210901165756.181192-1-stephen@that.guru>",
        "References": "<20210901165756.181192-1-stephen@that.guru>",
        "MIME-Version": "1.0",
        "X-AuthUser": "stephen@that.guru",
        "X-BeenThere": "patchwork@lists.ozlabs.org",
        "X-Mailman-Version": "2.1.29",
        "Precedence": "list",
        "List-Id": "Patchwork development <patchwork.lists.ozlabs.org>",
        "List-Unsubscribe": "<https://lists.ozlabs.org/options/patchwork>,\n <mailto:patchwork-request@lists.ozlabs.org?subject=unsubscribe>",
        "List-Archive": "<http://lists.ozlabs.org/pipermail/patchwork/>",
        "List-Post": "<mailto:patchwork@lists.ozlabs.org>",
        "List-Help": "<mailto:patchwork-request@lists.ozlabs.org?subject=help>",
        "List-Subscribe": "<https://lists.ozlabs.org/listinfo/patchwork>,\n <mailto:patchwork-request@lists.ozlabs.org?subject=subscribe>",
        "Content-Type": "text/plain; charset=\"us-ascii\"",
        "Content-Transfer-Encoding": "7bit",
        "Errors-To": "patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org",
        "Sender": "\"Patchwork\"\n <patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org>"
    },
    "content": "If we already have a user account associated with an email address, why\nmake the user jump through hoops when opting in or out of emails. It's\nsilly.\n\nSigned-off-by: Stephen Finucane <stephen@that.guru>\n---\n patchwork/views/user.py | 78 +++++++++--------------------------------\n 1 file changed, 16 insertions(+), 62 deletions(-)",
    "diff": "diff --git patchwork/views/user.py patchwork/views/user.py\nindex d1a1180e..440aa38a 100644\n--- patchwork/views/user.py\n+++ patchwork/views/user.py\n@@ -103,50 +103,6 @@ def register_confirm(request, conf):\n     return render(request, 'patchwork/registration-confirm.html')\n \n \n-def _opt_in(request, email):\n-    conf = EmailConfirmation(type='optin', email=email)\n-    conf.save()\n-\n-    context = {'confirmation': conf}\n-    subject = render_to_string('patchwork/mails/optin-request-subject.txt')\n-    message = render_to_string(\n-        'patchwork/mails/optin-request.txt', context, request=request)\n-\n-    try:\n-        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])\n-    except smtplib.SMTPException:\n-        messages.error(\n-            request,\n-            'An error occurred while submitting this request. '\n-            'Please contact an administrator.'\n-        )\n-        return False\n-\n-    return True\n-\n-\n-def _opt_out(request, email):\n-    conf = EmailConfirmation(type='optout', email=email)\n-    conf.save()\n-\n-    context = {'confirmation': conf}\n-    subject = render_to_string('patchwork/mails/optout-request-subject.txt')\n-    message = render_to_string(\n-        'patchwork/mails/optout-request.txt', context, request=request)\n-\n-    try:\n-        send_mail(subject, message, settings.DEFAULT_FROM_EMAIL, [email])\n-    except smtplib.SMTPException:\n-        messages.error(\n-            request,\n-            'An error occurred while submitting this request. '\n-            'Please contact an administrator.'\n-        )\n-        return False\n-\n-    return True\n-\n-\n def _send_confirmation_email(request, email):\n     conf = EmailConfirmation(type='userperson', user=request.user, email=email)\n     conf.save()\n@@ -228,30 +184,28 @@ def profile(request):\n             user_email_optin_form = forms.UserEmailOptinForm(\n                 user=request.user, data=request.POST)\n             if user_email_optin_form.is_valid():\n-                if _opt_in(\n-                    request, user_email_optin_form.cleaned_data['email'],\n-                ):\n-                    messages.success(\n-                        request,\n-                        'Requested opt-in to email from Patchwork. '\n-                        'Check your email for confirmation.',\n-                    )\n-                    return HttpResponseRedirect(reverse('user-profile'))\n+                EmailOptout.objects.filter(\n+                    email=user_email_optin_form.cleaned_data['email'],\n+                ).delete()\n+                messages.success(\n+                    request,\n+                    'Opt-in into email from Patchwork.'\n+                )\n+                return HttpResponseRedirect(reverse('user-profile'))\n \n             messages.error(request, 'Error opting into email.')\n         elif form_name == forms.UserEmailOptoutForm.name:\n             user_email_optout_form = forms.UserEmailOptoutForm(\n                 user=request.user, data=request.POST)\n             if user_email_optout_form.is_valid():\n-                if _opt_out(\n-                    request, user_email_optout_form.cleaned_data['email'],\n-                ):\n-                    messages.success(\n-                        request,\n-                        'Requested opt-out from email from Patchwork. '\n-                        'Check your email for confirmation.',\n-                    )\n-                    return HttpResponseRedirect(reverse('user-profile'))\n+                EmailOptout(\n+                    email=user_email_optout_form.cleaned_data['email'],\n+                ).save()\n+                messages.success(\n+                    request,\n+                    'Opted-out from email from Patchwork.'\n+                )\n+                return HttpResponseRedirect(reverse('user-profile'))\n \n             messages.error(request, 'Error opting out of email.')\n         elif form_name == UserForm.name:\n",
    "prefixes": [
        "RFC",
        "v2",
        "12/19"
    ]
}