From 90a68a83a8e0126fcb8b9b9f52a827a7d84f8c4c Mon Sep 17 00:00:00 2001
From: Gerhard le Roux <gerhardlr@gmail.com>
Date: Mon, 6 Jul 2020 15:00:00 +0000
Subject: [PATCH] add cors and validation

---
 .../grafana-plugins/pytest-command/src/ButtonPanel.tsx | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/grafana/grafana-plugins/pytest-command/src/ButtonPanel.tsx b/grafana/grafana-plugins/pytest-command/src/ButtonPanel.tsx
index c01fe9b..af49a71 100755
--- a/grafana/grafana-plugins/pytest-command/src/ButtonPanel.tsx
+++ b/grafana/grafana-plugins/pytest-command/src/ButtonPanel.tsx
@@ -11,7 +11,7 @@ export const ButtonPanel: React.FC<Props> = ({ options, data, width, height }) =
   const handleClick = async () => {
     const result = await fetch(options.url, {
       method: 'POST', // *GET, POST, PUT, DELETE, etc.
-      mode: 'no-cors', // no-cors, *cors, same-origin
+      mode: 'cors', // no-cors, *cors, same-origin
       cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
       credentials: 'same-origin', // include, *same-origin, omit
       headers: {
@@ -36,8 +36,12 @@ export const ButtonPanel: React.FC<Props> = ({ options, data, width, height }) =
       setError(result.statusText);
       return;
     }
-    if (json['data']['executeCommand']['ok']) {
-      alert('Command executed successfully. ');
+    if (json['path'] === options.test_path) {
+      if (json['module'] === options.test_module) {
+        if (json['test'] === options.test_name) {
+          alert('Command executed successfully. ');
+        }
+      }
     } else {
       setError(json['data']['executeCommand']['message']);
       alert('Command failed!');
-- 
GitLab