|
6 | 6 | import logging
|
7 | 7 | import re
|
8 | 8 |
|
| 9 | +from allauth.socialaccount.providers.github.provider import GitHubProvider |
| 10 | +from allauth.socialaccount.models import SocialAccount |
| 11 | + |
9 | 12 | from django.shortcuts import get_object_or_404
|
10 | 13 | from rest_framework import permissions, status
|
11 | 14 | from rest_framework.exceptions import NotFound, ParseError
|
|
27 | 30 | build_external_version,
|
28 | 31 | )
|
29 | 32 | from readthedocs.integrations.models import HttpExchange, Integration
|
| 33 | +from readthedocs.oauth.services.github import GitHubService |
30 | 34 | from readthedocs.projects.models import Project, Feature
|
31 | 35 |
|
32 | 36 |
|
33 | 37 | log = logging.getLogger(__name__)
|
34 | 38 |
|
35 | 39 | GITHUB_EVENT_HEADER = 'HTTP_X_GITHUB_EVENT'
|
36 | 40 | GITHUB_SIGNATURE_HEADER = 'HTTP_X_HUB_SIGNATURE'
|
| 41 | +GITHUB_MEMBER = 'member' |
37 | 42 | GITHUB_PUSH = 'push'
|
38 | 43 | GITHUB_PULL_REQUEST = 'pull_request'
|
39 | 44 | GITHUB_PULL_REQUEST_OPENED = 'opened'
|
@@ -459,6 +464,16 @@ def handle_webhook(self):
|
459 | 464 | except KeyError:
|
460 | 465 | raise ParseError('Parameter "ref" is required')
|
461 | 466 |
|
| 467 | + # Re-sync repositories for the user if any permission has changed |
| 468 | + if event == GITHUB_MEMBER: |
| 469 | + uid = self.data.get('member').get('id') |
| 470 | + socialaccount = SocialAccount.objects.get( |
| 471 | + provider=GitHubProvider.id, |
| 472 | + uid=uid, |
| 473 | + ) |
| 474 | + service = GitHubService(user=socialaccount.user, account=socialaccount) |
| 475 | + service.sync() |
| 476 | + |
462 | 477 | return None
|
463 | 478 |
|
464 | 479 | def _normalize_ref(self, ref):
|
|
0 commit comments