mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-16 03:10:16 -04:00
platform admins can go back to any service
This commit is contained in:
@@ -26,11 +26,11 @@ def show_accounts_or_dashboard():
|
||||
return redirect(url_for('.index'))
|
||||
|
||||
service_id = session.get('service_id')
|
||||
if any(service_id == x for x in current_user.services):
|
||||
if service_id and (service_id in current_user.services or current_user.platform_admin):
|
||||
return redirect(url_for('.service_dashboard', service_id=service_id))
|
||||
|
||||
organisation_id = session.get('organisation_id')
|
||||
if any(organisation_id == x for x in current_user.organisations):
|
||||
if organisation_id and (organisation_id in current_user.organisations or current_user.platform_admin):
|
||||
return redirect(url_for('.organisation_dashboard', org_id=organisation_id))
|
||||
|
||||
if len(current_user.services) == 1 and not current_user.organisations:
|
||||
|
||||
@@ -37,11 +37,12 @@ SAMPLE_DATA = {
|
||||
}
|
||||
|
||||
|
||||
def user_with_orgs_and_services(num_orgs, num_services):
|
||||
def user_with_orgs_and_services(num_orgs, num_services, platform_admin=False):
|
||||
return User(user_json(
|
||||
name='leo',
|
||||
organisations=['org{}'.format(i) for i in range(1, num_orgs + 1)],
|
||||
services=['service{}'.format(i) for i in range(1, num_services + 1)]
|
||||
services=['service{}'.format(i) for i in range(1, num_services + 1)],
|
||||
platform_admin=platform_admin
|
||||
))
|
||||
|
||||
|
||||
@@ -231,3 +232,42 @@ def test_show_accounts_or_dashboard_redirects_if_not_logged_in(
|
||||
response = client.get(url_for('main.show_accounts_or_dashboard'))
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for('main.index', _external=True)
|
||||
|
||||
|
||||
def test_show_accounts_or_dashboard_redirects_to_service_dashboard_if_platform_admin(
|
||||
client,
|
||||
mocker,
|
||||
mock_get_service
|
||||
):
|
||||
client.login(user_with_orgs_and_services(num_orgs=1, num_services=1, platform_admin=True), mocker=mocker)
|
||||
with client.session_transaction() as session:
|
||||
session['service_id'] = 'service2'
|
||||
session['organisation_id'] = None
|
||||
|
||||
response = client.get(url_for('.show_accounts_or_dashboard'))
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.service_dashboard',
|
||||
service_id='service2',
|
||||
_external=True
|
||||
)
|
||||
|
||||
|
||||
def test_show_accounts_or_dashboard_redirects_to_org_dashboard_if_platform_admin(
|
||||
client,
|
||||
mocker
|
||||
):
|
||||
client.login(user_with_orgs_and_services(num_orgs=1, num_services=1, platform_admin=True), mocker=mocker)
|
||||
with client.session_transaction() as session:
|
||||
session['service_id'] = None
|
||||
session['organisation_id'] = 'org2'
|
||||
|
||||
response = client.get(url_for('.show_accounts_or_dashboard'))
|
||||
|
||||
assert response.status_code == 302
|
||||
assert response.location == url_for(
|
||||
'main.organisation_dashboard',
|
||||
org_id='org2',
|
||||
_external=True
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user