Skip to content
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

core: added feature flag and removed signals. #109

Merged
merged 6 commits into from
Jul 11, 2023

Conversation

alejandromumo
Copy link
Member

closes #107

Copy link
Member

@zzacharo zzacharo left a comment

Choose a reason for hiding this comment

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

minor naming suggestion and we can merge this!

invenio_github/config.py Outdated Show resolved Hide resolved
Copy link
Member

@slint slint left a comment

Choose a reason for hiding this comment

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

Changes we discussed IRL look good 👍

Comments are mostly on older things from the previous PR, some minor naming, and using an overall "safer" style.

invenio_github/api.py Outdated Show resolved Hide resolved
"""Return OAuth access token."""
if self.user_id:
return RemoteToken.get(self.user_id, self.remote.consumer_key).access_token
return self.remote.get_request_token()[0]
Copy link
Member

Choose a reason for hiding this comment

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

minor: this might be needed for when the user links their OAuth GitHub account, after which we have the special account setup handler that goes to GitHub and syncs repository info. During this request the GitHub RemoteToken is not committed yet in the database, but is temporarily stored somewhere in the Flask request (this needs a deep-dive in the get_request_token() method to verify).

Copy link
Member Author

Choose a reason for hiding this comment

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

I think we're using this token getter:

https://github.com/inveniosoftware/invenio-oauthclient/blob/master/invenio_oauthclient/handlers/utils.py#L157

It sets the RemoteToken in the session and returns the RemoteToken.token(), which is a tuple: https://github.com/inveniosoftware/invenio-oauthclient/blob/master/invenio_oauthclient/models.py#L140

Since both are returning RemoteToken.get(), they should be similar. However the get_request_token() sets it in the session, if it exists.

Nevertheless, I will revert the change :)

invenio_github/api.py Outdated Show resolved Hide resolved

def disable_repo(self, repo):
"""Disables all current user repositories."""
assert repo.user_id == self.user_id
Copy link
Member

Choose a reason for hiding this comment

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

minor/question: Is this check transferred over from the models? Since we're in the "business layer" Instead of an assert I would go with raising an exception (that the caller can then reliably catch and handle).

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes, it comes from the model. Before we were checking it on access (e.g. Repository.get()) and that was moved to the business logic.

This "disable_repo" was moved from the disconnect handler, to wrap the repo functionality in an API call.

I realised we also have the permission check to access the repo and that can be reused here.

Copy link
Member Author

Choose a reason for hiding this comment

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

However, since we are hiding the enabling/disabling actions behind the API class and checking for permissions it can have an impact on support. E.g. we'd have to impersonate a user to enable/disable the repo

invenio_github/api.py Outdated Show resolved Hide resolved
invenio_github/oauth/handlers.py Outdated Show resolved Hide resolved
for repo in db_repos:
Repository.disable(repo)
# Disable every GitHub webhooks from our side
repos = github.user_repositories
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
repos = github.user_repositories
repos = github.user_repositories.all()
repos_with_hooks = [(r.github_id, r.hook) for r in repos if r.hook]

We need the .all() here to "cache" the results, because after we disable each repo, this information will be lost, and we need it to delete the remaining repo hooks.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also, we were already iterating the repos so it could've been done in one iteration.

Thanks!

invenio_github/oauth/handlers.py Outdated Show resolved Hide resolved
invenio_github/api.py Outdated Show resolved Hide resolved
invenio_github/views/github.py Outdated Show resolved Hide resolved
@zzacharo zzacharo merged commit 06c1428 into inveniosoftware:master Jul 11, 2023
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.

config: investigate github app import
3 participants