Skip to content

Use RemoteRepository releation to match already imported projects #8024

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
Mar 22, 2021

Conversation

humitos
Copy link
Member

@humitos humitos commented Mar 17, 2021

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.

NOTE that this PR is based on rel which already have #7949 merged. We can cherry-pick this commit into rel and also into #7949 before merging that PR into master.

@humitos humitos requested review from ericholscher, saadmk11 and a team March 17, 2021 10:29
@humitos humitos force-pushed the humitos/import-project-matches branch from dc7bed2 to 7e7bfe1 Compare March 17, 2021 10:35
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is better than the current code, but I'm still not sure this is the right approach. Just because the repo already has been imported doesn't mean the user has access, given that we don't support GH auth permissions in .org yet.

This is better than the current logic tho, so at least a step towards better modeling.

Another question: should we disable manual imports of projects that already have a project connected with that URL? That would stop non-admin users from creating RTD "forks" of projects, which might be useful at some point in the future.

@humitos
Copy link
Member Author

humitos commented Mar 17, 2021

I agree with you. This is just to fix the current bug, but it doesn't change behavior. We need to have a conversation about disabling manual import because there is a bigger issue here with translations. We currently do not support importing the same repository twice (or more times) and people have to do it via Manual Import. This is bad UX, but disabling manual import because that repository is already imported will be worse.

@agjohnson has raised this problem multiple times already but we didn't work towards a good solution yet. I think this was planned to be part of the new ext-theme, but we didn't get there yet.

Comment on lines 211 to 213
projects = Project.objects.public(user).filter(
Q(repo=self.clone_url) |
Q(repo=truncated_url) |
Q(repo=truncated_url + '.git') |
Q(repo=http_url) |
Q(repo=http_url + '.git')
remote_repository=self,
).values('slug')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use self.project.slug here as it's an OneToOne relationship and it will reduce the number of queries if we use select_related() in the RemoteRepository Queryset?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I think you are right! We will need to check for user permissions on that project, tho. Note that we are using .public queryset in the query here.

Can you write an example? I'm confused 😞

Also, I think eventually we will want to allow multiple projects connected to the same RemoteRepository (because of translations)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At First, I thought we could do something similar to this

return [{
    'id': self.project.slug,
    'url': reverse(
        'projects_detail',
        kwargs={
            'project_slug': self.project.slug,
        },
    ),
}] if self.project else []

But as you mentioned there are some permissions related here with .public() :(

@humitos humitos added the Status: blocked Issue is blocked on another issue label Mar 18, 2021
@humitos
Copy link
Member Author

humitos commented Mar 18, 2021

Marking as blocked just to remember that we need to cherry-pick the commit in two branches.

@humitos humitos changed the base branch from rel to master March 22, 2021 15:24
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.
@humitos humitos force-pushed the humitos/import-project-matches branch from 7e7bfe1 to 114ad6c Compare March 22, 2021 15:27
@humitos humitos removed the Status: blocked Issue is blocked on another issue label Mar 22, 2021
@humitos humitos enabled auto-merge March 22, 2021 15:32
@humitos humitos merged commit 655a34a into master Mar 22, 2021
@humitos humitos deleted the humitos/import-project-matches branch March 22, 2021 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants