Merge pull request #1350 from anoek/rbac

Split active flag removal migration
This commit is contained in:
Wayne Witzel III 2016-03-31 10:05:59 -04:00
commit d20d67d5f3
13 changed files with 31 additions and 22 deletions

View File

@ -521,10 +521,6 @@ class BaseSerializer(serializers.ModelSerializer):
raise ValidationError(d)
return attrs
def to_representation(self, obj):
ret = super(BaseSerializer, self).to_representation(obj)
return ret
class EmptySerializer(serializers.Serializer):
pass

View File

@ -569,7 +569,7 @@ class OrganizationList(ListCreateAPIView):
# 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.count() > 0):
self.model.objects.exists()):
raise LicenseForbids('Your Tower license only permits a single '
'organization to exist.')

View File

@ -644,7 +644,7 @@ class ProjectAccess(BaseAccess):
if self.user.is_superuser:
return True
qs = Organization.accessible_objects(self.user, ALL_PERMISSIONS)
return bool(qs.count() > 0)
return qs.exists()
def can_change(self, obj, data):
if self.user.is_superuser:

View 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),
]

View File

@ -1,19 +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'),
('main', '0006_v300_active_flag_cleanup'),
]
operations = [
migrations.RunPython(cleanup_deleted.cleanup_deleted),
migrations.RemoveField(
model_name='credential',
name='active',

View File

@ -14,7 +14,7 @@ class Migration(migrations.Migration):
('taggit', '0002_auto_20150616_2121'),
('contenttypes', '0002_remove_content_type_name'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('main', '0006_v300_active_flag_removal'),
('main', '0007_v300_active_flag_removal'),
]
operations = [

View File

@ -8,7 +8,7 @@ from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('main', '0007_v300_rbac_changes'),
('main', '0008_v300_rbac_changes'),
]
operations = [

View File

@ -107,7 +107,7 @@ def create_system_job_templates(apps, schema_editor):
class Migration(migrations.Migration):
dependencies = [
('main', '0008_v300_rbac_migrations'),
('main', '0009_v300_rbac_migrations'),
]
operations = [

View File

@ -7,7 +7,7 @@ from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0009_v300_create_system_job_templates'),
('main', '0010_v300_create_system_job_templates'),
]
operations = [

View File

@ -12,7 +12,7 @@ class Migration(migrations.Migration):
dependencies = [
('taggit', '0002_auto_20150616_2121'),
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('main', '0010_v300_credential_domain_field'),
('main', '0011_v300_credential_domain_field'),
]
operations = [

View File

@ -13,7 +13,7 @@ class Migration(DataMigration):
# and orm['appname.ModelName'] for models in other applications.
# 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
host.last_job_host_summary.job.active and
host.last_job_host_summary.failed)
@ -30,9 +30,9 @@ class Migration(DataMigration):
for subgroup in group.children.exclude(pk__in=except_group_pks):
qs = qs | get_all_hosts_for_group(subgroup, except_group_pks)
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)
failed_hosts = all_hosts.filter(
failed_hosts = all_hosts.filter(active=True,
last_job_host_summary__job__active=True,
last_job_host_summary__failed=True)
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
# inventories.
for inventory in orm.Inventory.objects:
failed_hosts = inventory.hosts.filter( has_active_failures=True)
for inventory in orm.Inventory.objects.filter(active=True):
failed_hosts = inventory.hosts.filter(active=True, has_active_failures=True)
hosts_with_active_failures = failed_hosts.count()
has_active_failures = bool(hosts_with_active_failures)
changed = False

View File

@ -8,7 +8,7 @@ from django.db import models
class Migration(DataMigration):
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:
continue
iu.name = "%s (%s)" % (iu.inventory_source.group.name, iu.inventory_source.inventory.name)

View File

@ -12,7 +12,7 @@ from django.conf import settings
class Migration(DataMigration):
def forwards(self, orm):
for j in orm.UnifiedJob.objects:
for j in orm.UnifiedJob.objects.filter(active=True):
cur = connection.cursor()
stdout_filename = os.path.join(settings.JOBOUTPUT_ROOT, "%d-%s.out" % (j.pk, str(uuid.uuid1())))
fd = open(stdout_filename, 'w')