forked from GithubBackups/healthchecks
If user has a single project, _redirect_after_login redirects to it.
This commit is contained in:
parent
f2ae573872
commit
c1e4595ab2
@ -16,8 +16,7 @@ class CheckTokenTestCase(BaseTestCase):
|
|||||||
self.assertContains(r, "You are about to log in")
|
self.assertContains(r, "You are about to log in")
|
||||||
|
|
||||||
def test_it_redirects(self):
|
def test_it_redirects(self):
|
||||||
r = self.client.post("/accounts/check_token/alice/secret-token/",
|
r = self.client.post("/accounts/check_token/alice/secret-token/")
|
||||||
follow=True)
|
|
||||||
|
|
||||||
self.assertRedirects(r, self.checks_url)
|
self.assertRedirects(r, self.checks_url)
|
||||||
|
|
||||||
@ -30,8 +29,7 @@ class CheckTokenTestCase(BaseTestCase):
|
|||||||
self.client.login(username="alice@example.org", password="password")
|
self.client.login(username="alice@example.org", password="password")
|
||||||
|
|
||||||
# Login again, when already authenticated
|
# Login again, when already authenticated
|
||||||
r = self.client.post("/accounts/check_token/alice/secret-token/",
|
r = self.client.post("/accounts/check_token/alice/secret-token/")
|
||||||
follow=True)
|
|
||||||
|
|
||||||
self.assertRedirects(r, self.checks_url)
|
self.assertRedirects(r, self.checks_url)
|
||||||
|
|
||||||
@ -49,5 +47,5 @@ class CheckTokenTestCase(BaseTestCase):
|
|||||||
|
|
||||||
def test_it_ignores_bad_next_parameter(self):
|
def test_it_ignores_bad_next_parameter(self):
|
||||||
url = "/accounts/check_token/alice/secret-token/?next=/evil/"
|
url = "/accounts/check_token/alice/secret-token/?next=/evil/"
|
||||||
r = self.client.post(url, follow=True)
|
r = self.client.post(url)
|
||||||
self.assertRedirects(r, self.checks_url)
|
self.assertRedirects(r, self.checks_url)
|
||||||
|
@ -53,7 +53,7 @@ class LoginTestCase(BaseTestCase):
|
|||||||
"password": "password"
|
"password": "password"
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self.client.post("/accounts/login/", form, follow=True)
|
r = self.client.post("/accounts/login/", form)
|
||||||
self.assertRedirects(r, self.checks_url)
|
self.assertRedirects(r, self.checks_url)
|
||||||
|
|
||||||
def test_it_handles_password_login_with_redirect(self):
|
def test_it_handles_password_login_with_redirect(self):
|
||||||
@ -81,7 +81,7 @@ class LoginTestCase(BaseTestCase):
|
|||||||
"password": "password"
|
"password": "password"
|
||||||
}
|
}
|
||||||
|
|
||||||
r = self.client.post("/accounts/login/?next=/evil/", form, follow=True)
|
r = self.client.post("/accounts/login/?next=/evil/", form)
|
||||||
self.assertRedirects(r, self.checks_url)
|
self.assertRedirects(r, self.checks_url)
|
||||||
|
|
||||||
def test_it_handles_wrong_password(self):
|
def test_it_handles_wrong_password(self):
|
||||||
|
@ -80,6 +80,10 @@ def _redirect_after_login(request):
|
|||||||
if _is_whitelisted(redirect_url):
|
if _is_whitelisted(redirect_url):
|
||||||
return redirect(redirect_url)
|
return redirect(redirect_url)
|
||||||
|
|
||||||
|
if request.user.project_set.count() == 1:
|
||||||
|
project = request.user.project_set.first()
|
||||||
|
return redirect("hc-checks", project.code)
|
||||||
|
|
||||||
return redirect("hc-index")
|
return redirect("hc-index")
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user