diff options
author | Parker Berberian <pberberian@iol.unh.edu> | 2019-04-16 16:53:08 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@opnfv.org> | 2019-04-16 16:53:08 +0000 |
commit | aef82a1a9b2ba3524f33b23462ad469b44b37c71 (patch) | |
tree | 04c3f6250fd06773a002bfb9e074d048ad06ac44 /dashboard/src | |
parent | b2c5b21679ff2411b44ea90faef5ccae90cafac0 (diff) | |
parent | 2256207ce42d9314ea50c9286e0db37098834530 (diff) |
Merge "Limit total number of active bookings per user"
Diffstat (limited to 'dashboard/src')
-rw-r--r-- | dashboard/src/booking/quick_deployer.py | 8 | ||||
-rw-r--r-- | dashboard/src/workflow/models.py | 6 |
2 files changed, 12 insertions, 2 deletions
diff --git a/dashboard/src/booking/quick_deployer.py b/dashboard/src/booking/quick_deployer.py index cc593fa..640ded9 100644 --- a/dashboard/src/booking/quick_deployer.py +++ b/dashboard/src/booking/quick_deployer.py @@ -92,6 +92,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] @@ -262,6 +266,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) diff --git a/dashboard/src/workflow/models.py b/dashboard/src/workflow/models.py index 3784fe1..4ebb042 100644 --- a/dashboard/src/workflow/models.py +++ b/dashboard/src/workflow/models.py @@ -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)) |