From b347fe749db86e7ef098243668c939fcf1ad9aeb Mon Sep 17 00:00:00 2001
From: chausman <chausman@nrao.edu>
Date: Fri, 12 Aug 2022 11:38:41 -0600
Subject: [PATCH] make sure qa notes is using the correct weblog location

---
 services/workflow/workflow/server.py | 33 ++++++++++++++--------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/services/workflow/workflow/server.py b/services/workflow/workflow/server.py
index 0757efa34..a3c3e3712 100644
--- a/services/workflow/workflow/server.py
+++ b/services/workflow/workflow/server.py
@@ -17,6 +17,7 @@
 # along with Workspaces.  If not, see <https://www.gnu.org/licenses/>.
 # pylint: disable=E0401
 """ This is our workflow server API. """
+import glob
 import http
 import json
 import logging
@@ -183,31 +184,31 @@ class WorkflowWorkingDirRestService:
     def get_qa_notes(self):
         requested_workflow = self.request.info.lookup_workflow_request(self.request.matchdict["request_id"])
         results_path = requested_workflow.results_dir
-        paths = []
-        for root, dirs, _ in os.walk(results_path, followlinks=True):
-            for d in dirs:
-                if d.startswith("pipeline-"):
-                    paths.append(os.path.join(root, d))
 
-        qa_notes_path = paths[0] + "/html/qa_notes.html"
-        qa_notes_text = ""
+        # qa notes need the products directory weblog
+        path = glob.glob(results_path + "/products/pipeline-*/html")[0]
+        qa_notes_path = path + "/qa_notes.html"
 
-        with open(qa_notes_path, "r") as qa_notes:
-            qa_notes_text = qa_notes.read()
+        if Path(qa_notes_path).exists():
+            qa_notes_text = ""
+            with open(qa_notes_path, "r") as qa_notes:
+                qa_notes_text = qa_notes.read()
 
-        return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{qa_notes_text}"})
+            return Response(status_int=http.HTTPStatus.OK, json_body={"resp": f"{qa_notes_text}"})
+
+        return Response(
+            status_int=http.HTTPStatus.NOT_FOUND,
+            json_body={"resp": "QA Notes file not found. Please close the window and try again."},
+        )
 
     @view_config(request_method="POST", route_name="get_qa_notes", renderer="json")
     def save_qa_notes(self):
         requested_workflow = self.request.info.lookup_workflow_request(self.request.matchdict["request_id"])
         results_path = requested_workflow.results_dir
-        paths = []
-        for root, dirs, _ in os.walk(results_path, followlinks=True):
-            for d in dirs:
-                if d.startswith("pipeline-"):
-                    paths.append(os.path.join(root, d))
 
-        qa_notes_path = paths[0] + "/html/qa_notes.html"
+        # qa notes need the products directory weblog
+        path = glob.glob(results_path + "/products/pipeline-*/html")[0]
+        qa_notes_path = path + "/qa_notes.html"
 
         with open(qa_notes_path, "w") as qa_notes:
             # sanitize input before writing/persisting
-- 
GitLab