-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Remote repository: Keep in sync when repos are moved to another org/users #9178
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This approach looks good. I'm a bit worried, tho. I'm not sure that I'm understanding 100% what it conveys and what problems this change can bring.
The main thing I'm thinking about is if we may need to trigger a re-sync for all users that has access to a repository when its organization is changed? I'm trying to think if when a project is moved from one organization to the other users won't lose permissions on it because being out-of-sync.
ad68360
to
4c7f257
Compare
I think this is a problem with the current implementation as well, like when a project is transferred to another user or a user is removed from an org/project, it looks like we are refreshing the permissions every 4 hours. Anyway, those problems should be solved by subscribing to a webhook if we aren't already. |
readthedocs/oauth/services/github.py
Outdated
if ( | ||
organization | ||
and owner_type == "Organization" | ||
and organization.remote_id == fields["owner"]["id"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This shouldn't be needed since we are passing the org from where the projects were fetched from, but just in case.
…ser. We were doing some checks to avoid removing the remote organization from a remote repo when this is listed from the /users/repos/ endpoint or changing the organization when the project was moved. But, since we are hitting the GitHub API directly, we can always trust the result from there, which includes the type of owner of the repository, we can use that to decide if the repository belongs to an organization or not. Fixes #8715
4c7f257
to
8c7c362
Compare
1248df5
to
eb8d042
Compare
Yeah, we tried to do this, but we can't do it properly being a OAuth application. It will be possible when using a GitHub Application instead. See #7336 (comment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is fine. I've made more suggestions after a deeper review. Note this is changing a core part of our auth permissions and we should be careful here. I'd like another pair of eyes reviewing this as well just in case I'm missing something -- cc @ericholscher @agjohnson
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't have much else to add here, but do echo the concerns @humitos has around auth/SSO and simplicity. For that, trading performance optimization for more simplicity makes sense.
def create_repository(self, fields, privacy=None, organization=None): | ||
""" | ||
Update or create a repository from API response. | ||
|
||
:param fields: dictionary of response data from API | ||
:param privacy: privacy level to support | ||
:param organization: remote organization to associate with | ||
:type organization: RemoteOrganization | ||
:rtype: RemoteRepository | ||
""" | ||
raise NotImplementedError | ||
|
||
def create_organization(self, fields): | ||
""" | ||
Update or create remote organization from API response. | ||
|
||
:param fields: dictionary response of data from API | ||
:rtype: RemoteOrganization | ||
""" | ||
raise NotImplementedError | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the signature is different for the github provider now, we don't make any reference to these methods outside the class (we use the sync method) so we are fine having a different signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should implement the same logic for the other providers as well if that's technically possible. Otherwise, we will have different behavior between GH SSO and the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me! I wonder if we should implement the same logic for GitLab and Bitbucket also to keep consistency between providers and avoid future problems with inconsistency on SSO accounts
def create_repository(self, fields, privacy=None, organization=None): | ||
""" | ||
Update or create a repository from API response. | ||
|
||
:param fields: dictionary of response data from API | ||
:param privacy: privacy level to support | ||
:param organization: remote organization to associate with | ||
:type organization: RemoteOrganization | ||
:rtype: RemoteRepository | ||
""" | ||
raise NotImplementedError | ||
|
||
def create_organization(self, fields): | ||
""" | ||
Update or create remote organization from API response. | ||
|
||
:param fields: dictionary response of data from API | ||
:rtype: RemoteOrganization | ||
""" | ||
raise NotImplementedError | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should implement the same logic for the other providers as well if that's technically possible. Otherwise, we will have different behavior between GH SSO and the others.
Ops, I didn't add the comment to the approval. I'm fine merging these changes since they are good and they will solve some issues we have. However, we should add a new issue to track the work required for the other VCS and implement the same logic for them. |
We were doing some checks to avoid removing the remote organization
from a remote repo when this is listed from the /users/repos/ endpoint
or changing the organization when the project was moved.
But, since we are hitting the GitHub API directly,
we can always trust the result from there,
which includes the type of owner of the repository,
we can use that to decide if the repository belongs to an organization or not.
Fixes #8715