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

global: make a better separation between request-related and "business logic" code #177

Open
slint opened this issue Oct 4, 2018 · 0 comments

Comments

@slint
Copy link
Member

slint commented Oct 4, 2018

The various client handlers contain business logic related to how to e.g. disconnect a user from an OAuth service which shouldn't depend on the request context. Example from invenio_oauthclient.contrib.orcid.disconnect_handler:

...
def disconnect_handler(remote, *args, **kwargs):
    """Handle unlinking of remote account.
    :param remote: The remote application.
    """
    # ...this is request-related...
    if not current_user.is_authenticated: 
        return current_app.login_manager.unauthorized()

    # -- START --
    # This part should be in a different function, since it only depends on a User ID
    account = RemoteAccount.get(user_id=current_user.get_id(),
                                client_id=remote.consumer_key)
    orcid = account.extra_data.get('orcid')

    if orcid:
        oauth_unlink_external_id({'id': orcid, 'method': 'orcid'})
    if account:
        with db.session.begin_nested():
            account.delete()
    # -- END --

    # ...this is request-related...
    return redirect(url_for('invenio_oauthclient_settings.index'))
...
@slint slint changed the title global: make a better separation between request-related global: make a better separation between request-related and "business logic" code Oct 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant