Skip to content

Commit

Permalink
Re-sync all users for all the organizations the user belongs to
Browse files Browse the repository at this point in the history
  • Loading branch information
humitos committed Oct 21, 2021
1 parent f143538 commit 423347b
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions readthedocs/api/v2/views/integrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from rest_framework.status import HTTP_400_BAD_REQUEST
from rest_framework.views import APIView

from readthedocs.core.permissions import AdminPermission
from readthedocs.core.signals import (
webhook_bitbucket,
webhook_github,
Expand All @@ -30,7 +31,7 @@
trigger_sync_versions,
)
from readthedocs.integrations.models import HttpExchange, Integration
from readthedocs.oauth.tasks import sync_remote_repositories
from readthedocs.oauth.tasks import sync_remote_repositories, sync_remote_repositories_organizations
from readthedocs.projects.models import Project, Feature

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -464,7 +465,19 @@ def handle_webhook(self):
provider=GitHubProvider.id,
uid=uid,
)
sync_remote_repositories.delay(socialaccount.user.pk)

# Retrieve all organization the user belongs to
organization_slugs = set(
AdminPermission.projects(
socialaccount.user,
admin=True,
member=True,
).values_list('organizations__slug', flat=True)
)
if organization_slugs:
sync_remote_repositories_organizations(organization_slugs=organization_slugs)
else:
sync_remote_repositories.delay(socialaccount.user.pk)

return None

Expand Down

0 comments on commit 423347b

Please sign in to comment.