Skip to content

Commit cdf8f99

Browse files
authored
Project: add helper method to get old GitHub OAuth app repo (#12574)
Used in readthedocs/readthedocs-corporate#2057
1 parent b0274f3 commit cdf8f99

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

readthedocs/projects/models.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
from readthedocs.domains.querysets import DomainQueryset
4242
from readthedocs.domains.validators import check_domains_limit
4343
from readthedocs.notifications.models import Notification as NewNotification
44+
from readthedocs.oauth.constants import GITHUB
4445
from readthedocs.oauth.constants import GITHUB_APP
4546
from readthedocs.projects import constants
4647
from readthedocs.projects.exceptions import ProjectConfigurationError
@@ -1080,6 +1081,24 @@ def is_github_project(self):
10801081
def is_github_app_project(self):
10811082
return self.remote_repository and self.remote_repository.vcs_provider == GITHUB_APP
10821083

1084+
@property
1085+
def old_github_remote_repository(self):
1086+
"""
1087+
Get the old GitHub OAuth repository for GitHub App projects.
1088+
1089+
This is mainly used for projects that migrated to the new GitHub App,
1090+
but its users have not yet connected their accounts to the new GitHub App.
1091+
We still need to reference the old repository for permissions when using GH as SSO method.
1092+
"""
1093+
from readthedocs.oauth.models import RemoteRepository
1094+
1095+
if self.is_github_app_project:
1096+
return RemoteRepository.objects.filter(
1097+
vcs_provider=GITHUB,
1098+
remote_id=self.remote_repository.remote_id,
1099+
).first()
1100+
return None
1101+
10831102
@property
10841103
def is_gitlab_project(self):
10851104
from readthedocs.oauth.services import GitLabService

0 commit comments

Comments
 (0)