Skip to content

Commit 5317c80

Browse files
authored
Merge pull request #7993 from saadmk11/remove-json-field
2 parents 76604af + 12e6f64 commit 5317c80

6 files changed

+6
-46
lines changed

readthedocs/oauth/migrations/0012_create_new_table_for_remote_organization_normalization.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
from django.db import migrations, models
55
import django.db.models.deletion
66
import django_extensions.db.fields
7-
import jsonfield.fields
87

98

109
class Migration(migrations.Migration):
@@ -41,7 +40,6 @@ class Migration(migrations.Migration):
4140
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
4241
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
4342
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
44-
('json', jsonfield.fields.JSONField(verbose_name='Serialized API response')),
4543
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to='socialaccount.SocialAccount', verbose_name='Connected account')),
4644
('remote_organization', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to='oauth.RemoteOrganization')),
4745
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_organization_relations', to=settings.AUTH_USER_MODEL)),

readthedocs/oauth/migrations/0013_create_new_table_for_remote_repository_normalization.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
# Generated by Django 2.2.17 on 2020-12-21 18:16
22

33
from django.conf import settings
4-
import django.core.validators
54
from django.db import migrations, models
65
import django.db.models.deletion
76
import django_extensions.db.fields
8-
import jsonfield.fields
97

108

119
class Migration(migrations.Migration):
@@ -52,7 +50,6 @@ class Migration(migrations.Migration):
5250
('created', django_extensions.db.fields.CreationDateTimeField(auto_now_add=True, verbose_name='created')),
5351
('modified', django_extensions.db.fields.ModificationDateTimeField(auto_now=True, verbose_name='modified')),
5452
('admin', models.BooleanField(default=False, verbose_name='Has admin privilege')),
55-
('json', jsonfield.fields.JSONField(verbose_name='Serialized API response')),
5653
('account', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to='socialaccount.SocialAccount', verbose_name='Connected account')),
5754
('remote_repository', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to='oauth.RemoteRepository')),
5855
('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='remote_repository_relations', to=settings.AUTH_USER_MODEL)),

readthedocs/oauth/models.py

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from allauth.socialaccount.models import SocialAccount
1313
from django_extensions.db.models import TimeStampedModel
14-
from jsonfield import JSONField
1514

1615
from readthedocs.projects.constants import REPO_CHOICES
1716
from readthedocs.projects.models import Project
@@ -94,20 +93,10 @@ class RemoteOrganizationRelation(TimeStampedModel):
9493
related_name='remote_organization_relations',
9594
on_delete=models.CASCADE
9695
)
97-
json = JSONField(_('Serialized API response')) # noqa: F811
9896

9997
class Meta:
10098
unique_together = ('remote_organization', 'account',)
10199

102-
def get_serialized(self, key=None, default=None):
103-
try:
104-
data = self.json
105-
if key is not None:
106-
return data.get(key, default)
107-
return data
108-
except ValueError:
109-
pass
110-
111100

112101
class RemoteRepository(TimeStampedModel):
113102

@@ -266,16 +255,6 @@ class RemoteRepositoryRelation(TimeStampedModel):
266255
on_delete=models.CASCADE
267256
)
268257
admin = models.BooleanField(_('Has admin privilege'), default=False)
269-
json = JSONField(_('Serialized API response')) # noqa: F811
270258

271259
class Meta:
272260
unique_together = ('remote_repository', 'account',)
273-
274-
def get_serialized(self, key=None, default=None):
275-
try:
276-
data = self.json
277-
if key is not None:
278-
return data.get(key, default)
279-
return data
280-
except ValueError:
281-
pass

readthedocs/oauth/services/bitbucket.py

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ def create_repository(self, fields, privacy=None, organization=None):
136136
remote_id=fields['uuid'],
137137
vcs_provider=self.vcs_provider_slug
138138
)
139-
remote_repository_relation = repo.get_remote_repository_relation(
139+
repo.get_remote_repository_relation(
140140
self.user, self.account
141141
)
142142

@@ -178,9 +178,6 @@ def create_repository(self, fields, privacy=None, organization=None):
178178

179179
repo.save()
180180

181-
remote_repository_relation.json = fields
182-
remote_repository_relation.save()
183-
184181
return repo
185182

186183
log.debug(
@@ -199,7 +196,7 @@ def create_organization(self, fields):
199196
remote_id=fields['uuid'],
200197
vcs_provider=self.vcs_provider_slug
201198
)
202-
remote_organization_relation = organization.get_remote_organization_relation(
199+
organization.get_remote_organization_relation(
203200
self.user, self.account
204201
)
205202

@@ -215,9 +212,6 @@ def create_organization(self, fields):
215212

216213
organization.save()
217214

218-
remote_organization_relation.json = fields
219-
remote_organization_relation.save()
220-
221215
return organization
222216

223217
def get_next_url_to_paginate(self, response):

readthedocs/oauth/services/github.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def create_repository(self, fields, privacy=None, organization=None):
141141

142142
repo.save()
143143

144-
remote_repository_relation.json = fields
145144
remote_repository_relation.admin = fields.get('permissions', {}).get('admin', False)
146145
remote_repository_relation.save()
147146

@@ -163,7 +162,7 @@ def create_organization(self, fields):
163162
remote_id=fields['id'],
164163
vcs_provider=self.vcs_provider_slug
165164
)
166-
remote_organization_relation = organization.get_remote_organization_relation(
165+
organization.get_remote_organization_relation(
167166
self.user, self.account
168167
)
169168

@@ -179,9 +178,6 @@ def create_organization(self, fields):
179178

180179
organization.save()
181180

182-
remote_organization_relation.json = fields
183-
remote_organization_relation.save()
184-
185181
return organization
186182

187183
def get_next_url_to_paginate(self, response):

readthedocs/oauth/services/gitlab.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ def _get_repo_id(self, project):
5555
# The ID or URL-encoded path of the project
5656
# https://docs.gitlab.com/ce/api/README.html#namespaced-path-encoding
5757
try:
58-
repo_id = json.loads(project.remote_repository.json).get('id')
59-
except Exception:
58+
repo_id = project.remote_repository.remote_id
59+
except Project.remote_repository.RelatedObjectDoesNotExist:
6060
# Handle "Manual Import" when there is no RemoteRepository
6161
# associated with the project. It only works with gitlab.com at the
6262
# moment (doesn't support custom gitlab installations)
@@ -248,7 +248,6 @@ def create_repository(self, fields, privacy=None, organization=None):
248248
project_access_level in (self.PERMISSION_MAINTAINER, self.PERMISSION_OWNER),
249249
group_access_level in (self.PERMISSION_MAINTAINER, self.PERMISSION_OWNER),
250250
])
251-
remote_repository_relation.json = fields
252251
remote_repository_relation.save()
253252

254253
return repo
@@ -270,7 +269,7 @@ def create_organization(self, fields):
270269
remote_id=fields['id'],
271270
vcs_provider=self.vcs_provider_slug
272271
)
273-
remote_organization_relation = organization.get_remote_organization_relation(
272+
organization.get_remote_organization_relation(
274273
self.user, self.account
275274
)
276275

@@ -287,9 +286,6 @@ def create_organization(self, fields):
287286

288287
organization.save()
289288

290-
remote_organization_relation.json = fields
291-
remote_organization_relation.save()
292-
293289
return organization
294290

295291
def get_webhook_data(self, repo_id, project, integration):

0 commit comments

Comments
 (0)