mirror of
https://github.com/ansible/awx.git
synced 2026-01-29 23:34:42 -03:30
28 lines
916 B
Python
28 lines
916 B
Python
# Copyright (c) 2015 Ansible, Inc.
|
|
# All Rights Reserved
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from crum import impersonate
|
|
from awx.main.models import User, Organization
|
|
|
|
|
|
class Command(BaseCommand):
|
|
"""Creates the default organization if and only if no organizations
|
|
exist in the system.
|
|
"""
|
|
help = 'Creates a default organization iff there are none.'
|
|
|
|
def handle(self, *args, **kwargs):
|
|
# Sanity check: Is there already an organization in the system?
|
|
if Organization.objects.count():
|
|
return
|
|
|
|
# Create a default organization as the first superuser found.
|
|
try:
|
|
superuser = User.objects.filter(is_superuser=True).order_by('pk')[0]
|
|
except IndexError:
|
|
superuser = None
|
|
with impersonate(superuser):
|
|
Organization.objects.create(name='Default')
|
|
print('Default organization added.')
|