From nobody Fri Apr 26 17:12:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) client-ip=209.132.183.28; envelope-from=patchew-devel-bounces@redhat.com; helo=mx1.redhat.com; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of redhat.com designates 209.132.183.28 as permitted sender) smtp.mailfrom=patchew-devel-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1521184121537264.4412624533792; Fri, 16 Mar 2018 00:08:41 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 3B75F7E9D8; Fri, 16 Mar 2018 07:08:40 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.21]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 30A595D72D; Fri, 16 Mar 2018 07:08:40 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 274EF4CA98; Fri, 16 Mar 2018 07:08:40 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w2G78cvN022349 for ; Fri, 16 Mar 2018 03:08:38 -0400 Received: by smtp.corp.redhat.com (Postfix) id 3DDBD2026609; Fri, 16 Mar 2018 07:08:38 +0000 (UTC) Received: from lemon.usersys.redhat.com (ovpn-12-97.pek2.redhat.com [10.72.12.97]) by smtp.corp.redhat.com (Postfix) with ESMTP id 1BB5D2026E03; Fri, 16 Mar 2018 07:08:36 +0000 (UTC) From: Fam Zheng To: patchew-devel@redhat.com Date: Fri, 16 Mar 2018 15:08:31 +0800 Message-Id: <20180316070831.20987-1-famz@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] mods: Add the first maintainer op X-BeenThere: patchew-devel@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Patchew development and discussion list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: patchew-devel-bounces@redhat.com Errors-To: patchew-devel-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.26]); Fri, 16 Mar 2018 07:08:40 +0000 (UTC) X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" No extention to data model yet but a separate mod is probably a suitable place to keep maintainership related code. Signed-off-by: Fam Zheng --- mods/maintainer.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++= ++++ 1 file changed, 59 insertions(+) create mode 100644 mods/maintainer.py diff --git a/mods/maintainer.py b/mods/maintainer.py new file mode 100644 index 0000000..e25d8e2 --- /dev/null +++ b/mods/maintainer.py @@ -0,0 +1,59 @@ +#!/usr/bin/env python3 +# +# Copyright 2018 Red Hat, Inc. +# +# Authors: +# Fam Zheng +# +# This work is licensed under the MIT License. Please see the LICENSE fil= e or +# http://opensource.org/licenses/MIT. + +from django.conf.urls import url +from django.http import Http404, HttpResponseRedirect +from django.urls import reverse +from mod import PatchewModule +from api.models import Message + +class MaintainerModule(PatchewModule): + """ Project maintainer related tasks """ + + name =3D "maintainer" + + def _update_merge_state(self, request, message_id, is_merged): + s =3D Message.objects.find_series(message_id) + if not s: + raise Http404("Series not found") + if not s.project.maintained_by(request.user): + return HttpResponseForbidden() + s.is_merged =3D is_merged + s.save() + return HttpResponseRedirect(request.META.get('HTTP_REFERER')) + + def www_view_mark_as_merged(self, request, message_id): + return self._update_merge_state(request, message_id, True) + + def www_view_clear_merged(self, request, message_id): + return self._update_merge_state(request, message_id, False) + + def www_url_hook(self, urlpatterns): + urlpatterns.append(url(r"^mark-as-merged/(?P.*)/", + self.www_view_mark_as_merged, + name=3D"mark-as-merged")) + urlpatterns.append(url(r"^clear-merged/(?P.*)/", + self.www_view_clear_merged, + name=3D"clear-merged")) + + def prepare_message_hook(self, request, message, detailed): + if not detailed: + return + if message.is_series_head and request.user.is_authenticated: + if message.is_merged: + message.extra_ops.append({"url": reverse("clear-merged", + kwargs=3D{"messag= e_id": message.message_id}), + "icon": "times", + "title": "Clear merged state"}) + else: + message.extra_ops.append({"url": reverse("mark-as-merged", + kwargs=3D{"messag= e_id": message.message_id}), + "icon": "check", + "title": "Mark series as merged"= }) --=20 2.14.3 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel