Skip to content

Commit 114ad6c

Browse files
committed
Use RemoteRepository releation to match already imported projects
Currently production code consider a project already imported if the `Project.repo` fuzzy matches `RemoteRepository.clone_url` even if that `Project` is not linked to any `RemoteRepository`. This allow anyone to import a repository manually using the real GitHub URL to "take over" that repository and avoiding the real owner of that repository to import it from "Import Project" page because it says: This repository has already been imported and linking to the project that someone's else has imported. With the changes on this PR, we are showing that message only if the `Project` is connected to a `RemoteRepository` which is only possible to be done by owners of the GitHub repository.
1 parent b076906 commit 114ad6c

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

readthedocs/oauth/models.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,22 +200,16 @@ class Meta:
200200
def __str__(self):
201201
return 'Remote repository: {}'.format(self.html_url)
202202

203-
@property
204-
def clone_fuzzy_url(self):
205-
"""Try to match against several permutations of project URL."""
206-
207203
def matches(self, user):
208-
"""Projects that exist with repository URL already."""
209-
# Support Git scheme GitHub url format that may exist in database
210-
truncated_url = self.clone_url.replace('.git', '')
211-
http_url = self.clone_url.replace('git://', 'https://').replace('.git', '')
204+
"""Existing projects connected to this RemoteRepository."""
205+
206+
# TODO: remove this method and refactor the API response in ``/api/v2/repos/``
207+
# (or v3) to just return the linked Project (slug, url) if the ``RemoteRepository``
208+
# connection exists. Note the frontend needs to be simplified as well in
209+
# ``import.js`` and ``project_import.html``.
212210

213211
projects = Project.objects.public(user).filter(
214-
Q(repo=self.clone_url) |
215-
Q(repo=truncated_url) |
216-
Q(repo=truncated_url + '.git') |
217-
Q(repo=http_url) |
218-
Q(repo=http_url + '.git')
212+
remote_repository=self,
219213
).values('slug')
220214

221215
return [{

0 commit comments

Comments
 (0)