Browse Source

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

pull/217/head
Pēteris Caune 6 years ago
parent
commit
c1e4595ab2
No known key found for this signature in database GPG Key ID: E28D7679E9A9EDE2
3 changed files with 9 additions and 7 deletions
  1. +3
    -5
      hc/accounts/tests/test_check_token.py
  2. +2
    -2
      hc/accounts/tests/test_login.py
  3. +4
    -0
      hc/accounts/views.py

+ 3
- 5
hc/accounts/tests/test_check_token.py View File

@ -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/",
follow=True)
r = self.client.post("/accounts/check_token/alice/secret-token/")
self.assertRedirects(r, self.checks_url) self.assertRedirects(r, self.checks_url)
@ -30,8 +29,7 @@ class CheckTokenTestCase(BaseTestCase):
self.client.login(username="[email protected]", password="password") self.client.login(username="[email protected]", password="password")
# Login again, when already authenticated # 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) 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)

+ 2
- 2
hc/accounts/tests/test_login.py View File

@ -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):


+ 4
- 0
hc/accounts/views.py View File

@ -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…
Cancel
Save