mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-08-19 14:09:20 -04:00
Merge pull request #2510 from alphagov/fix-user-with-no-permissions
Fix the permission check for users without permissions.
This commit is contained in:
@@ -485,6 +485,7 @@ def validate_route_permission(mocker,
|
||||
usr,
|
||||
service):
|
||||
usr._permissions[str(service['id'])] = permissions
|
||||
usr.services = [service['id']]
|
||||
mocker.patch(
|
||||
'app.user_api_client.check_verify_code',
|
||||
return_value=(True, ''))
|
||||
|
||||
@@ -211,6 +211,22 @@ def test_user_doesnt_have_permissions_for_organisation(
|
||||
index()
|
||||
|
||||
|
||||
def test_user_with_no_permissions_to_service_goes_to_templates(
|
||||
client,
|
||||
mocker
|
||||
):
|
||||
user = _user_with_permissions()
|
||||
mocker.patch('app.user_api_client.get_user', return_value=user)
|
||||
client.login(user)
|
||||
request.view_args = {'service_id': 'bar'}
|
||||
|
||||
@user_has_permissions()
|
||||
def index():
|
||||
pass
|
||||
|
||||
index()
|
||||
|
||||
|
||||
def _user_with_permissions():
|
||||
from app.notify_client.user_api_client import User
|
||||
|
||||
@@ -224,6 +240,7 @@ def _user_with_permissions():
|
||||
'permissions': {'foo': ['manage_users', 'manage_templates', 'manage_settings']},
|
||||
'platform_admin': False,
|
||||
'organisations': ['org_1', 'org_2'],
|
||||
'services': ['foo', 'bar']
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
|
||||
@@ -875,6 +875,7 @@ def _test_dashboard_menu(mocker, app_, usr, service, permissions):
|
||||
with app_.test_request_context():
|
||||
with app_.test_client() as client:
|
||||
usr._permissions[str(service['id'])] = permissions
|
||||
usr.services = [service['id']]
|
||||
mocker.patch('app.user_api_client.check_verify_code', return_value=(True, ''))
|
||||
mocker.patch('app.service_api_client.get_services', return_value={'data': [service]})
|
||||
mocker.patch('app.user_api_client.get_user', return_value=usr)
|
||||
|
||||
@@ -1498,7 +1498,7 @@ def test_route_permissions_for_choose_template(
|
||||
api_user_active,
|
||||
mock_get_template_folders,
|
||||
service_one,
|
||||
mock_get_service_templates,
|
||||
mock_get_service_templates
|
||||
):
|
||||
mocker.patch('app.job_api_client.get_job')
|
||||
validate_route_permission(
|
||||
@@ -1510,7 +1510,7 @@ def test_route_permissions_for_choose_template(
|
||||
'main.choose_template',
|
||||
service_id=service_one['id'],
|
||||
),
|
||||
['view_activity'],
|
||||
[],
|
||||
api_user_active,
|
||||
service_one)
|
||||
|
||||
|
||||
@@ -1178,7 +1178,8 @@ def active_user_with_permissions(fake_uuid):
|
||||
'view_activity']},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': [ORGANISATION_ID]
|
||||
'organisations': [ORGANISATION_ID],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
@@ -1205,6 +1206,7 @@ def active_caseworking_user(fake_uuid):
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': [],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
@@ -1232,7 +1234,8 @@ def active_user_no_mobile(fake_uuid):
|
||||
'view_activity']},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'email_auth',
|
||||
'organisations': []
|
||||
'organisations': [],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
@@ -1253,7 +1256,8 @@ def active_user_view_permissions(fake_uuid):
|
||||
'permissions': {SERVICE_ONE_ID: ['view_activity']},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': []
|
||||
'organisations': [],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
@@ -1271,10 +1275,11 @@ def active_user_empty_permissions(fake_uuid):
|
||||
'mobile_number': '07700 900763',
|
||||
'state': 'active',
|
||||
'failed_login_count': 0,
|
||||
'permissions': {SERVICE_ONE_ID: []},
|
||||
'permissions': {},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': []
|
||||
'organisations': [],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
@@ -1299,7 +1304,8 @@ def active_user_manage_template_permission(fake_uuid):
|
||||
]},
|
||||
'platform_admin': False,
|
||||
'auth_type': 'sms_auth',
|
||||
'organisations': []
|
||||
'organisations': [],
|
||||
'services': [SERVICE_ONE_ID]
|
||||
}
|
||||
user = User(user_data)
|
||||
return user
|
||||
|
||||
Reference in New Issue
Block a user