Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

fix Bountysource regression #1697

Merged
merged 4 commits into from
Nov 27, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions default_local.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ NANSWERS_THRESHOLD=2
NMEMBERS_THRESHOLD=50
UPDATE_HOMEPAGE_EVERY=10
BOUNTYSOURCE_API_SECRET=e2BbqjNY60kC7V-Uq1dv2oHgGavbWm9pUJmiRHCApFZHDiY9aZyAspInhZaZ94x9
BOUNTYSOURCE_API_HOST=https://api-qa.bountysource.com/
BOUNTYSOURCE_WWW_HOST=https://www-qa.bountysource.com/
BOUNTYSOURCE_API_HOST=https://staging-qa.bountysource.com
BOUNTYSOURCE_WWW_HOST=https://staging.bountysource.com
BOUNTYSOURCE_CALLBACK=http://127.0.0.1:8537/on/bountysource/associate
GOOGLE_ANALYTICS_ID=
GAUGES_ID=
Expand Down
4 changes: 2 additions & 2 deletions default_tests.env
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ NANSWERS_THRESHOLD=2
NMEMBERS_THRESHOLD=50
UPDATE_HOMEPAGE_EVERY=10
BOUNTYSOURCE_API_SECRET=e2BbqjNY60kC7V-Uq1dv2oHgGavbWm9pUJmiRHCApFZHDiY9aZyAspInhZaZ94x9
BOUNTYSOURCE_API_HOST=https://api-qa.bountysource.com/
BOUNTYSOURCE_WWW_HOST=https://www-qa.bountysource.com/
BOUNTYSOURCE_API_HOST=https://staging-qa.bountysource.com
BOUNTYSOURCE_WWW_HOST=https://staging.bountysource.com
BOUNTYSOURCE_CALLBACK=http://127.0.0.1:8537/on/bountysource/associate
GOOGLE_ANALYTICS_ID=
GAUGES_ID=
Expand Down
7 changes: 5 additions & 2 deletions gittip/elsewhere/bountysource.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@ class BountysourceAccount(AccountElsewhere):
platform = u'bountysource'

def get_url(self):
url = "https://www.bountysource.com/#users/%s" % self.user_info["slug"]
return url

# I don't see that we actually use this. Leaving as a stub pending
# https://github.com/gittip/www.gittip.com/pull/1369.

raise NotImplementedError


def resolve(login):
Expand Down
12 changes: 12 additions & 0 deletions tests/test_elsewhere_bountysource.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from __future__ import absolute_import, division, print_function, unicode_literals

from gittip.testing import Harness
from gittip.testing.client import TestClient


class Tests(Harness):

def test_redirect_redirects(self):
self.make_participant('alice')
actual = TestClient().get('/on/bountysource/redirect', user='alice').code
assert actual == 302
64 changes: 3 additions & 61 deletions www/on/bountysource/redirect.spt
Original file line number Diff line number Diff line change
Expand Up @@ -21,68 +21,10 @@ connect_params = {
'login': user.participant.username
}


# Collect extra params from accounts elsewhere.
# =============================================
# The following attributes will be added to connect_params from linked accounts
# if present: email, first_name, last_name, avatar_url. These are used to
# prefill the account creation screen on Bountysource.

for account in user.participant.get_accounts_elsewhere():
# Note: returns None for accounts that haven't been linked yet
if account is None:
continue

# from Github
if account.platform == 'github':
# split single name string into parts
name_parts = re.split('\s+', account.user_info.get('name', '').strip())

if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('login')
if not connect_params.get('email'):
connect_params['email'] = account.user_info.get('email')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = account.user_info.get('avatar_url')
if not connect_params.get('first_name'):
if len(name_parts) >= 1:
connect_params['first_name'] = name_parts[0]
if not connect_params.get('last_name'):
if len(name_parts) >= 2:
connect_params['last_name'] = name_parts[-1]

# from Twitter
if account.platform == 'twitter':
# split single name string into parts
name_parts = re.split('/s+', account.user_info.get('name').strip())

if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('screen_name')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = \
account.user_info.get('profile_image_url_https')
if not connect_params.get('first_name'):
if name_parts:
connect_params['first_name'] = name_parts[0]
if not connect_params.get('last_name'):
if len(name_parts) >= 2:
connect_params['last_name'] = name_parts[-1]

# from Bitbucket
if account.platform == 'bitbucket':
if not connect_params.get('login'):
connect_params['login'] = account.user_info.get('username')
if not connect_params.get('avatar_url'):
connect_params['avatar_url'] = account.user_info.get('avatar')
if not connect_params.get('first_name'):
connect_params['first_name'] = account.user_info.get('first_name')
if not connect_params.get('last_name'):
connect_params['last_name'] = account.user_info.get('last_name')

# build redirect URL to Bountysource from collected data
auth_url = "%s#auth/gittip/confirm?%s" % ( bountysource.www_host
, urlencode(connect_params)
)
auth_url = "{}/auth/gittip/confirm?{}".format( website.bountysource_www_host
, urlencode(connect_params)
)

log("Redirect to Bountysource for authorization: %s" % connect_params)
request.redirect(auth_url)
Expand Down