Skip to content

OAuth: re-sync RemoteRepository on login #9409

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
Jul 11, 2022
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
4 changes: 3 additions & 1 deletion readthedocs/oauth/apps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# -*- coding: utf-8 -*-

"""OAuth app config."""

Expand All @@ -7,3 +6,6 @@

class OAuthConfig(AppConfig):
name = 'readthedocs.oauth'

def ready(self):
import readthedocs.oauth.signals # noqa
24 changes: 24 additions & 0 deletions readthedocs/oauth/signals.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import structlog
from allauth.account.signals import user_logged_in
from django.contrib.auth.models import User
from django.dispatch import receiver

from readthedocs.oauth.tasks import sync_remote_repositories

log = structlog.get_logger(__name__)


@receiver(user_logged_in, sender=User)
def sync_remote_repositories_on_login(sender, request, user, *args, **kwargs):
"""
Sync ``RemoteRepository`` objects when a user logs in via Social Login.

This function will trigger a background task that will pull down
repositories from all the user's Social Account connected and create/update
their ``RemoteRepository`` in our database.
"""
log.info(
"Triggering sync RemoteRepository in background on login.",
user_username=user.username,
)
sync_remote_repositories.delay(user.pk)