Skip to content

Commit

Permalink
Add MISFIT_ERROR_REDIRECT setting.
Browse files Browse the repository at this point in the history
  • Loading branch information
grokcode committed Jan 8, 2015
1 parent 567559d commit 784d023
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 5 additions & 1 deletion misfitapp/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
# removed.
MISFIT_LOGOUT_REDIRECT = '/'

# Where to redirect to if there is an error while authenticating a Misfit
# user.
MISFIT_ERROR_REDIRECT = None

# The template to use when an unavoidable error occurs during Misfit
# integration.
# integration. This setting is ignored if MISFIT_ERROR_REDIRECT is set.
MISFIT_ERROR_TEMPLATE = 'misfit/error.html'

# The default message used by the misfit_integration_warning decorator to
Expand Down
7 changes: 7 additions & 0 deletions misfitapp/tests/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,13 @@ def _get(self, use_token=True, use_verifier=True, use_limiting=False, **kwargs):
return super(TestCompleteView, self)._get(get_kwargs=get_kwargs,
**kwargs)

def test_error_redirect(self):
""" Complete view should redirect to MISFIT_ERROR_REDIRECT if set. """
url = '/'
with patch('celery.app.task.Task.delay') as mock_delay:
with self.settings(MISFIT_ERROR_REDIRECT=url):
response = self._get(use_limiting=True)
self.assertRedirectsNoFollow(response, url)


def test_ratelimiting(self):
Expand Down
7 changes: 5 additions & 2 deletions misfitapp/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ def complete(request):
After the user authorizes us, Misfit sends a callback to this URL to
complete authentication.
If there was an error, the user is redirected again to the `error` view.
If there was an error, the user is redirected to the url set in
:ref:`MISFIT_ERROR_REDIRECT` if it is set, or to the `error` view
otherwise.
If the authorization was successful, the credentials are stored for us to
use later, and the user is redirected. If 'next_url' is in the request
Expand All @@ -74,7 +76,8 @@ def complete(request):
misfit = utils.create_misfit(access_token)
profile = misfit.profile()
except:
return redirect(reverse('misfit-error'))
next_url = utils.get_setting('MISFIT_ERROR_REDIRECT') or reverse('misfit-error')
return redirect(next_url)


user_updates = {'access_token': access_token,
Expand Down

0 comments on commit 784d023

Please sign in to comment.