diff --git a/readthedocs/oauth/migrations/0012_create_new_table_for_remote_organization_normalization.py b/readthedocs/oauth/migrations/0012_create_new_table_for_remote_organization_normalization.py index a23ad03bd10..233473fd929 100644 --- a/readthedocs/oauth/migrations/0012_create_new_table_for_remote_organization_normalization.py +++ b/readthedocs/oauth/migrations/0012_create_new_table_for_remote_organization_normalization.py @@ -4,7 +4,6 @@ from django.db import migrations, models import django.db.models.deletion import django_extensions.db.fields -import jsonfield.fields class Migration(migrations.Migration): @@ -41,7 +40,6 @@ class Migration(migrations.Migration): ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), - ('json', jsonfield.fields.JSONField(verbose_name='Serialized API response')), ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to='socialaccount.SocialAccount', verbose_name='Connected account')), ('remote_organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to='oauth.RemoteOrganization')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to=settings.AUTH_USER_MODEL)), diff --git a/readthedocs/oauth/migrations/0013_create_new_table_for_remote_repository_normalization.py b/readthedocs/oauth/migrations/0013_create_new_table_for_remote_repository_normalization.py index 86cdab720f5..f2dd10d39d7 100644 --- a/readthedocs/oauth/migrations/0013_create_new_table_for_remote_repository_normalization.py +++ b/readthedocs/oauth/migrations/0013_create_new_table_for_remote_repository_normalization.py @@ -1,11 +1,9 @@ # Generated by Django 2.2.17 on 2020-12-21 18:16 from django.conf import settings -import django.core.validators from django.db import migrations, models import django.db.models.deletion import django_extensions.db.fields -import jsonfield.fields class Migration(migrations.Migration): @@ -52,7 +50,6 @@ class Migration(migrations.Migration): ('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')), ('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')), ('admin', models.BooleanField(default=False, verbose_name='Has admin privilege')), - ('json', jsonfield.fields.JSONField(verbose_name='Serialized API response')), ('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to='socialaccount.SocialAccount', verbose_name='Connected account')), ('remote_repository', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to='oauth.RemoteRepository')), ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to=settings.AUTH_USER_MODEL)), diff --git a/readthedocs/oauth/models.py b/readthedocs/oauth/models.py index a02b3812029..c5afbe2d4f3 100644 --- a/readthedocs/oauth/models.py +++ b/readthedocs/oauth/models.py @@ -11,7 +11,6 @@ from allauth.socialaccount.models import SocialAccount from django_extensions.db.models import TimeStampedModel -from jsonfield import JSONField from readthedocs.projects.constants import REPO_CHOICES from readthedocs.projects.models import Project @@ -94,20 +93,10 @@ class RemoteOrganizationRelation(TimeStampedModel): related_name='remote_organization_relations', on_delete=models.CASCADE ) - json = JSONField(_('Serialized API response')) # noqa: F811 class Meta: unique_together = ('remote_organization', 'account',) - def get_serialized(self, key=None, default=None): - try: - data = self.json - if key is not None: - return data.get(key, default) - return data - except ValueError: - pass - class RemoteRepository(TimeStampedModel): @@ -266,16 +255,6 @@ class RemoteRepositoryRelation(TimeStampedModel): on_delete=models.CASCADE ) admin = models.BooleanField(_('Has admin privilege'), default=False) - json = JSONField(_('Serialized API response')) # noqa: F811 class Meta: unique_together = ('remote_repository', 'account',) - - def get_serialized(self, key=None, default=None): - try: - data = self.json - if key is not None: - return data.get(key, default) - return data - except ValueError: - pass diff --git a/readthedocs/oauth/services/bitbucket.py b/readthedocs/oauth/services/bitbucket.py index 1741a7580ca..119f386fc29 100644 --- a/readthedocs/oauth/services/bitbucket.py +++ b/readthedocs/oauth/services/bitbucket.py @@ -136,7 +136,7 @@ def create_repository(self, fields, privacy=None, organization=None): remote_id=fields['uuid'], vcs_provider=self.vcs_provider_slug ) - remote_repository_relation = repo.get_remote_repository_relation( + repo.get_remote_repository_relation( self.user, self.account ) @@ -178,9 +178,6 @@ def create_repository(self, fields, privacy=None, organization=None): repo.save() - remote_repository_relation.json = fields - remote_repository_relation.save() - return repo log.debug( @@ -199,7 +196,7 @@ def create_organization(self, fields): remote_id=fields['uuid'], vcs_provider=self.vcs_provider_slug ) - remote_organization_relation = organization.get_remote_organization_relation( + organization.get_remote_organization_relation( self.user, self.account ) @@ -215,9 +212,6 @@ def create_organization(self, fields): organization.save() - remote_organization_relation.json = fields - remote_organization_relation.save() - return organization def get_next_url_to_paginate(self, response): diff --git a/readthedocs/oauth/services/github.py b/readthedocs/oauth/services/github.py index ed0957891b8..33a15c6bea8 100644 --- a/readthedocs/oauth/services/github.py +++ b/readthedocs/oauth/services/github.py @@ -141,7 +141,6 @@ def create_repository(self, fields, privacy=None, organization=None): repo.save() - remote_repository_relation.json = fields remote_repository_relation.admin = fields.get('permissions', {}).get('admin', False) remote_repository_relation.save() @@ -163,7 +162,7 @@ def create_organization(self, fields): remote_id=fields['id'], vcs_provider=self.vcs_provider_slug ) - remote_organization_relation = organization.get_remote_organization_relation( + organization.get_remote_organization_relation( self.user, self.account ) @@ -179,9 +178,6 @@ def create_organization(self, fields): organization.save() - remote_organization_relation.json = fields - remote_organization_relation.save() - return organization def get_next_url_to_paginate(self, response): diff --git a/readthedocs/oauth/services/gitlab.py b/readthedocs/oauth/services/gitlab.py index 8d2f215324a..6213c876968 100644 --- a/readthedocs/oauth/services/gitlab.py +++ b/readthedocs/oauth/services/gitlab.py @@ -55,8 +55,8 @@ def _get_repo_id(self, project): # The ID or URL-encoded path of the project # https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding try: - repo_id = json.loads(project.remote_repository.json).get('id') - except Exception: + repo_id = project.remote_repository.remote_id + except Project.remote_repository.RelatedObjectDoesNotExist: # Handle "Manual Import" when there is no RemoteRepository # associated with the project. It only works with gitlab.com at the # moment (doesn't support custom gitlab installations) @@ -248,7 +248,6 @@ def create_repository(self, fields, privacy=None, organization=None): project_access_level in (self.PERMISSION_MAINTAINER, self.PERMISSION_OWNER), group_access_level in (self.PERMISSION_MAINTAINER, self.PERMISSION_OWNER), ]) - remote_repository_relation.json = fields remote_repository_relation.save() return repo @@ -270,7 +269,7 @@ def create_organization(self, fields): remote_id=fields['id'], vcs_provider=self.vcs_provider_slug ) - remote_organization_relation = organization.get_remote_organization_relation( + organization.get_remote_organization_relation( self.user, self.account ) @@ -287,9 +286,6 @@ def create_organization(self, fields): organization.save() - remote_organization_relation.json = fields - remote_organization_relation.save() - return organization def get_webhook_data(self, repo_id, project, integration):