mirror of
https://github.com/ZwareBear/awx.git
synced 2026-04-22 07:51:52 -05:00
Added code to raise permission denied on exceeded server counts using licensing system.
Some very minor/misc cleanup and minor docs also included.
This commit is contained in:
@@ -5,6 +5,9 @@ import logging
|
||||
from django.db.models import Q
|
||||
from django.contrib.auth.models import User
|
||||
from awx.main.models import *
|
||||
from awx.main.licenses import LicenseReader
|
||||
from django.core.exceptions import PermissionDenied
|
||||
import sys
|
||||
|
||||
__all__ = ['get_user_queryset', 'check_user_access']
|
||||
|
||||
@@ -242,11 +245,32 @@ class HostAccess(BaseAccess):
|
||||
return check_user_access(self.user, Inventory, 'read', obj.inventory)
|
||||
|
||||
def can_add(self, data):
|
||||
|
||||
|
||||
if not 'inventory' in data:
|
||||
return False
|
||||
|
||||
inventory = Inventory.objects.get(pk=data['inventory'])
|
||||
|
||||
# Checks for admin or change permission on inventory.
|
||||
return check_user_access(self.user, Inventory, 'change', inventory, None)
|
||||
permissions_ok = check_user_access(self.user, Inventory, 'change', inventory, None)
|
||||
if not permissions_ok:
|
||||
return False
|
||||
|
||||
# Check to see if we have enough licenses
|
||||
reader = LicenseReader()
|
||||
validation_info = reader.from_file()
|
||||
|
||||
if 'test' in sys.argv and 'free_instances' in validation_info:
|
||||
# this hack is in here so the test code can function
|
||||
# but still go down *most* of the license code path.
|
||||
validation_info['free_instances'] = 99999999
|
||||
|
||||
if validation_info['free_instances'] > 0:
|
||||
# BOOKMARK
|
||||
return True
|
||||
instances = validation_info['available_instances']
|
||||
raise PermissionDenied("license range of %s instances has been exceed" % instances)
|
||||
|
||||
def can_change(self, obj, data):
|
||||
# Checks for admin or change permission on inventory, controls whether
|
||||
|
||||
Reference in New Issue
Block a user