Skip to content

Remove json field from RemoteRepositoryRelation and RemoteOrganizationRelation model #7993

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)),
Expand Down
Original file line number Diff line number Diff line change
@@ -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):
Expand Down Expand Up @@ -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)),
Expand Down
21 changes: 0 additions & 21 deletions readthedocs/oauth/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):

Expand Down Expand Up @@ -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
10 changes: 2 additions & 8 deletions readthedocs/oauth/services/bitbucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

Expand Down Expand Up @@ -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(
Expand All @@ -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
)

Expand All @@ -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):
Expand Down
6 changes: 1 addition & 5 deletions readthedocs/oauth/services/github.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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
)

Expand All @@ -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):
Expand Down
10 changes: 3 additions & 7 deletions readthedocs/oauth/services/gitlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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
)

Expand All @@ -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):
Expand Down