Skip to content

Commit 95bbf66

Browse files
authored
Add migration page for GitHub App (#12112)
Can be tested together with readthedocs/ext-theme#570, there is a video there showing the workflow. What this does is groups all repositories the user has linked to a project, and works over that. The actions the user takes are as follows: - Connect its account to our new GH app, we validate that the new account matches the account from the old integration. - Install our app into the organization/users that the user has repositories imported from. Users that are part of projects where they don't have access to the repository owner/organization, can omit those, so the proper owner can migrate those, or in the case of organizations, they can request for an admin to approve the installation. - Users can migrate their projects to the new GitHub app only if the app is installed in the proper repository, and if they have admin access to the repository. - The migration basically consists of removing the old webhooks/ssh keys from the repo as they are no longer needed, and after that changing the remote repository to the one from the GH app. - After all that is done, the next step is to revoke access to our old OAuth app, the user must do this, as we can't do that on behalf of the user. This step is recommended but not necessary required (we do make it required in our migration page, so we aren't responsible for lingering accounts). - The final step is basically disconnecting the old GH OAuth app from the social accounts of the user, once that is done, we no longer can migrate the project on behalf of the user (or at least the part about removing the ssh key and webhook), connecting the project to the new remote repository can still be done, but users can also do that. Extracted from #11942
1 parent 7c8fced commit 95bbf66

File tree

11 files changed

+1535
-3
lines changed

11 files changed

+1535
-3
lines changed

readthedocs/core/templatetags/readthedocs/socialaccounts.py

+22
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
from allauth.socialaccount.adapter import get_adapter
2+
from allauth.socialaccount.providers.github.provider import GitHubProvider
23
from django import forms
34
from django import template
45

6+
from readthedocs.allauth.providers.githubapp.provider import GitHubAppProvider
7+
from readthedocs.oauth.utils import is_access_revoked as utils_is_access_revoked
8+
59

610
register = template.Library()
711

@@ -19,3 +23,21 @@ def can_be_disconnected(account):
1923
return True
2024
except forms.ValidationError:
2125
return False
26+
27+
28+
@register.filter
29+
def is_access_revoked(account):
30+
"""Check if access to the account is revoked."""
31+
return utils_is_access_revoked(account)
32+
33+
34+
@register.filter
35+
def has_github_app_account(account):
36+
"""Check if there is a GitHub App account matching this account."""
37+
if account.provider != GitHubProvider.id:
38+
return False
39+
40+
return account.user.socialaccount_set.filter(
41+
provider=GitHubAppProvider.id,
42+
uid=account.uid,
43+
).exists()

0 commit comments

Comments
 (0)