def service_users_report_json(service_id): # permissions are structured differently on invited vs accepted-invite users def user_permissions(user): return { permission for permission in all_permissions if user.has_permission_for_service(service_id, permission) } def present_row(user): logged_in_at = getattr(user, 'logged_in_at', None) if logged_in_at: logged_in_at = gmt_timezones(logged_in_at) return { "email_address": user.email_address, "name": getattr(user, 'name', None), # does not exist on invited user "mobile_number": getattr(user, 'mobile_number', None), # does not exist on invited user "last_login": logged_in_at, "auth_type": user.auth_type, "permissions": list(user_permissions(user)), } users = sorted( user_api_client.get_users_for_service(service_id=service_id) + [ invite for invite in invite_api_client.get_invites_for_service( service_id=service_id) if invite.status != 'accepted' ], key=lambda user: user.email_address, ) return json_download([present_row(user) for user in users], f'service-{service_id}-users')
def manage_users(service_id): users = user_api_client.get_users_for_service(service_id=service_id) invited_users = [invite for invite in invite_api_client.get_invites_for_service(service_id=service_id) if invite.status != 'accepted'] return render_template( 'views/manage-users.html', users=users, current_user=current_user, invited_users=invited_users )
def manage_users(service_id): users = user_api_client.get_users_for_service(service_id=service_id) invited_users = [ invite for invite in invite_api_client.get_invites_for_service( service_id=service_id) if invite.status != 'accepted' ] return render_template('views/manage-users.html', users=users, current_user=current_user, invited_users=invited_users)
def manage_users(service_id): users = sorted( user_api_client.get_users_for_service(service_id=service_id) + [ invite for invite in invite_api_client.get_invites_for_service( service_id=service_id) if invite.status != 'accepted' ], key=lambda user: user.email_address, ) return render_template( 'views/manage-users.html', users=users, current_user=current_user, show_search_box=(len(users) > 7), form=SearchUsersForm(), )
def test_client_returns_invite(mocker, sample_invite): sample_invite['status'] = 'pending' service_id = sample_invite['service'] expected_data = {'data': [sample_invite]} expected_url = '/service/{}/invite'.format(service_id) mock_get = mocker.patch('app.notify_client.invite_api_client.InviteApiClient.get', return_value=expected_data) invites = invite_api_client.get_invites_for_service(service_id) mock_get.assert_called_once_with(expected_url) assert len(invites) == 1 assert invites[0].status == 'pending'
def test_client_returns_invite(mocker, sample_invite): sample_invite["status"] = "pending" service_id = sample_invite["service"] expected_data = {"data": [sample_invite]} expected_url = "/service/{}/invite".format(service_id) mock_get = mocker.patch( "app.notify_client.invite_api_client.InviteApiClient.get", return_value=expected_data, ) invites = invite_api_client.get_invites_for_service(service_id) mock_get.assert_called_once_with(expected_url) assert len(invites) == 1 assert invites[0]["status"] == "pending"
def service_users_report(service_id): # permissions are structured differently on invited vs accepted-invite users def user_permissions(user): return { permission for permission in all_permissions if user.has_permission_for_service(service_id, permission) } def present_row(user): logged_in_at = getattr(user, 'logged_in_at', None) if logged_in_at: logged_in_at = gmt_timezones(logged_in_at) return [ user.email_address, getattr(user, 'name', None), # does not exist on invited user getattr(user, 'mobile_number', None), # does not exist on invited user logged_in_at, user.auth_type, ';'.join(user_permissions(user)) ] users = sorted( user_api_client.get_users_for_service(service_id=service_id) + [ invite for invite in invite_api_client.get_invites_for_service( service_id=service_id) if invite.status != 'accepted' ], key=lambda user: user.email_address, ) columns = [ "email_address", "name", "mobile_number", "last_login", "auth_type", "permissions" ] csv_data = [columns, *(present_row(user) for user in users)] return Spreadsheet.from_rows(csv_data).as_csv_data, 200, { 'Content-Type': 'text/csv; charset=utf-8', 'Content-Disposition': f'inline; filename="service-{service_id}-users.csv"' }