mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-09-10 10:03:21 -04:00
Merge pull request #1967 from alphagov/login-redirect
redirect to show_accounts_or_dashboard on login
This commit is contained in:
@@ -13,7 +13,7 @@ from flask_login import current_user, login_user
|
|||||||
from itsdangerous import SignatureExpired
|
from itsdangerous import SignatureExpired
|
||||||
from notifications_utils.url_safe_token import check_token
|
from notifications_utils.url_safe_token import check_token
|
||||||
|
|
||||||
from app import service_api_client, user_api_client
|
from app import user_api_client
|
||||||
from app.main import main
|
from app.main import main
|
||||||
from app.main.forms import TwoFactorForm
|
from app.main.forms import TwoFactorForm
|
||||||
from app.utils import redirect_to_sign_in
|
from app.utils import redirect_to_sign_in
|
||||||
@@ -112,9 +112,4 @@ def redirect_when_logged_in(user_id):
|
|||||||
if current_user.platform_admin:
|
if current_user.platform_admin:
|
||||||
return redirect(url_for('main.platform_admin'))
|
return redirect(url_for('main.platform_admin'))
|
||||||
|
|
||||||
services = service_api_client.get_active_services({'user_id': str(user_id)}).get('data', [])
|
return redirect(url_for('main.show_accounts_or_dashboard'))
|
||||||
|
|
||||||
if len(services) == 1:
|
|
||||||
return redirect(url_for('main.service_dashboard', service_id=services[0]['id']))
|
|
||||||
else:
|
|
||||||
return redirect(url_for('main.choose_account'))
|
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def test_should_sign_in_when_password_reset_is_successful_for_email_auth(
|
|||||||
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
|
response = client.post(url_for('.new_password', token=token), data={'new_password': 'a-new_password'})
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('.choose_account', _external=True)
|
assert response.location == url_for('.show_accounts_or_dashboard', _external=True)
|
||||||
assert mock_get_user_by_email_request_password_reset.called
|
assert mock_get_user_by_email_request_password_reset.called
|
||||||
assert mock_reset_failed_login_count.called
|
assert mock_reset_failed_login_count.called
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,3 @@
|
|||||||
from unittest.mock import ANY
|
|
||||||
|
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
from flask import url_for
|
from flask import url_for
|
||||||
from tests.conftest import SERVICE_ONE_ID, normalize_spaces, set_config
|
from tests.conftest import SERVICE_ONE_ID, normalize_spaces, set_config
|
||||||
@@ -21,38 +19,12 @@ def test_should_render_two_factor_page(
|
|||||||
assert '''We’ve sent you a text message with a security code.''' in response.get_data(as_text=True)
|
assert '''We’ve sent you a text message with a security code.''' in response.get_data(as_text=True)
|
||||||
|
|
||||||
|
|
||||||
def test_should_login_user_and_redirect_to_service_dashboard(
|
|
||||||
client,
|
|
||||||
api_user_active,
|
|
||||||
mock_get_user,
|
|
||||||
mock_get_user_by_email,
|
|
||||||
mock_check_verify_code,
|
|
||||||
mock_get_services_with_one_service,
|
|
||||||
mock_events,
|
|
||||||
):
|
|
||||||
with client.session_transaction() as session:
|
|
||||||
session['user_details'] = {
|
|
||||||
'id': api_user_active.id,
|
|
||||||
'email': api_user_active.email_address}
|
|
||||||
response = client.post(url_for('main.two_factor'),
|
|
||||||
data={'sms_code': '12345'})
|
|
||||||
assert response.status_code == 302
|
|
||||||
assert response.location == url_for(
|
|
||||||
'main.service_dashboard',
|
|
||||||
service_id=SERVICE_ONE_ID,
|
|
||||||
_external=True
|
|
||||||
)
|
|
||||||
|
|
||||||
mock_events.assert_called_with('sucessful_login', ANY)
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_login_user_and_should_redirect_to_next_url(
|
def test_should_login_user_and_should_redirect_to_next_url(
|
||||||
client,
|
client,
|
||||||
api_user_active,
|
api_user_active,
|
||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_check_verify_code,
|
mock_check_verify_code,
|
||||||
mock_get_services,
|
|
||||||
):
|
):
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
session['user_details'] = {
|
session['user_details'] = {
|
||||||
@@ -83,20 +55,15 @@ def test_should_login_user_and_not_redirect_to_external_url(
|
|||||||
response = client.post(url_for('main.two_factor', next='http://www.google.com'),
|
response = client.post(url_for('main.two_factor', next='http://www.google.com'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
'main.service_dashboard',
|
|
||||||
service_id=SERVICE_ONE_ID,
|
|
||||||
_external=True
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
def test_should_login_user_and_redirect_to_choose_accounts(
|
def test_should_login_user_and_redirect_to_show_accounts(
|
||||||
client,
|
client,
|
||||||
api_user_active,
|
api_user_active,
|
||||||
mock_get_user,
|
mock_get_user,
|
||||||
mock_get_user_by_email,
|
mock_get_user_by_email,
|
||||||
mock_check_verify_code,
|
mock_check_verify_code,
|
||||||
mock_get_services,
|
|
||||||
):
|
):
|
||||||
with client.session_transaction() as session:
|
with client.session_transaction() as session:
|
||||||
session['user_details'] = {
|
session['user_details'] = {
|
||||||
@@ -106,7 +73,7 @@ def test_should_login_user_and_redirect_to_choose_accounts(
|
|||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.choose_account', _external=True)
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
|
|
||||||
|
|
||||||
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(
|
def test_should_return_200_with_sms_code_error_when_sms_code_is_wrong(
|
||||||
@@ -159,11 +126,8 @@ def test_two_factor_should_set_password_when_new_password_exists_in_session(
|
|||||||
response = client.post(url_for('main.two_factor'),
|
response = client.post(url_for('main.two_factor'),
|
||||||
data={'sms_code': '12345'})
|
data={'sms_code': '12345'})
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for(
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
'main.service_dashboard',
|
|
||||||
service_id=SERVICE_ONE_ID,
|
|
||||||
_external=True
|
|
||||||
)
|
|
||||||
mock_update_user_password.assert_called_once_with(api_user_active.id, password='changedpassword')
|
mock_update_user_password.assert_called_once_with(api_user_active.id, password='changedpassword')
|
||||||
|
|
||||||
|
|
||||||
@@ -230,7 +194,7 @@ def test_valid_two_factor_email_link_logs_in_user(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.service_dashboard', service_id=SERVICE_ONE_ID, _external=True)
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
|
|
||||||
|
|
||||||
def test_two_factor_email_link_has_expired(
|
def test_two_factor_email_link_has_expired(
|
||||||
@@ -321,4 +285,4 @@ def test_two_factor_email_link_used_when_user_already_logged_in(
|
|||||||
url_for('main.two_factor_email', token=valid_token)
|
url_for('main.two_factor_email', token=valid_token)
|
||||||
)
|
)
|
||||||
assert response.status_code == 302
|
assert response.status_code == 302
|
||||||
assert response.location == url_for('main.choose_account', _external=True)
|
assert response.location == url_for('main.show_accounts_or_dashboard', _external=True)
|
||||||
|
|||||||
Reference in New Issue
Block a user