If user has a single project, _redirect_after_login redirects to it.

This commit is contained in:
Pēteris Caune 2019-01-29 19:05:32 +02:00
parent f2ae573872
commit c1e4595ab2
No known key found for this signature in database
GPG Key ID: E28D7679E9A9EDE2
3 changed files with 9 additions and 7 deletions

View File

@ -16,8 +16,7 @@ class CheckTokenTestCase(BaseTestCase):
self.assertContains(r, "You are about to log in")
def test_it_redirects(self):
r = self.client.post("/accounts/check_token/alice/secret-token/",
follow=True)
r = self.client.post("/accounts/check_token/alice/secret-token/")
self.assertRedirects(r, self.checks_url)
@ -30,8 +29,7 @@ class CheckTokenTestCase(BaseTestCase):
self.client.login(username="alice@example.org", password="password")
# Login again, when already authenticated
r = self.client.post("/accounts/check_token/alice/secret-token/",
follow=True)
r = self.client.post("/accounts/check_token/alice/secret-token/")
self.assertRedirects(r, self.checks_url)
@ -49,5 +47,5 @@ class CheckTokenTestCase(BaseTestCase):
def test_it_ignores_bad_next_parameter(self):
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)

View File

@ -53,7 +53,7 @@ class LoginTestCase(BaseTestCase):
"password": "password"
}
r = self.client.post("/accounts/login/", form, follow=True)
r = self.client.post("/accounts/login/", form)
self.assertRedirects(r, self.checks_url)
def test_it_handles_password_login_with_redirect(self):
@ -81,7 +81,7 @@ class LoginTestCase(BaseTestCase):
"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)
def test_it_handles_wrong_password(self):

View File

@ -80,6 +80,10 @@ def _redirect_after_login(request):
if _is_whitelisted(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")