[Patchew-devel] [PATCH] mods: Add the first maintainer op

Fam Zheng posted 1 patch 6 years, 3 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/patchew-ci tags/patchew/20180316070831.20987-1-famz@redhat.com
mods/maintainer.py | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
create mode 100644 mods/maintainer.py
[Patchew-devel] [PATCH] mods: Add the first maintainer op
Posted by Fam Zheng 6 years, 3 months ago
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 <famz@redhat.com>
---
 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 <famz@redhat.com>
+#
+# This work is licensed under the MIT License.  Please see the LICENSE file 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 = "maintainer"
+
+    def _update_merge_state(self, request, message_id, is_merged):
+        s = 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 = 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<message_id>.*)/",
+                               self.www_view_mark_as_merged,
+                               name="mark-as-merged"))
+        urlpatterns.append(url(r"^clear-merged/(?P<message_id>.*)/",
+                               self.www_view_clear_merged,
+                               name="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={"message_id": message.message_id}),
+                                          "icon": "times",
+                                          "title": "Clear merged state"})
+            else:
+                message.extra_ops.append({"url": reverse("mark-as-merged",
+                                                         kwargs={"message_id": message.message_id}),
+                                          "icon": "check",
+                                          "title": "Mark series as merged"})
-- 
2.14.3

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH] mods: Add the first maintainer op
Posted by Paolo Bonzini 6 years, 3 months ago
On 16/03/2018 08:08, Fam Zheng wrote:
> 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 <famz@redhat.com>
> ---
>  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 <famz@redhat.com>
> +#
> +# This work is licensed under the MIT License.  Please see the LICENSE file 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 = "maintainer"
> +
> +    def _update_merge_state(self, request, message_id, is_merged):
> +        s = 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 = 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<message_id>.*)/",
> +                               self.www_view_mark_as_merged,
> +                               name="mark-as-merged"))
> +        urlpatterns.append(url(r"^clear-merged/(?P<message_id>.*)/",
> +                               self.www_view_clear_merged,
> +                               name="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={"message_id": message.message_id}),
> +                                          "icon": "times",
> +                                          "title": "Clear merged state"})
> +            else:
> +                message.extra_ops.append({"url": reverse("mark-as-merged",
> +                                                         kwargs={"message_id": message.message_id}),
> +                                          "icon": "check",
> +                                          "title": "Mark series as merged"})
> 

Nice!

Paolo

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel
Re: [Patchew-devel] [PATCH] mods: Add the first maintainer op
Posted by Fam Zheng 6 years, 3 months ago
On Fri, 03/16 13:28, Paolo Bonzini wrote:
> On 16/03/2018 08:08, Fam Zheng wrote:
> > 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 <famz@redhat.com>
> > ---
> >  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 <famz@redhat.com>
> > +#
> > +# This work is licensed under the MIT License.  Please see the LICENSE file 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 = "maintainer"
> > +
> > +    def _update_merge_state(self, request, message_id, is_merged):
> > +        s = 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 = 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<message_id>.*)/",
> > +                               self.www_view_mark_as_merged,
> > +                               name="mark-as-merged"))
> > +        urlpatterns.append(url(r"^clear-merged/(?P<message_id>.*)/",
> > +                               self.www_view_clear_merged,
> > +                               name="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={"message_id": message.message_id}),
> > +                                          "icon": "times",
> > +                                          "title": "Clear merged state"})
> > +            else:
> > +                message.extra_ops.append({"url": reverse("mark-as-merged",
> > +                                                         kwargs={"message_id": message.message_id}),
> > +                                          "icon": "check",
> > +                                          "title": "Mark series as merged"})
> > 
> 
> Nice!
> 
> Paolo

Pushed, thanks.

Fam

_______________________________________________
Patchew-devel mailing list
Patchew-devel@redhat.com
https://www.redhat.com/mailman/listinfo/patchew-devel