Skip to content

Remote repository: filter by account before deleting #7454

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
merged 1 commit into from
Sep 4, 2020
Merged
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
21 changes: 16 additions & 5 deletions readthedocs/oauth/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,21 +191,32 @@ def sync(self):

- creates a new RemoteRepository/Organization per new repository
- updates fields for existing RemoteRepository/Organization
- deletes old RemoteRepository/Organization that are not present for this user
- deletes old RemoteRepository/Organization that are not present
for this user in the current provider
"""
repos = self.sync_repositories()
organizations, organization_repos = self.sync_organizations()

# Delete RemoteRepository where the user doesn't have access anymore
# (skip RemoteRepository tied to a Project on this user)
repository_full_names = self.get_repository_full_names(repos + organization_repos)
self.user.oauth_repositories.exclude(
Q(full_name__in=repository_full_names) | Q(project__isnull=False)
).delete()
(
self.user.oauth_repositories
.exclude(
Q(full_name__in=repository_full_names) | Q(project__isnull=False)
)
.filter(account=self.account)
.delete()
)

# Delete RemoteOrganization where the user doesn't have access anymore
organization_names = self.get_organization_names(organizations)
self.user.oauth_organizations.exclude(name__in=organization_names).delete()
(
self.user.oauth_organizations
.exclude(name__in=organization_names)
.filter(account=self.account)
.delete()
)

def create_repository(self, fields, privacy=None, organization=None):
"""
Expand Down