Skip to content
This repository has been archived by the owner. It is now read-only.

Link venmo #1857

Merged
merged 30 commits into from Jan 10, 2014
Merged

Link venmo #1857

Changes from 1 commit
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
ba597f6
Began adding account linking with Venmo
Jan 7, 2014
ff9ab95
Add venmo api keys for dev, began associate
Jan 7, 2014
dcb34fd
typo
Jan 7, 2014
f167db9
WIP connecting venmo
simon-weber Jan 7, 2014
c3f780b
Save venmo information to db, including oauth
Jan 7, 2014
880663d
Refactor confirm
Jan 7, 2014
8df9b9c
create platform -> class registry for AccountElsewhere
simon-weber Jan 7, 2014
2d6bc4b
leave registry interface as dictionary
simon-weber Jan 7, 2014
3ed0f6e
wip refactor
Jan 7, 2014
6359aea
remove username helpers comment
simon-weber Jan 8, 2014
fbdb2ac
Merge branch 'D-refactor-platforms' into link-venmo
simon-weber Jan 8, 2014
e475555
Merge branch 'refactor-platforms' into link-venmo
simon-weber Jan 8, 2014
2a677c6
Merge branch 'master' into link-venmo
simon-weber Jan 8, 2014
32b7d70
Update/organize default env files
Jan 8, 2014
2d7ee98
use requests.json rather than json.loads
simon-weber Jan 8, 2014
277ca54
DRYer AccountElsewhere
Jan 8, 2014
b763a21
WIP link
Jan 8, 2014
ff7298e
note platform_classes requirement
simon-weber Jan 8, 2014
bcdaa14
Merge branch 'link-venmo' of github.com:venmo/www.gittip.com into lin…
simon-weber Jan 8, 2014
8f5915f
resolve platform_classes ordering
simon-weber Jan 8, 2014
c0029ac
prevent data leakage in %username/public.json
simon-weber Jan 9, 2014
427ae5e
ensure platform_classes is populated at config-time
simon-weber Jan 9, 2014
cac31ca
use platform_classes in configure-aspen
simon-weber Jan 9, 2014
2897cad
Merge branch 'master' into link-venmo
Jan 9, 2014
30988e8
Add openstreetmap to list of accounts
Jan 9, 2014
5262b2c
remove debug line from associate view
Jan 9, 2014
257647a
wrap schema changes in transaction
simon-weber Jan 10, 2014
8a8cffa
remove duplicated ProblemChangingUsername exception
simon-weber Jan 10, 2014
9780f0b
Merge upstream
simon-weber Jan 10, 2014
1d2ce2f
remove unused platforms_ordered import
simon-weber Jan 10, 2014
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

resolve platform_classes ordering

  • Loading branch information...
simon-weber committed Jan 8, 2014
commit 8f5915fc9b47dee210278b23df3ffca0e47a9470
@@ -1,17 +1,35 @@
"""This subpackage contains functionality for working with accounts elsewhere.
"""
from __future__ import print_function, unicode_literals
from collections import OrderedDict

from aspen.utils import typecheck
from psycopg2 import IntegrityError

import gittip
from gittip.exceptions import ProblemChangingUsername, UnknownPlatform
from gittip.utils.username import reserve_a_random_username
from gittip.exceptions import ProblemChangingUsername


ACTIONS = [u'opt-in', u'connect', u'lock', u'unlock']
platform_classes = {} # updated by _RegisterPlatformMeta


# when adding a new platform, add its name to this list.
# its class will automatically be set in platform_classes at import-time.
# the ordering of this list defines the ordering of platform_classes.items().
_platforms_ordered = (
'twitter',
'github',
'bitbucket',
'bountysource',
'venmo',
)

# init-time setup is necessary for two reasons:
# 1) to allow for deterministic iter order in templates
# 2) to allow the use of platform_classes.keys() at import-time
# note that OrderedDicts retain ordering of keys after they are replaced.
platform_classes = OrderedDict([(platform, None) for platform in _platforms_ordered])


