mirror of
https://github.com/ansible/awx.git
synced 2026-05-20 23:37:39 -02:30
Single organization license diff.
This commit is contained in:
26
awx/api/license.py
Normal file
26
awx/api/license.py
Normal file
@@ -0,0 +1,26 @@
|
||||
# Copyright (c) 2015 Ansible, Inc.
|
||||
# All Rights Reserved.
|
||||
|
||||
from rest_framework.exceptions import APIException
|
||||
|
||||
from awx.main.task_engine import TaskSerializer
|
||||
|
||||
|
||||
class LicenseForbids(APIException):
|
||||
status_code = 402
|
||||
default_detail = 'Your Tower license does not allow that.'
|
||||
|
||||
|
||||
def get_license(show_key=False):
|
||||
"""Return a dictionary representing the license currently in
|
||||
place on this Tower instance.
|
||||
"""
|
||||
license_reader = TaskSerializer()
|
||||
return license_reader.from_file(show_key=show_key)
|
||||
|
||||
|
||||
def feature_enabled(name):
|
||||
"""Return True if the requested feature is enabled, False otherwise.
|
||||
If the feature does not exist, raise KeyError.
|
||||
"""
|
||||
return get_license()['features'][name]
|
||||
@@ -483,6 +483,24 @@ class OrganizationList(ListCreateAPIView):
|
||||
model = Organization
|
||||
serializer_class = OrganizationSerializer
|
||||
|
||||
def create(self, request, *args, **kwargs):
|
||||
"""Create a new organzation.
|
||||
|
||||
If there is already an organization and the license of the Tower
|
||||
instance does not permit multiple organizations, then raise
|
||||
LicenseForbids.
|
||||
"""
|
||||
# Sanity check: If the multiple organizations feature is disallowed
|
||||
# by the license, then we are only willing to create this organization
|
||||
# if no organizations exist in the system.
|
||||
if (not feature_enabled('multiple_organizations') and
|
||||
self.model.objects.filter(active=True).count() > 0):
|
||||
raise LicenseForbids('This Tower license only permits a single '
|
||||
'organization to exist.')
|
||||
|
||||
# Okay, create the organization as usual.
|
||||
return super(OrganizationList, self).create(request, *args, **kwargs)
|
||||
|
||||
class OrganizationDetail(RetrieveUpdateDestroyAPIView):
|
||||
|
||||
model = Organization
|
||||
|
||||
Reference in New Issue
Block a user