diff --git a/api/migrations/0002_auto__del_field_build_version__del_unique_build_version_formation.py b/api/migrations/0002_auto__del_field_build_version__del_unique_build_version_formation.py new file mode 100644 index 0000000000..18a1b3c473 --- /dev/null +++ b/api/migrations/0002_auto__del_field_build_version__del_unique_build_version_formation.py @@ -0,0 +1,206 @@ +# -*- coding: utf-8 -*- +import datetime +from south.db import db +from south.v2 import SchemaMigration +from django.db import models + + +class Migration(SchemaMigration): + + def forwards(self, orm): + # Removing unique constraint on 'Build', fields ['version', 'formation'] + db.delete_unique(u'api_build', ['version', 'formation_id']) + + # Deleting field 'Build.version' + db.delete_column(u'api_build', 'version') + + + def backwards(self, orm): + + # User chose to not deal with backwards NULL issues for 'Build.version' + raise RuntimeError("Cannot reverse this migration. 'Build.version' and its values cannot be restored.") + # Adding unique constraint on 'Build', fields ['version', 'formation'] + db.create_unique(u'api_build', ['version', 'formation_id']) + + + models = { + u'api.access': { + 'Meta': {'object_name': 'Access'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'role': ('django.db.models.fields.CharField', [], {'default': "u'user'", 'max_length': '6'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.build': { + 'Meta': {'ordering': "[u'-created']", 'object_name': 'Build'}, + 'checksum': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'config': ('api.fields.EnvVarsField', [], {'default': "u'null'", 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'dockerfile': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'output': ('django.db.models.fields.TextField', [], {'blank': 'True'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'procfile': ('api.fields.ProcfileField', [], {'default': "u'null'", 'blank': 'True'}), + 'sha': ('django.db.models.fields.CharField', [], {'max_length': '255', 'blank': 'True'}), + 'size': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'url': ('django.db.models.fields.URLField', [], {'max_length': '200'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.config': { + 'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'formation', u'version'),)", 'object_name': 'Config'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}), + 'values': ('api.fields.EnvVarsField', [], {'default': "u'{}'", 'blank': 'True'}), + 'version': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + u'api.container': { + 'Meta': {'unique_together': "((u'formation', u'type', u'num'),)", 'object_name': 'Container'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'id': ('django.db.models.fields.CharField', [], {'max_length': '128', 'blank': 'True'}), + 'metadata': ('json_field.fields.JSONField', [], {'default': "u'null'", 'blank': 'True'}), + 'node': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Node']"}), + 'num': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'port': ('django.db.models.fields.IntegerField', [], {'null': 'True', 'blank': 'True'}), + 'type': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.event': { + 'Meta': {'object_name': 'Event'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.flavor': { + 'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Flavor'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}), + 'init': ('api.fields.CloudInitField', [], {}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'params': ('api.fields.ParamsField', [], {'default': "u'null'"}), + 'provider': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Provider']"}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.formation': { + 'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Formation'}, + 'containers': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}), + 'layers': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.key': { + 'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Key'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'public': ('django.db.models.fields.TextField', [], {}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.layer': { + 'Meta': {'unique_together': "((u'formation', u'id'),)", 'object_name': 'Layer'}, + 'chef_version': ('django.db.models.fields.CharField', [], {'default': "u'11.4.4'", 'max_length': '32'}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'environment': ('django.db.models.fields.CharField', [], {'default': "u'_default'", 'max_length': '64'}), + 'flavor': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Flavor']"}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}), + 'initial_attributes': ('json_field.fields.JSONField', [], {'default': "u'{}'", 'blank': 'True'}), + 'level': ('django.db.models.fields.PositiveIntegerField', [], {'default': '0'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'run_list': ('django.db.models.fields.CharField', [], {'max_length': '512'}), + 'ssh_private_key': ('django.db.models.fields.TextField', [], {}), + 'ssh_public_key': ('django.db.models.fields.TextField', [], {}), + 'ssh_username': ('django.db.models.fields.CharField', [], {'default': "u'ubuntu'", 'max_length': '64'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.node': { + 'Meta': {'unique_together': "((u'formation', u'id'),)", 'object_name': 'Node'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'fqdn': ('django.db.models.fields.CharField', [], {'max_length': '256', 'null': 'True', 'blank': 'True'}), + 'id': ('django.db.models.fields.CharField', [], {'max_length': '64'}), + 'layer': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Layer']"}), + 'num': ('django.db.models.fields.PositiveIntegerField', [], {}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'provider_id': ('django.db.models.fields.SlugField', [], {'max_length': '64', 'null': 'True', 'blank': 'True'}), + 'status': ('api.fields.NodeStatusField', [], {'default': "u'null'", 'null': 'True', 'blank': 'True'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.provider': { + 'Meta': {'unique_together': "((u'owner', u'id'),)", 'object_name': 'Provider'}, + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'creds': ('api.fields.CredentialsField', [], {'default': "u'null'"}), + 'id': ('django.db.models.fields.SlugField', [], {'max_length': '64'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'type': ('django.db.models.fields.SlugField', [], {'max_length': '16'}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}) + }, + u'api.release': { + 'Meta': {'ordering': "[u'-created']", 'unique_together': "((u'formation', u'version'),)", 'object_name': 'Release'}, + 'build': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Build']", 'null': 'True', 'blank': 'True'}), + 'config': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Config']"}), + 'created': ('django.db.models.fields.DateTimeField', [], {'auto_now_add': 'True', 'blank': 'True'}), + 'formation': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['api.Formation']"}), + 'image': ('django.db.models.fields.CharField', [], {'default': "u'ubuntu'", 'max_length': '256'}), + 'owner': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['auth.User']"}), + 'updated': ('django.db.models.fields.DateTimeField', [], {'auto_now': 'True', 'blank': 'True'}), + 'uuid': ('api.fields.UuidField', [], {'unique': 'True', 'max_length': '32', 'primary_key': 'True'}), + 'version': ('django.db.models.fields.PositiveIntegerField', [], {}) + }, + u'auth.group': { + 'Meta': {'object_name': 'Group'}, + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '80'}), + 'permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}) + }, + u'auth.permission': { + 'Meta': {'ordering': "(u'content_type__app_label', u'content_type__model', u'codename')", 'unique_together': "((u'content_type', u'codename'),)", 'object_name': 'Permission'}, + 'codename': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'content_type': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['contenttypes.ContentType']"}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '50'}) + }, + u'auth.user': { + 'Meta': {'object_name': 'User'}, + 'date_joined': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'email': ('django.db.models.fields.EmailField', [], {'max_length': '75', 'blank': 'True'}), + 'first_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'groups': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Group']", 'symmetrical': 'False', 'blank': 'True'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'is_active': ('django.db.models.fields.BooleanField', [], {'default': 'True'}), + 'is_staff': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'is_superuser': ('django.db.models.fields.BooleanField', [], {'default': 'False'}), + 'last_login': ('django.db.models.fields.DateTimeField', [], {'default': 'datetime.datetime.now'}), + 'last_name': ('django.db.models.fields.CharField', [], {'max_length': '30', 'blank': 'True'}), + 'password': ('django.db.models.fields.CharField', [], {'max_length': '128'}), + 'user_permissions': ('django.db.models.fields.related.ManyToManyField', [], {'to': u"orm['auth.Permission']", 'symmetrical': 'False', 'blank': 'True'}), + 'username': ('django.db.models.fields.CharField', [], {'unique': 'True', 'max_length': '30'}) + }, + u'contenttypes.contenttype': { + 'Meta': {'ordering': "('name',)", 'unique_together': "(('app_label', 'model'),)", 'object_name': 'ContentType', 'db_table': "'django_content_type'"}, + 'app_label': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}), + 'model': ('django.db.models.fields.CharField', [], {'max_length': '100'}), + 'name': ('django.db.models.fields.CharField', [], {'max_length': '100'}) + } + } + + complete_apps = ['api'] \ No newline at end of file diff --git a/api/models.py b/api/models.py index 2f9f980882..0334db0c35 100644 --- a/api/models.py +++ b/api/models.py @@ -662,8 +662,6 @@ class Build(UuidAuditedModel): owner = models.ForeignKey(settings.AUTH_USER_MODEL) formation = models.ForeignKey('Formation') - version = models.PositiveIntegerField() - sha = models.CharField('SHA', max_length=255, blank=True) output = models.TextField(blank=True) @@ -678,7 +676,6 @@ class Build(UuidAuditedModel): class Meta: get_latest_by = 'created' ordering = ['-created'] - unique_together = (('formation', 'version'),) def __str__(self): return '{0}-v{1}'.format(self.formation.id, self.version) @@ -694,10 +691,10 @@ def push(cls, push): # SECURITY: # we assume the first part of the ssh key name # is the authenticated user because we trust gitosis - username = push.pop('ssh_key').split('_')[0] + username = push.pop('username').split('_')[0] # retrieve the user and formation instances user = User.objects.get(username=username) - formation = Formation.objects.get(owner=push['owner'], + formation = Formation.objects.get(owner=user, id=push.pop('formation')) # merge the push with the required model instances push['owner'] = user diff --git a/api/tests/build.py b/api/tests/build.py index 232b59d61b..61c8b4b7c8 100644 --- a/api/tests/build.py +++ b/api/tests/build.py @@ -63,7 +63,6 @@ def test_build(self): self.assertEqual(response.status_code, 201) build1 = response.data self.assertEqual(response.data['url'], body['url']) - self.assertEqual(response.data['version'], 1) # read the build response = self.client.get(url) self.assertEqual(response.status_code, 200) @@ -80,7 +79,6 @@ def test_build(self): response = self.client.post(url, json.dumps(body), content_type='application/json') self.assertEqual(response.status_code, 201) build3 = response.data - self.assertEqual(response.data['version'], 2) self.assertEqual(response.data['url'], body['url']) self.assertNotEqual(build2['uuid'], build3['uuid']) # disallow put/patch/delete diff --git a/api/views.py b/api/views.py index 84251b0425..185e24b473 100644 --- a/api/views.py +++ b/api/views.py @@ -10,7 +10,6 @@ from django.conf import settings from django.contrib.auth.models import Group, AnonymousUser, User from django.db.utils import IntegrityError -from django.http.response import Http404 from django.utils import timezone from rest_framework import permissions, status, viewsets from rest_framework.authentication import BaseAuthentication @@ -399,11 +398,6 @@ def post_save(self, obj, created=False): def create(self, request, *args, **kwargs): request._data = request.DATA.copy() - try: - obj = self.get_object() - request.DATA['version'] = obj.version + 1 - except Http404: - request.DATA['version'] = 1 formation = models.Formation.objects.get( owner=self.request.user, id=self.kwargs['id']) request.DATA['formation'] = formation