class _RegisterPlatformMeta(type):

This comment has been minimized.

Copy link
@chadwhitacre

chadwhitacre Jan 10, 2014

Contributor

This reminds me of something I was doing on the elsewhere refactor branch. Does this relate to that?

This comment has been minimized.

Copy link
@chadwhitacre

This comment has been minimized.

Copy link
@chadwhitacre

chadwhitacre Jan 10, 2014

Contributor

This is what I was thinking of:

https://github.com/gittip/www.gittip.com/pull/1369/files#diff-7698816a9bc10d53930d35de3e4bafdfR13

There I'm using __new__ to switch which AccountElsewhere subclass we're using to hydrate the result of any given database query.

This comment has been minimized.

Copy link
@simon-weber

simon-weber Jan 10, 2014

Contributor

Yup, it accomplishes the same thing as the PlatformRegistry, but doesn't require the manual call to register.

This comment has been minimized.

Copy link
@simon-weber

simon-weber Jan 10, 2014

Contributor

Oh, I misunderstood. Yeah, I think hooking __new__ is the way to go when hydrating.

@@ -21,8 +39,13 @@ class _RegisterPlatformMeta(type):
def __new__(cls, name, bases, dct):
c = super(_RegisterPlatformMeta, cls).__new__(cls, name, bases, dct)

# register the platform and verify it was added at init-time
c_platform = getattr(c, 'platform')
if c_platform is not None:
if name == 'AccountElsewhere':
pass
elif c_platform not in platform_classes:
raise UnknownPlatform(c_platform) # has it been added to platform_classes init?
else:
platform_classes[c_platform] = c

return c
@@ -5,7 +5,8 @@
from __future__ import print_function, unicode_literals


# originally from gittip.models.participant

class UnknownPlatform(Exception): pass

class ProblemChangingUsername(Exception):
def __str__(self):
@@ -5,15 +5,14 @@
from aspen.utils import typecheck
from psycopg2 import IntegrityError

from gittip.utils.username import reserve_a_random_username, gen_random_usernames
from gittip.exceptions import UnknownPlatform
from gittip.elsewhere import platform_classes
from gittip.utils.username import reserve_a_random_username, gen_random_usernames


# Exceptions
# ==========

class UnknownPlatform(Exception): pass

class NeedConfirmation(Exception):
"""Represent the case where we need user confirmation during a merge.
@@ -46,10 +45,8 @@ def __nonzero__(self):
# Mixin
# =====

_account_types = ('github', 'twitter', 'bitbucket', 'bountysource', 'venmo')
#TODO(simonweber): use platform_classes

AccountsTuple = namedtuple('AccountsTuple', _account_types)
# note that the ordering of these fields is defined by platform_classes
AccountsTuple = namedtuple('AccountsTuple', platform_classes.keys())

class MixinElsewhere(object):
"""We use this as a mixin for Participant, and in a hackish way on the
@@ -58,18 +55,21 @@ class MixinElsewhere(object):
"""

def get_accounts_elsewhere(self):
"""Return an AccountsTuple of elsewhere Records.
"""Return an AccountsTuple of AccountElsewhere instances.
"""

ACCOUNTS = "SELECT * FROM elsewhere WHERE participant=%s"
accounts = self.db.all(ACCOUNTS, (self.username,))

accounts_dict = {a_type: None for a_type in _account_types}
accounts_dict = {platform: None for platform in platform_classes}

for account in accounts:
if account.platform not in _account_types:
if account.platform not in platform_classes:
raise UnknownPlatform(account.platform)
accounts_dict[account.platform] = platform_classes[account.platform](self.db, account.user_id, existing_record=account)

account_cls = platform_classes[account.platform]
accounts_dict[account.platform] = \
account_cls(self.db, account.user_id, existing_record=account)

return AccountsTuple(**accounts_dict)

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.