Fix migration and models
[pharos-tools.git] / dashboard / src / workflow / models.py
index 4e79546..cdfddef 100644 (file)
@@ -21,6 +21,7 @@ from api.models import JobFactory
 from dashboard.exceptions import ResourceAvailabilityException, ModelValidationException
 from resource_inventory.models import Image, GenericInterface
 from resource_inventory.resource_manager import ResourceManager
+from resource_inventory.pdf_templater import PDFTemplater
 from notifier.manager import NotificationHandler
 from booking.models import Booking
 
@@ -61,15 +62,25 @@ class BookingAuthManager():
     def parse_gerrit_url(self, url):
         project_leads = []
         try:
-            parts = url.split("/")
+            halfs = url.split("?")
+            parts = halfs[0].split("/")
+            args = halfs[1].split(";")
             if "http" in parts[0]:  # the url include http(s)://
                 parts = parts[2:]
-            if "f=INFO.yaml" not in parts[-1].split(";"):
+            if "f=INFO.yaml" not in args:
                 return None
             if "gerrit.opnfv.org" not in parts[0]:
                 return None
+            try:
+                i = args.index("a=blob")
+                args[i] = "a=blob_plain"
+            except ValueError:
+                pass
+            # recreate url
+            halfs[1] = ";".join(args)
+            halfs[0] = "/".join(parts)
             # now to download and parse file
-            url = "https://" + "/".join(parts)
+            url = "https://" + "?".join(halfs)
             info_file = requests.get(url, timeout=15).text
             info_parsed = yaml.load(info_file)
             ptl = info_parsed.get('project_lead')
@@ -138,8 +149,11 @@ class BookingAuthManager():
             return True  # admin override for this user
         if repo.BOOKING_INFO_FILE not in repo.el:
             return False  # INFO file not provided
-        ptl_info = self.parse_url(repo.BOOKING_INFO_FILE)
-        return ptl_info and ptl_info == booking.owner.userprofile.email_addr
+        ptl_info = self.parse_url(repo.el.get(repo.BOOKING_INFO_FILE))
+        for ptl in ptl_info:
+            if ptl['email'] == booking.owner.userprofile.email_addr:
+                return True
+        return False
 
 
 class WorkflowStep(object):
@@ -310,8 +324,8 @@ class Repository():
     SNAPSHOT_DESC = "description of the snapshot"
     BOOKING_INFO_FILE = "the INFO.yaml file for this user's booking"
 
-    #migratory elements of segmented workflow
-    #each of these is the end result of a different workflow.
+    # migratory elements of segmented workflow
+    # each of these is the end result of a different workflow.
     HAS_RESULT = "whether or not workflow has a result"
     RESULT_KEY = "key for target index that result will be put into in parent"
     RESULT = "result object from workflow"
@@ -445,7 +459,7 @@ class Repository():
                         try:
                             interface.host = interface.host
                             interface.save()
-                        except Exception as e:
+                        except Exception:
                             return "GRB, saving interface " + str(interface) + " failed. CODE:0x0019"
             else:
                 return "GRB, no interface set provided. CODE:0x001a"
@@ -564,7 +578,7 @@ class Repository():
             booking.collaborators.add(collaborator)
 
         try:
-            booking.pdf = ResourceManager().makePDF(booking.resource)
+            booking.pdf = PDFTemplater.makePDF(booking.resource)
             booking.save()
         except Exception as e:
             return "BOOK, failed to create Pod Desriptor File: " + str(e)