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

Changes to support Bitbucket OAuth2 #1850

Merged
merged 23 commits into from
Jan 6, 2016
Merged

Changes to support Bitbucket OAuth2 #1850

merged 23 commits into from
Jan 6, 2016

Conversation

agjohnson
Copy link
Contributor

Changes most API calls to use APIv2 and relies on OAuth2 for sessions. Bitbucket's OAuth2
implementation expires tokens after 2 hours, so this also implements token refreshing on
the general session creation.

This updates the UI around connecting accounts, namely:

  • Use our common list styling for list of connected services
  • Add a basic warning element for guiding users to reconnect accounts
  • Make connect services buttons themed buttons instead of basic links
  • Updated some of the text from "Social Accounts" to "Connected Services".

screen shot 2016-01-01 at 3 50 13 pm

The project import page will now warn when deprecated accounts are connected, the new API sync code for Bitbucket uses version 2 of the API for almost all requests. Our API will filter out repos/orgs from these deprecated services, but the services themselves are kept around to allow for user administration on the connected services page.

Refs pennersr/django-allauth#1215
Refs pennersr/django-allauth#1212
Fixes #1675
I believe this fixes #1864
Fixes #1696
Refs #1893 - repin django-allauth next release
Fixes #1684 - "social accounts" rename
Fixes #1668 - social account page 500 error
Fixes #1446 - add bitbucket tests

Outstanding:

  • Test handling of existing Bitbucket social accounts
  • How to handle migration fo existing Bitbucket social accounts
  • UI and styling bits to point users to reconnect
  • Some more test cases around bitbucket
  • Import form uses HTTP, but complains about "this is a private repo"

@agjohnson agjohnson added the PR: work in progress Pull request is not ready for full review label Dec 4, 2015
Changes most API calls to use APIv2 and relies on OAuth2 for sessions. Bitbucket's OAuth2
implementation expires tokens after 2 hours, so this also implements token refreshing on
the general session creation.

For now, this relies on a patched version of django-allauth. A new ticket should be created
to track migrating django-allauth back to upstream once the PRs are merged in and released.

Refs pennersr/django-allauth#1215
Refs pennersr/django-allauth#1212
Move oauth syncing code to composed classes, instead of a nest of functions.
Push common configuration and code to a base class. Repo/org models will
start to refer to the SocialAccount they are connected through.
The current implementation split up code between syncing and creating objects
in an awkward way. This way, all code particular to the service is contained
in the service class.

Adds migrations to fix remote org/repo models, moves `source` to `account`
foreign key, allowing for more logical queries and cascading deletes from
account deletion. Migrates source field data to the account field via lookup,
drops source field, and also sets org slug to non-unique, as we don't perform
lookups on org slugs.
@saily
Copy link

saily commented Jan 2, 2016

@agjohnson good job, i was thinking about same kind of implementation using an abstract base class, which you implemented using a non-abstract Service base class.

from abc import ABCMeta
from abc import abstractmethod


class Service:
    __metaclass__ = ABCMeta

    @abstractmethod
    def sync(self, sync):
        pass

    @abstractmethod
    def create_repository(self, fields, privacy=DEFAULT_PRIVACY_LEVEL, organization=None):
        pass

    @abstractmethod
    def create_organization(self, fields):
        pass

    @abstractmethod
    def setup_webhook(self, project):
        pass

Making it abstract would make more sense to me, what do you think?
After this was merged into master i'll rebase #1870.

import_github(user=User.objects.get(username=slug), sync=True)
service = GitHubService.for_user(User.objects.get(username=slug))
if service is not None:
service.sync(sync=True)
Copy link
Member

Choose a reason for hiding this comment

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

.sync(sync=True) feels like a weird API. Are there times we'll call sync without syncing?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't see any, this is brought over from before the refactor. Not sure what sync=false would ever be used for.

@agjohnson
Copy link
Contributor Author

@saily interesting, I almost settled on a similar pattern. In the end, I kept the pattern here simple, as we have some complications with inheritance for readthedocs.com. There's a good deal of common functionality implemented in the base class, so I think it's fair to consider services as subclasses of this class anyways.

Adds a warning to the listing if any of the accounts connected for the
user are not supported accounts.
'''
deprecated_accounts = (
Copy link
Member

Choose a reason for hiding this comment

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

Do these SocialAccount's get removed when they set up their new account? Or are we expecting them to "unlink" them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, it requires manually unlinking them in the connections page. Or, rather, both can exist, we just need the Bitbucket OAuth2 provider. So as long as the user sets that up, everything will work -- albeit there will be a warning still. I considered making a view that unlinks the account and redirects to django-allauth, but felt that was over-complicating the issue.

@ericholscher
Copy link
Member

LGTM 👍 -- definitely happy to have this stuff sanely refactored.

agjohnson added a commit that referenced this pull request Jan 6, 2016
Changes to support Bitbucket OAuth2
@agjohnson agjohnson merged commit e495883 into master Jan 6, 2016
@agjohnson agjohnson deleted the bitbucket-oauth2 branch May 10, 2017 21:34
agjohnson added a commit that referenced this pull request May 10, 2017
Addresses #2708 by using a version of our extension that supports more than one
version of Sphinx.

Refs #1895
Refs #1850
Refs #2755
agjohnson added a commit that referenced this pull request May 11, 2017
Addresses #2708 by using a version of our extension that supports more than one
version of Sphinx.

Refs #1895
Refs #1850
Refs #2755
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants