Skip to content

Commit 5421dcb

Browse files
authored
Merge pull request #7454 from readthedocs/filter-by-account
Remote repository: filter by account before deleting
2 parents 77df279 + 28748d6 commit 5421dcb

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

readthedocs/oauth/services/base.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,21 +191,32 @@ def sync(self):
191191
192192
- creates a new RemoteRepository/Organization per new repository
193193
- updates fields for existing RemoteRepository/Organization
194-
- deletes old RemoteRepository/Organization that are not present for this user
194+
- deletes old RemoteRepository/Organization that are not present
195+
for this user in the current provider
195196
"""
196197
repos = self.sync_repositories()
197198
organizations, organization_repos = self.sync_organizations()
198199

199200
# Delete RemoteRepository where the user doesn't have access anymore
200201
# (skip RemoteRepository tied to a Project on this user)
201202
repository_full_names = self.get_repository_full_names(repos + organization_repos)
202-
self.user.oauth_repositories.exclude(
203-
Q(full_name__in=repository_full_names) | Q(project__isnull=False)
204-
).delete()
203+
(
204+
self.user.oauth_repositories
205+
.exclude(
206+
Q(full_name__in=repository_full_names) | Q(project__isnull=False)
207+
)
208+
.filter(account=self.account)
209+
.delete()
210+
)
205211

206212
# Delete RemoteOrganization where the user doesn't have access anymore
207213
organization_names = self.get_organization_names(organizations)
208-
self.user.oauth_organizations.exclude(name__in=organization_names).delete()
214+
(
215+
self.user.oauth_organizations
216+
.exclude(name__in=organization_names)
217+
.filter(account=self.account)
218+
.delete()
219+
)
209220

210221
def create_repository(self, fields, privacy=None, organization=None):
211222
"""

0 commit comments

Comments
 (0)