From nobody Thu Apr 25 05:42:14 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 ARC-Seal: i=1; a=rsa-sha256; t=1557923767; cv=none; d=zoho.com; s=zohoarc; b=NuX++uyjPK0p8a8AMHHgPMFyoK5ovOpIJrbQWVq7icPVy9Ozl5TXiRuTDL4BfMtw+4Aeo7h2Suskj3nFYrgnnJ9vktxOLQVHIKH4x1xw+NjTGER5Z+kzBFTvymuFzGHfeatehMno3XUaAPWP46CNj1j1D5rMJCfsrxpNWm9DWik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557923767; h=Content-Type:Content-Transfer-Encoding:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=3Aemh7V/OYlE1Nrh+eKqWrISybdJdFLLP8G+3GuRrY0=; b=fBxsJ1z4hQK6qpnrVkqJLUHo/GBQevOh7jKbb9FmY50u3HVHqWaOcDUVFMd7EaMKgYFDoPP2XKVjKk2BFB7GckuFBHw5VAZxv/8eolDekbMlfnRc5SiuuOdDKwz8Sw64GH+qcC+EI8jFlpD6wnzW746Fd3ZQRVN6Hg6KuEKA1ks= ARC-Authentication-Results: i=1; mx.zoho.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 header.from= (p=none dis=none) header.from= Return-Path: Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by mx.zohomail.com with SMTPS id 1557923767773529.5457242694553; Wed, 15 May 2019 05:36:07 -0700 (PDT) Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B18175D5FD; Wed, 15 May 2019 12:36:02 +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 A67D7608BA; Wed, 15 May 2019 12:36:02 +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 9A89818089CB; Wed, 15 May 2019 12:36:02 +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 x4FCa1Bv008911 for ; Wed, 15 May 2019 08:36:01 -0400 Received: by smtp.corp.redhat.com (Postfix) id 0BC1E5D9E5; Wed, 15 May 2019 12:36:01 +0000 (UTC) Received: from donizetti.redhat.com (ovpn-112-34.ams2.redhat.com [10.36.112.34]) by smtp.corp.redhat.com (Postfix) with ESMTP id 62FB95D9C3 for ; Wed, 15 May 2019 12:35:56 +0000 (UTC) From: Paolo Bonzini To: patchew-devel@redhat.com Date: Wed, 15 May 2019 14:35:54 +0200 Message-Id: <20190515123554.27035-1-pbonzini@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 X-loop: patchew-devel@redhat.com Subject: [Patchew-devel] [PATCH] mod: use REST API to store project config 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: , 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.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.39]); Wed, 15 May 2019 12:36:02 +0000 (UTC) Content-Type: text/plain; charset="utf-8" This gets rid of the current_project hack and one more legacy APIView; it also fixes the lack of CSRF support in the configuration editor. The conversion from dotted property path to JSON is now done in the client. Signed-off-by: Paolo Bonzini --- api/views.py | 19 ------------------- static/js/config-editor.js | 31 ++++++++++++++++++++++--------- static/js/patchew.js | 6 ------ www/templates/project-detail.html | 6 +++--- 4 files changed, 25 insertions(+), 37 deletions(-) diff --git a/api/views.py b/api/views.py index 672cdc8..b931fff 100644 --- a/api/views.py +++ b/api/views.py @@ -129,25 +129,6 @@ class UpdateProjectHeadView(APILoginRequiredView): return ret =20 =20 -class SetProjectConfigView(APILoginRequiredView): - name =3D "set-project-config" - allowed_groups =3D ["maintainers"] - - def handle(self, request, project, config): - po =3D Project.objects.get(name=3Dproject) - if not po.maintained_by(request.user): - raise PermissionDenied("Access denied to this project") - new_config =3D {} - for k, v in config.items(): - *path, last =3D k.split('.') - parent =3D new_config - for item in path: - parent =3D parent.setdefault(item, {}) - parent[last] =3D v - po.config =3D new_config - po.save() - - def prepare_patch(p): r =3D {"subject": p.subject, "message-id": p.message_id, diff --git a/static/js/config-editor.js b/static/js/config-editor.js index aae5302..0585eae 100644 --- a/static/js/config-editor.js +++ b/static/js/config-editor.js @@ -1,7 +1,3 @@ -function current_project() { - return $('h2').text(); -} - function confirm_leaving_page(enable) { if (enable) { window.onbeforeunload =3D function() { @@ -30,7 +26,16 @@ function save_done(btn, succeeded, error) { function collect_properties(btn, check_required) { properties =3D {}; $(btn).parent().parent().find(".project-property").each(function () { - path =3D $(this).data('property-path'); + path =3D $(this).data('property-path').split('.').reverse(); + parent =3D properties; + while (path.length > 1) { + key =3D path.pop(); + if (!(key in parent)) + parent[key] =3D {}; + parent =3D parent[key]; + } + key =3D path[0]; + if (check_required && this.required && !this.value) { alert($(this).parent().find("label").html() + " is required!"); $(this).focus(); @@ -54,7 +59,7 @@ function collect_properties(btn, check_required) { } else { val =3D this.value; } - properties[path] =3D val; + parent[key] =3D val; }); return properties; } @@ -70,9 +75,17 @@ function properties_save(btn) { $(btn).addClass("disabled"); $(btn).text("Saving..."); $(btn).parent().find(".save-message").remove(); - patchew_api_do("set-project-config", - { project: current_project(), - config: props }) + options =3D { + data: JSON.stringify(props), + type: 'PUT', + dataType: 'json', + headers: { 'Content-Type': 'application/json' } + }; + if ($(btn).data('csrf-token') !=3D '') { + options['headers']['X-CSRFToken'] =3D $(btn).data('csrf-token'); + } + console.log(props); + $.ajax($(btn).data('href'), options) .done(function (data) { save_done(btn, true); }) diff --git a/static/js/patchew.js b/static/js/patchew.js index ce45abd..6e88472 100644 --- a/static/js/patchew.js +++ b/static/js/patchew.js @@ -1,9 +1,3 @@ -function patchew_api_do(method, data) -{ - data =3D {params: JSON.stringify(data)}; - console.log(data); - return $.post("/api/" + method + "/", data); -} function patchew_toggler_onclick(which) { tgt =3D $(which).parent().find(".panel-collapse"); diff --git a/www/templates/project-detail.html b/www/templates/project-deta= il.html index 5895314..81307d0 100644 --- a/www/templates/project-detail.html +++ b/www/templates/project-detail.html @@ -80,9 +80,9 @@ {% endfor %} {% if request.user.is_authenticated %}
- +
{% endif %} --=20 2.21.0 _______________________________________________ Patchew-devel mailing list Patchew-devel@redhat.com https://www.redhat.com/mailman/listinfo/patchew-devel