From nobody Mon Sep 16 19:19:53 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; dkim=fail; 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 1538146736190403.26745306311363; Fri, 28 Sep 2018 07:58:56 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.phx2.redhat.com [10.5.11.15]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0A6D93001244; Fri, 28 Sep 2018 14:58:55 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id EEF835D776; Fri, 28 Sep 2018 14:58:54 +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 E20A3181A12F; Fri, 28 Sep 2018 14:58:54 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id w8SEwr6O026118 for ; Fri, 28 Sep 2018 10:58:53 -0400 Received: by smtp.corp.redhat.com (Postfix) id 6B60D18669; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mx1.redhat.com (ext-mx06.extmail.prod.ext.phx2.redhat.com [10.5.110.30]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 607EB5D9C6 for ; Fri, 28 Sep 2018 14:58:53 +0000 (UTC) Received: from mail-wr1-f49.google.com (mail-wr1-f49.google.com [209.85.221.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 94AAE356CD for ; Fri, 28 Sep 2018 14:58:51 +0000 (UTC) Received: by mail-wr1-f49.google.com with SMTP id z14-v6so6711328wrs.10 for ; Fri, 28 Sep 2018 07:58:51 -0700 (PDT) Received: from donizetti.par1.mozilla.com ([2a00:8c40:243:232:de:fba5:535e:2dc2]) by smtp.gmail.com with ESMTPSA id h73-v6sm5278053wma.11.2018.09.28.07.58.48 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 28 Sep 2018 07:58:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:subject:date:message-id:in-reply-to:references; bh=mUNU+2nbgN5239z8lBrEKm/icbEDQ5Fh3p1RPW9wJTU=; b=Q+jklbq0EhNRn4POt7xOMq0dgd9P5xOTVO3a2m7SNCRj1Jo2v51rA79sEpSK4MuL2o A8DD9h26MckIyGVYMyqD2jXRJvZeWL7+gWynWnG/5DWgyc5piVTe/VI7y4inZLR3u/4o /u+H1hMxTflwx1gHB9p9iGcUzincY5gsT4xerryhdedMcD4jXZfD8QdWsn0c7fpYZqzN McKngZi1uvFVWG/xUz6vQw2HZs0Nwx4cQdPTGaj2xvMK9xqwAle+2XdsWcZnHM4l4cx7 wuFDZwcaO1Y+mhp+nnAU0A+M/1GW+JsLQMKRNQDhwdz/hy3obWfc7/P3DPFaD4wOePjP Tt3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:subject:date:message-id :in-reply-to:references; bh=mUNU+2nbgN5239z8lBrEKm/icbEDQ5Fh3p1RPW9wJTU=; b=h8U8juE87r3m2D1lLgnrl9YeHWmuRSVUROhNIFiqS4AF5OhBMtFoaTa1ogT2HslPQP eB4zLgKQPznHMZjytbk6GbBq/uunW6IG6btpwiu1iU23eXrm9MFC3vaILQCmVkK4vKrJ WG1pU5RPoB1n2H2GQJravEBIl2D8LREHDnOrUunwHFRXzphv2dEk+pXc3r2Q7Q9+9yOh Ex9BGZoEeoC7NYRtwL7NzmPE8925czCMTze3MPzJ7QyzBxWTquxSC/tGXpFtr46angsi i8WW9pBKsXKTWiRRuslKq1lE+Rm9ut6XyQNpVfSISkdtDJ6dXKXVCVhwhTiOdlsDHtvu 6IXg== X-Gm-Message-State: ABuFfogZihmA8N9VlzUfuxhZL9WQ31AofD41qw+PNQazYhabSg4fiQw+ 0b72n8ShMfPXjNMYEr5gH6tKXO/Qzj8= X-Google-Smtp-Source: ACcGV62zgK3eyjrmZo2cpMF60SqgWcAhYe/AG7r9tWbtZtvwm1MhgwIMUUUr/fv39lRb9GeG6NeXjA== X-Received: by 2002:a05:6000:1187:: with SMTP id g7mr12735435wrx.173.1538146729721; Fri, 28 Sep 2018 07:58:49 -0700 (PDT) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Fri, 28 Sep 2018 16:58:43 +0200 Message-Id: <20180928145845.20473-3-pbonzini@redhat.com> In-Reply-To: <20180928145845.20473-1-pbonzini@redhat.com> References: <20180928145845.20473-1-pbonzini@redhat.com> X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.30]); Fri, 28 Sep 2018 14:58:52 +0000 (UTC) for IP:'209.85.221.49' DOMAIN:'mail-wr1-f49.google.com' HELO:'mail-wr1-f49.google.com' FROM:'paolo.bonzini@gmail.com' RCPT:'' X-RedHat-Spam-Score: 0.489 (DKIM_SIGNED, DKIM_VALID, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_PASS) 209.85.221.49 mail-wr1-f49.google.com 209.85.221.49 mail-wr1-f49.google.com X-RedHat-Possible-Forgery: Paolo Bonzini X-Scanned-By: MIMEDefang 2.78 on 10.5.110.30 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH v2 2/4] models: convert tags from property to field 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.15 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.45]); Fri, 28 Sep 2018 14:58:55 +0000 (UTC) X-ZohoMail-DKIM: fail (Header signature does not verify) X-ZohoMail: RDMRC_0 RDKM_2 RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Signed-off-by: Paolo Bonzini --- api/migrations/0035_message_tags.py | 22 ++++++++++ api/migrations/0036_populate_message_tags.py | 43 ++++++++++++++++++++ api/models.py | 1 + api/rest.py | 5 ++- api/views.py | 13 +++++- mods/git.py | 5 ++- mods/tags.py | 13 ++---- patchew-cli | 5 ++- www/urls.py | 2 +- 9 files changed, 91 insertions(+), 18 deletions(-) create mode 100644 api/migrations/0035_message_tags.py create mode 100644 api/migrations/0036_populate_message_tags.py diff --git a/api/migrations/0035_message_tags.py b/api/migrations/0035_mess= age_tags.py new file mode 100644 index 0000000..4354bba --- /dev/null +++ b/api/migrations/0035_message_tags.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.13 on 2018-09-27 10:09 +from __future__ import unicode_literals + +from django.db import migrations +import jsonfield.encoder +import jsonfield.fields + + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0034_auto_20180822_1106'), + ] + + operations =3D [ + migrations.AddField( + model_name=3D'message', + name=3D'tags', + field=3Djsonfield.fields.JSONField(default=3D[], dump_kwargs= =3D{'cls': jsonfield.encoder.JSONEncoder, 'separators': (',', ':')}, load_k= wargs=3D{}), + ), + ] diff --git a/api/migrations/0036_populate_message_tags.py b/api/migrations/= 0036_populate_message_tags.py new file mode 100644 index 0000000..e9f2a70 --- /dev/null +++ b/api/migrations/0036_populate_message_tags.py @@ -0,0 +1,43 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations +from django.db.models import Count +import json + + +def tags_from_property(apps, schema_editor): + # We can't import the models directly as they may be a newer + # version than this migration expects. We use the historical version. + Message =3D apps.get_model('api', 'Message') + MessageProperty =3D apps.get_model('api', 'MessageProperty') + messages =3D Message.objects.filter(properties__name=3D'tags') + for m in messages: + mp =3D m.properties.filter(name=3D'tags')[0] + m.tags =3D mp.value + m.save() + MessageProperty.objects.filter(name=3D'tags').delete() + +def tags_to_property(apps, schema_editor): + # We can't import the models directly as they may be a newer + # version than this migration expects. We use the historical version. + Message =3D apps.get_model('api', 'Message') + MessageProperty =3D apps.get_model('api', 'MessageProperty') + messages =3D Message.objects.exclude(tags=3D[]) + for m in messages: + mp =3D MessageProperty(message=3Dm, + name=3D'tags', + value=3Dm.tags, + blob=3DFalse) + mp.save() + +class Migration(migrations.Migration): + + dependencies =3D [ + ('api', '0035_message_tags'), + ] + + operations =3D [ + migrations.RunPython(tags_from_property, + reverse_code=3Dtags_to_property), + ] diff --git a/api/models.py b/api/models.py index a6639b7..ab0bd06 100644 --- a/api/models.py +++ b/api/models.py @@ -460,6 +460,7 @@ class Message(models.Model): version =3D models.PositiveSmallIntegerField(default=3D0) sender =3D jsonfield.JSONCharField(max_length=3D4096, db_index=3DTrue) recipients =3D jsonfield.JSONField() + tags =3D jsonfield.JSONField(default=3D[]) prefixes =3D jsonfield.JSONField(blank=3DTrue) is_series_head =3D models.BooleanField() is_complete =3D models.BooleanField(default=3DFalse) diff --git a/api/rest.py b/api/rest.py index 8789e25..61df8cd 100644 --- a/api/rest.py +++ b/api/rest.py @@ -19,7 +19,7 @@ from .search import SearchEngine from rest_framework import (permissions, serializers, viewsets, filters, mixins, generics, renderers, status) from rest_framework.decorators import detail_route, action -from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField +from rest_framework.fields import SerializerMethodField, CharField, JSONFi= eld, EmailField, ListField from rest_framework.relations import HyperlinkedIdentityField from rest_framework.response import Response import rest_framework @@ -238,11 +238,12 @@ class AddressSerializer(serializers.Serializer): class BaseMessageSerializer(serializers.ModelSerializer): class Meta: model =3D Message - fields =3D ('resource_uri', 'message_id', 'subject', 'date', 'send= er', 'recipients') + fields =3D ('resource_uri', 'message_id', 'subject', 'date', 'send= er', 'recipients', 'tags') =20 resource_uri =3D HyperlinkedMessageField(view_name=3D'messages-detail') recipients =3D AddressSerializer(many=3DTrue) sender =3D AddressSerializer() + tags =3D ListField(child=3DCharField(), required=3DFalse) =20 def create(self, validated_data): validated_data['recipients'] =3D self.fields['recipients'].create(= validated_data['recipients']) diff --git a/api/views.py b/api/views.py index 32bceab..f224a63 100644 --- a/api/views.py +++ b/api/views.py @@ -151,11 +151,18 @@ class SetProjectPropertiesView(APILoginRequiredView): for k, v in properties.items(): po.set_property(k, v) =20 +def get_properties(m): + r =3D m.get_properties() + # for compatibility with patchew-cli's applier mode + if m.tags: + r['tags'] =3D m.tags + return r + def prepare_patch(p): r =3D {"subject": p.subject, "message-id": p.message_id, "mbox": p.get_mbox(), - "properties": p.get_properties(), + "properties": get_properties(p) } return r =20 @@ -173,7 +180,9 @@ def prepare_series(request, s, fields=3DNone): if want_field("patches"): r["patches"] =3D [prepare_patch(x) for x in s.get_patches()] if want_field("properties"): - r["properties"] =3D s.get_properties() + r["properties"] =3D get_properties(s) + if want_field("tags"): + r["tags"] =3D s.tags if want_field("is_complete"): r["is_complete"] =3D s.is_complete if fields: diff --git a/mods/git.py b/mods/git.py index a985ba4..58e4bd2 100644 --- a/mods/git.py +++ b/mods/git.py @@ -228,7 +228,7 @@ class GitModule(PatchewModule): = project)}) =20 def get_base(self, series): - for tag in series.get_property("tags", []): + for tag in series.tags: if not tag.startswith("Based-on:"): continue base_id =3D tag[len("Based-on:"):].strip() @@ -279,7 +279,8 @@ class ApplierGetView(APILoginRequiredView): if not m: return None =20 - response =3D prepare_series(request, m, fields=3D["project", "mess= age-id", "patches", "properties"]) + response =3D prepare_series(request, m, fields=3D["project", "mess= age-id", "patches", + "properties", "tags"= ]) =20 po =3D m.project for prop in ["git.push_to", "git.public_repo", "git.url_template"]: diff --git a/mods/tags.py b/mods/tags.py index 5ec5bc2..1ac27a7 100644 --- a/mods/tags.py +++ b/mods/tags.py @@ -56,10 +56,11 @@ series cover letter, patch mail body and their replies. return set([x.strip() for x in tagsconfig.split(",") if x.strip()]= + BUILT_IN_TAGS) =20 def update_tags(self, s): - old =3D s.get_property("tags", []) + old =3D s.tags new =3D self.look_for_tags(s) if set(old) !=3D set(new): - s.set_property("tags", list(set(new))) + s.tags =3D list(set(new)) + s.save() return True =20 def on_message_added(self, event, message): @@ -84,7 +85,7 @@ series cover letter, patch mail body and their replies. num_reviewed =3D 0 def _find_reviewers(what): ret =3D set() - for rev_tag in [x for x in what.get_property("tags", []) if x.= lower().startswith(REV_BY_PREFIX.lower())]: + for rev_tag in [x for x in what.tags if x.lower().startswith(R= EV_BY_PREFIX.lower())]: ret.add(parse_address(rev_tag[len(REV_BY_PREFIX):])) return ret for p in series.get_patches(): @@ -120,12 +121,6 @@ series cover letter, patch mail body and their replies. r +=3D self.look_for_tags(x) return r =20 - def get_tags(self, m, request, format): - return m.get_property("tags", []) - - def rest_message_fields_hook(self, request, fields): - fields['tags'] =3D PluginMethodField(obj=3Dself) - def prepare_message_hook(self, request, message, detailed): if not message.is_series_head: return diff --git a/patchew-cli b/patchew-cli index c67abd5..b5d6ecb 100755 --- a/patchew-cli +++ b/patchew-cli @@ -693,8 +693,9 @@ class ApplyCommand(SubCommand): subprocess.check_output(["git", "log", "-n", "1", "--format=3D%b"], cwd=3Drepo)= \ .decode('utf-8').splitlines() - for t in set(p["properties"].get("tags", []) + \ - s["properties"].get("tags", [])): + # old servers do not have "tags" directly in the response + for t in set(p["properties"].get("tags", []) + p.get("tags", [= ]) + \ + s["properties"].get("tags", []) + s.get("tags", [= ])): if t in commit_message_lines: continue filter_cmd +=3D "echo '%s';" % t diff --git a/www/urls.py b/www/urls.py index 5787cbd..21b945c 100644 --- a/www/urls.py +++ b/www/urls.py @@ -34,6 +34,6 @@ urlpatterns +=3D [ url(r"^(?P[^/]*)/info$", views.view_project_detail, name= =3D"project_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/$", views.view_ser= ies_detail, name=3D"series_detail"), url(r"^(?P[^/]*)/(?P[^/]*)/(?P[^/]= *)/$", views.view_series_message, name=3D"series_message"), - url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _series_mbox, name=3D"mbox"), + url(r"^(?P[^/]*)/(?P[^/]*)/mbox$", views.view= _mbox, name=3D"mbox"), url(r"^$", views.view_project_list, name=3D"project_list"), ] --=20 2.17.1 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel