Limit total number of active bookings per user 01/67501/4
authorSawyer Bergeron <sbergeron@iol.unh.edu>
Mon, 8 Apr 2019 17:17:45 +0000 (13:17 -0400)
committerSawyer Bergeron <sbergeron@iol.unh.edu>
Tue, 16 Apr 2019 16:51:41 +0000 (12:51 -0400)
Change-Id: I4f79e3225f423274de3d2da912a080521447b185
Signed-off-by: Sawyer Bergeron <sbergeron@iol.unh.edu>
dashboard/src/booking/quick_deployer.py
dashboard/src/workflow/models.py

index f076a2e..7059313 100644 (file)
@@ -90,6 +90,10 @@ class NoRemainingPublicNetwork(Exception):
     pass
 
 
+class BookingPermissionException(Exception):
+    pass
+
+
 def parse_host_field(host_field_contents):
     host_json = json.loads(host_field_contents)
     lab_dict = host_json['labs'][0]
@@ -246,6 +250,10 @@ def create_from_form(form, request):
     data['host_profile'] = host_profile
     check_invariants(request, **data)
 
+    # check booking privileges
+    if Booking.objects.filter(owner=request.user, end__gt=timezone.now()).count() >= 3 and not request.user.userprofile.booking_privledge:
+        raise BookingPermissionException("You do not have permission to have more than 3 bookings at a time.")
+
     check_available_matching_host(lab, host_profile)  # requires cleanup if failure after this point
 
     grbundle = generate_grb(request.user, lab, quick_booking_id)
index cdfddef..7d24668 100644 (file)
@@ -143,10 +143,12 @@ class BookingAuthManager():
         currently checks if the booking uses multiple servers. if it does, then the owner must be a PTL,
         which is checked using the provided info file
         """
-        if len(booking.resource.template.getHosts()) < 2:
-            return True  # if they only have one server, we dont care
         if booking.owner.userprofile.booking_privledge:
             return True  # admin override for this user
+        if Booking.objects.filter(owner=booking.owner, end__gt=timezone.now()).count() >= 3:
+            return False
+        if len(booking.resource.template.getHosts()) < 2:
+            return True  # if they only have one server, we dont care
         if repo.BOOKING_INFO_FILE not in repo.el:
             return False  # INFO file not provided
         ptl_info = self.parse_url(repo.el.get(repo.BOOKING_INFO_FILE))