mirror of
https://github.com/ansible/awx.git
synced 2026-04-11 13:09:21 -02:30
Merge pull request #1350 from anoek/rbac
Split active flag removal migration
This commit is contained in:
@@ -521,10 +521,6 @@ class BaseSerializer(serializers.ModelSerializer):
|
|||||||
raise ValidationError(d)
|
raise ValidationError(d)
|
||||||
return attrs
|
return attrs
|
||||||
|
|
||||||
def to_representation(self, obj):
|
|
||||||
ret = super(BaseSerializer, self).to_representation(obj)
|
|
||||||
return ret
|
|
||||||
|
|
||||||
|
|
||||||
class EmptySerializer(serializers.Serializer):
|
class EmptySerializer(serializers.Serializer):
|
||||||
pass
|
pass
|
||||||
|
|||||||
@@ -569,7 +569,7 @@ class OrganizationList(ListCreateAPIView):
|
|||||||
# by the license, then we are only willing to create this organization
|
# by the license, then we are only willing to create this organization
|
||||||
# if no organizations exist in the system.
|
# if no organizations exist in the system.
|
||||||
if (not feature_enabled('multiple_organizations') and
|
if (not feature_enabled('multiple_organizations') and
|
||||||
self.model.objects.count() > 0):
|
self.model.objects.exists()):
|
||||||
raise LicenseForbids('Your Tower license only permits a single '
|
raise LicenseForbids('Your Tower license only permits a single '
|
||||||
'organization to exist.')
|
'organization to exist.')
|
||||||
|
|
||||||
|
|||||||
@@ -644,7 +644,7 @@ class ProjectAccess(BaseAccess):
|
|||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
return True
|
return True
|
||||||
qs = Organization.accessible_objects(self.user, ALL_PERMISSIONS)
|
qs = Organization.accessible_objects(self.user, ALL_PERMISSIONS)
|
||||||
return bool(qs.count() > 0)
|
return qs.exists()
|
||||||
|
|
||||||
def can_change(self, obj, data):
|
def can_change(self, obj, data):
|
||||||
if self.user.is_superuser:
|
if self.user.is_superuser:
|
||||||
|
|||||||
16
awx/main/migrations/0006_v300_active_flag_cleanup.py
Normal file
16
awx/main/migrations/0006_v300_active_flag_cleanup.py
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from awx.main.migrations import _cleanup_deleted as cleanup_deleted
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('main', '0005_v300_migrate_facts'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.RunPython(cleanup_deleted.cleanup_deleted),
|
||||||
|
]
|
||||||
@@ -1,19 +1,16 @@
|
|||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
from awx.main.migrations import _cleanup_deleted as cleanup_deleted
|
|
||||||
from django.db import migrations
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0005_v300_migrate_facts'),
|
('main', '0006_v300_active_flag_cleanup'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
migrations.RunPython(cleanup_deleted.cleanup_deleted),
|
|
||||||
|
|
||||||
migrations.RemoveField(
|
migrations.RemoveField(
|
||||||
model_name='credential',
|
model_name='credential',
|
||||||
name='active',
|
name='active',
|
||||||
@@ -14,7 +14,7 @@ class Migration(migrations.Migration):
|
|||||||
('taggit', '0002_auto_20150616_2121'),
|
('taggit', '0002_auto_20150616_2121'),
|
||||||
('contenttypes', '0002_remove_content_type_name'),
|
('contenttypes', '0002_remove_content_type_name'),
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
('main', '0006_v300_active_flag_removal'),
|
('main', '0007_v300_active_flag_removal'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -8,7 +8,7 @@ from django.db import migrations
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0007_v300_rbac_changes'),
|
('main', '0008_v300_rbac_changes'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -107,7 +107,7 @@ def create_system_job_templates(apps, schema_editor):
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0008_v300_rbac_migrations'),
|
('main', '0009_v300_rbac_migrations'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -7,7 +7,7 @@ from django.db import migrations, models
|
|||||||
class Migration(migrations.Migration):
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
('main', '0009_v300_create_system_job_templates'),
|
('main', '0010_v300_create_system_job_templates'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -12,7 +12,7 @@ class Migration(migrations.Migration):
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
('taggit', '0002_auto_20150616_2121'),
|
('taggit', '0002_auto_20150616_2121'),
|
||||||
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
|
||||||
('main', '0010_v300_credential_domain_field'),
|
('main', '0011_v300_credential_domain_field'),
|
||||||
]
|
]
|
||||||
|
|
||||||
operations = [
|
operations = [
|
||||||
@@ -13,7 +13,7 @@ class Migration(DataMigration):
|
|||||||
# and orm['appname.ModelName'] for models in other applications.
|
# and orm['appname.ModelName'] for models in other applications.
|
||||||
|
|
||||||
# Refresh has_active_failures for all hosts.
|
# Refresh has_active_failures for all hosts.
|
||||||
for host in orm.Host.objects:
|
for host in orm.Host.objects.filter(active=True):
|
||||||
has_active_failures = bool(host.last_job_host_summary and
|
has_active_failures = bool(host.last_job_host_summary and
|
||||||
host.last_job_host_summary.job.active and
|
host.last_job_host_summary.job.active and
|
||||||
host.last_job_host_summary.failed)
|
host.last_job_host_summary.failed)
|
||||||
@@ -30,9 +30,9 @@ class Migration(DataMigration):
|
|||||||
for subgroup in group.children.exclude(pk__in=except_group_pks):
|
for subgroup in group.children.exclude(pk__in=except_group_pks):
|
||||||
qs = qs | get_all_hosts_for_group(subgroup, except_group_pks)
|
qs = qs | get_all_hosts_for_group(subgroup, except_group_pks)
|
||||||
return qs
|
return qs
|
||||||
for group in orm.Group.objects:
|
for group in orm.Group.objects.filter(active=True):
|
||||||
all_hosts = get_all_hosts_for_group(group)
|
all_hosts = get_all_hosts_for_group(group)
|
||||||
failed_hosts = all_hosts.filter(
|
failed_hosts = all_hosts.filter(active=True,
|
||||||
last_job_host_summary__job__active=True,
|
last_job_host_summary__job__active=True,
|
||||||
last_job_host_summary__failed=True)
|
last_job_host_summary__failed=True)
|
||||||
hosts_with_active_failures = failed_hosts.count()
|
hosts_with_active_failures = failed_hosts.count()
|
||||||
@@ -49,8 +49,8 @@ class Migration(DataMigration):
|
|||||||
|
|
||||||
# Now update has_active_failures and hosts_with_active_failures for all
|
# Now update has_active_failures and hosts_with_active_failures for all
|
||||||
# inventories.
|
# inventories.
|
||||||
for inventory in orm.Inventory.objects:
|
for inventory in orm.Inventory.objects.filter(active=True):
|
||||||
failed_hosts = inventory.hosts.filter( has_active_failures=True)
|
failed_hosts = inventory.hosts.filter(active=True, has_active_failures=True)
|
||||||
hosts_with_active_failures = failed_hosts.count()
|
hosts_with_active_failures = failed_hosts.count()
|
||||||
has_active_failures = bool(hosts_with_active_failures)
|
has_active_failures = bool(hosts_with_active_failures)
|
||||||
changed = False
|
changed = False
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ from django.db import models
|
|||||||
class Migration(DataMigration):
|
class Migration(DataMigration):
|
||||||
|
|
||||||
def forwards(self, orm):
|
def forwards(self, orm):
|
||||||
for iu in orm.InventoryUpdate.objects:
|
for iu in orm.InventoryUpdate.objects.filter(active=True):
|
||||||
if iu.inventory_source is None or iu.inventory_source.group is None or iu.inventory_source.inventory is None:
|
if iu.inventory_source is None or iu.inventory_source.group is None or iu.inventory_source.inventory is None:
|
||||||
continue
|
continue
|
||||||
iu.name = "%s (%s)" % (iu.inventory_source.group.name, iu.inventory_source.inventory.name)
|
iu.name = "%s (%s)" % (iu.inventory_source.group.name, iu.inventory_source.inventory.name)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ from django.conf import settings
|
|||||||
class Migration(DataMigration):
|
class Migration(DataMigration):
|
||||||
|
|
||||||
def forwards(self, orm):
|
def forwards(self, orm):
|
||||||
for j in orm.UnifiedJob.objects:
|
for j in orm.UnifiedJob.objects.filter(active=True):
|
||||||
cur = connection.cursor()
|
cur = connection.cursor()
|
||||||
stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, "%d-%s.out" % (j.pk, str(uuid.uuid1())))
|
stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, "%d-%s.out" % (j.pk, str(uuid.uuid1())))
|
||||||
fd = open(stdout_filename, 'w')
|
fd = open(stdout_filename, 'w')
|
||||||
|
|||||||
Reference in New Issue
Block a user